aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-03 23:05:41 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-03 23:05:41 +0100
commit0c083ab2d3fd8151e6fd4238cf2159b56b96a708 (patch)
treefb59346977c5303c531db8ca187492434b6beaa0
parentI may have an idea (diff)
downloadthreshold-0c083ab2d3fd8151e6fd4238cf2159b56b96a708.tar.gz
threshold-0c083ab2d3fd8151e6fd4238cf2159b56b96a708.tar.bz2
threshold-0c083ab2d3fd8151e6fd4238cf2159b56b96a708.tar.xz
threshold-0c083ab2d3fd8151e6fd4238cf2159b56b96a708.tar.zst
threshold-0c083ab2d3fd8151e6fd4238cf2159b56b96a708.zip
treschaud
-rw-r--r--src/gameplay.cpp40
-rw-r--r--src/main.cpp1
2 files changed, 24 insertions, 17 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 3cbc17f..fafe4a5 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -13,13 +13,13 @@ Game::Game(void)
{
// nEnemies = GetRandomValue(5, 15);
- enemies = 3;
+ nEnemies = 4;
enemies = new std::vector<Entity>(nEnemies);
player = new Entity;
player->posX = SCREENWIDTH / 2;
player->posY = SCREENHEIGHT / 2;
- player->direction.x = 1;
+ player->direction.x = 0;
player->direction.y = 0;
}
@@ -54,26 +54,34 @@ void Game::tick() const
en.posX += en.direction.x;
en.posY += en.direction.y;
}
- player->posX += player->direction.x;
- player->posY += player->direction.y;
+ // player->posX += player->direction.x;
+ // player->posY += player->direction.y;
}
void Game::getKeys() const
{
- if (IsKeyPressed(KEY_UP)) {
- player->direction.x = 0;
- player->direction.y = -2;
+ auto oldX = 0, oldY = 0;
+
+ oldX = player->posX;
+ oldY = player->posY;
+ if (IsKeyDown(KEY_UP)) {
+ player->posX += 0;
+ player->posY += -4;
+ }
+ if (IsKeyDown(KEY_DOWN)) {
+ player->posX += 0;
+ player->posY += 4;
}
- if (IsKeyPressed(KEY_DOWN)) {
- player->direction.x = 0;
- player->direction.y = 2;
+ if (IsKeyDown(KEY_LEFT)) {
+ player->posX += -4;
+ player->posY += 0;
}
- if (IsKeyPressed(KEY_LEFT)) {
- player->direction.x = -2;
- player->direction.y = 0;
+ if (IsKeyDown(KEY_RIGHT)) {
+ player->posX += 4;
+ player->posY += 0;
}
- if (IsKeyPressed(KEY_RIGHT)) {
- player->direction.x = 2;
- player->direction.y = 0;
+ if (oldX != player->posX || oldY != player->posY)
+ {
+ this->tick();
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 283390a..20a6cdc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,7 +24,6 @@ int main(void) {
}
case (GAMEPLAY):
{
- game->tick();
break ;
}
case (ENDING):