mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
MOVE: Game::update
This commit is contained in:
parent
b031e74756
commit
1b571a6a46
@ -21,6 +21,8 @@ class Map;
|
|||||||
namespace engine {
|
namespace engine {
|
||||||
extern gamefunction init;
|
extern gamefunction init;
|
||||||
extern gamefunction update;
|
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
|
class Game
|
||||||
@ -64,9 +66,9 @@ public:
|
|||||||
|
|
||||||
void refreshPlayers();
|
void refreshPlayers();
|
||||||
Entity::TeamLabel getWinner() const;
|
Entity::TeamLabel getWinner() const;
|
||||||
|
void setWinner(Entity::TeamLabel winningTeam);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setWinner(Entity::TeamLabel winningTeam);
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
|
|||||||
20
src/Game.cpp
20
src/Game.cpp
@ -13,6 +13,8 @@
|
|||||||
#include "StatEffectsComponent.h"
|
#include "StatEffectsComponent.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
|
|
||||||
|
Game* engine::game = nullptr; // will be initialized in constructor
|
||||||
|
|
||||||
Game::Game() :
|
Game::Game() :
|
||||||
manager(this),
|
manager(this),
|
||||||
tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)),
|
tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)),
|
||||||
@ -24,6 +26,7 @@ Game::Game() :
|
|||||||
player2(manager.addEntity()),
|
player2(manager.addEntity()),
|
||||||
wall(manager.addEntity())
|
wall(manager.addEntity())
|
||||||
{
|
{
|
||||||
|
engine::game = this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Game::~Game() = default;
|
Game::~Game() = default;
|
||||||
@ -291,27 +294,10 @@ void Game::handleEvents()
|
|||||||
|
|
||||||
void Game::update()
|
void Game::update()
|
||||||
{
|
{
|
||||||
Vector2D playerPos = player1.getComponent<TransformComponent>().position;
|
|
||||||
Vector2D enemyPos = player2.getComponent<TransformComponent>().position;
|
|
||||||
|
|
||||||
int powerupSpawn = rand() % 500;
|
|
||||||
|
|
||||||
manager.refresh();
|
manager.refresh();
|
||||||
manager.update();
|
manager.update();
|
||||||
|
|
||||||
engine::update(); // TODO: this might have to be split up into two update functions, before and after manager...
|
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<HealthComponent>().getHealth() <= 0) {
|
|
||||||
this->setWinner(player->getTeam());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::render()
|
void Game::render()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user