aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <47527723+salaaad2@users.noreply.github.com>2022-01-12 20:00:49 +0100
committerGitHub <noreply@github.com>2022-01-12 20:00:49 +0100
commit7c1b7e94e647fc18f97ce2f2cdb500742f17f8ef (patch)
tree4237e4726fa0040fcd61ffe7c4abc7518b8c6a38
parentstages now work as intended, with multiple waves : \[v0.0.9\] (diff)
parentMerge branch 'master' into master (diff)
downloadthreshold-7c1b7e94e647fc18f97ce2f2cdb500742f17f8ef.tar.gz
threshold-7c1b7e94e647fc18f97ce2f2cdb500742f17f8ef.tar.bz2
threshold-7c1b7e94e647fc18f97ce2f2cdb500742f17f8ef.tar.xz
threshold-7c1b7e94e647fc18f97ce2f2cdb500742f17f8ef.tar.zst
threshold-7c1b7e94e647fc18f97ce2f2cdb500742f17f8ef.zip
Merge pull request #1 from Paure42/master
fix player leaving the map
-rw-r--r--src/gameplay.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index c27c712..de4ba66 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -221,25 +221,37 @@ int Game::tick() {
return (0);
}
-int Game::getKeys() {
- auto oldX = 0, oldY = 0; // get position before processing keys to check
+int Game::getKeys() const {
+ auto oldX = 0, oldY = 0, speed = 7; // get position before processing keys to check
// for player movement in threshold mode
oldX = player->posX;
oldY = player->posY;
if (IsKeyDown(KEY_W)) {
player->posX += 0;
- player->posY += -7;
+ if ((player->posY + speed) < 0)
+ player->posY = 0;
+ else
+ player->posY += -speed;
}
if (IsKeyDown(KEY_S)) {
player->posX += 0;
- player->posY += 7;
+ if ((player->posY + speed) > SCREENHEIGHT)
+ player->posY = SCREENHEIGHT;
+ else
+ player->posY += speed;
}
if (IsKeyDown(KEY_A)) {
- player->posX += -7;
+ if ((player->posX - speed) < 0) // avoid leaving the map
+ player->posX = 0;
+ else
+ player->posX += -speed;
player->posY += 0;
}
if (IsKeyDown(KEY_D)) {
- player->posX += 7;
+ if ((player->posX + speed) > SCREENWIDTH)
+ player->posX = SCREENWIDTH;
+ else
+ player->posX += speed;
player->posY += 0;
}
if (player->fury >= 5 && IsKeyDown(KEY_E)) {