diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-01-03 22:10:27 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-01-03 22:10:27 +0100 |
commit | 0292e135be5f576d14e9589ad0ed8543a03b544c (patch) | |
tree | dc8b0ba9c0c566959ea47871119b56d3fd978a57 | |
parent | add circles (diff) | |
download | threshold-0292e135be5f576d14e9589ad0ed8543a03b544c.tar.gz threshold-0292e135be5f576d14e9589ad0ed8543a03b544c.tar.bz2 threshold-0292e135be5f576d14e9589ad0ed8543a03b544c.tar.xz threshold-0292e135be5f576d14e9589ad0ed8543a03b544c.tar.zst threshold-0292e135be5f576d14e9589ad0ed8543a03b544c.zip |
balls move yknow
-rw-r--r-- | src/gameplay.cpp | 34 | ||||
-rw-r--r-- | src/gameplay.hpp | 12 | ||||
-rw-r--r-- | src/main.cpp | 5 |
3 files changed, 48 insertions, 3 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 90b6603..56429d9 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -7,7 +7,13 @@ Enemy::Enemy(void) { posX = GetRandomValue(0, SCREENWIDTH); posY = GetRandomValue(0, SCREENHEIGHT); - direction = (Vector2){posX, posY}; + if (static_cast<int>(posX) & 1) + { + direction = (Vector2){posX / 100, -posY / 100}; + } else { + direction = (Vector2){-posX / 100, posY / 100}; + } + } Enemy::~Enemy() {} @@ -24,10 +30,34 @@ void Game::start() const { std::cout << "----- Gameplay: Start -----" << std::endl; std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned" << std::endl; +} + +void Game::draw() const +{ + for (auto & en : *enemies) + { + DrawCircleV((Vector2){en.posX, en.posY}, 10, RED); + } +} + +void Game::tick() const +{ for (auto & en : *enemies) { - DrawCircleV(en.direction, 10, RED); + if (en.posX >= SCREENWIDTH || en.posX <= 0) + { + en.direction.x = -en.direction.x; + } + if (en.posY >= SCREENHEIGHT || en.posY <= 0) + { + en.direction.y = -en.direction.y; + } + en.posX += en.direction.x; + en.posY += en.direction.y; } +} +void Game::getKeys() const +{ } diff --git a/src/gameplay.hpp b/src/gameplay.hpp index 3c73d09..3dc6b27 100644 --- a/src/gameplay.hpp +++ b/src/gameplay.hpp @@ -14,6 +14,15 @@ class Enemy { ~Enemy(); }; +class Player { + public: + float posX; + float posY; + Vector2 direction; + Player(); + ~Player(); +}; + class Game { int nEnemies; @@ -24,6 +33,9 @@ class Game { ~Game(); void start() const ; + void draw() const ; + void tick() const ; + void getKeys() const ; }; #endif // GAMEPLAY_H_ diff --git a/src/main.cpp b/src/main.cpp index f5a27af..283390a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,11 +18,13 @@ int main(void) { if (IsKeyPressed(KEY_ENTER)) { gs = GAMEPLAY; + game->start(); } break ; } case (GAMEPLAY): { + game->tick(); break ; } case (ENDING): @@ -42,7 +44,8 @@ int main(void) { } case (GAMEPLAY): { - game->start(); + game->getKeys(); + game->draw(); break ; } case (ENDING): |