From 1b571a6a46fe157a71bea03d478921d0a5ec86d3 Mon Sep 17 00:00:00 2001 From: Benedikt Galbavy Date: Sat, 13 Apr 2024 17:14:04 +0200 Subject: [PATCH] MOVE: Game::update --- include/Game.h | 4 +++- src/Game.cpp | 20 +++----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/include/Game.h b/include/Game.h index 0b1270b..7ff50d6 100644 --- a/include/Game.h +++ b/include/Game.h @@ -21,6 +21,8 @@ class Map; namespace engine { extern gamefunction init; extern gamefunction update; + + extern Game* game; // this is a temporary fix to remove artifacts of chicken_game from the engine while the API is not yet finalized } class Game @@ -64,9 +66,9 @@ public: void refreshPlayers(); Entity::TeamLabel getWinner() const; + void setWinner(Entity::TeamLabel winningTeam); private: - void setWinner(Entity::TeamLabel winningTeam); int counter = 0; bool isRunning = false; diff --git a/src/Game.cpp b/src/Game.cpp index a234607..f7785e1 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -13,6 +13,8 @@ #include "StatEffectsComponent.h" #include "Constants.h" +Game* engine::game = nullptr; // will be initialized in constructor + Game::Game() : manager(this), tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)), @@ -24,6 +26,7 @@ Game::Game() : player2(manager.addEntity()), wall(manager.addEntity()) { + engine::game = this; }; Game::~Game() = default; @@ -291,27 +294,10 @@ void Game::handleEvents() void Game::update() { - Vector2D playerPos = player1.getComponent().position; - Vector2D enemyPos = player2.getComponent().position; - - int powerupSpawn = rand() % 500; - manager.refresh(); manager.update(); engine::update(); // TODO: this might have to be split up into two update functions, before and after manager... - - if (powerupSpawn == 0) - { - assets->createPowerup(assets->calculateSpawnPosition(), assets->calculateType()); - } - - // needs to be in game.cpp to have access to internal functions - for (auto& player : manager.getGroup((size_t) Entity::GroupLabel::PLAYERS)) { - if (player->getComponent().getHealth() <= 0) { - this->setWinner(player->getTeam()); - } - } } void Game::render()