ADD: Integrate Turnsystem into BuildingPlacementSystem
This commit is contained in:
parent
1735d89eca
commit
ce2858534f
@ -73,7 +73,6 @@ void GameLayer::onDetach()
|
|||||||
|
|
||||||
void GameLayer::onUpdate()
|
void GameLayer::onUpdate()
|
||||||
{
|
{
|
||||||
PlayerID player = gameMode->getCurrentPlayer();
|
|
||||||
mousePicker->update(*camera);
|
mousePicker->update(*camera);
|
||||||
//printf("Mouse Ray: %f, %f, %f\n", mousePicker->getCurrentRay().x, mousePicker->getCurrentRay().y, mousePicker->getCurrentRay().z);
|
//printf("Mouse Ray: %f, %f, %f\n", mousePicker->getCurrentRay().x, mousePicker->getCurrentRay().y, mousePicker->getCurrentRay().z);
|
||||||
glm::vec3 moveDir = glm::vec3(0,0,0);
|
glm::vec3 moveDir = glm::vec3(0,0,0);
|
||||||
@ -95,7 +94,7 @@ void GameLayer::onUpdate()
|
|||||||
|
|
||||||
camera->move(moveDir, 0.5f);
|
camera->move(moveDir, 0.5f);
|
||||||
tileHighlightSystem->update(*entityManager, *mousePicker, *camera);
|
tileHighlightSystem->update(*entityManager, *mousePicker, *camera);
|
||||||
buildingPlacementSystem->update(*entityManager, *gameMode, 0);
|
buildingPlacementSystem->update(*entityManager, *gameMode, 0, *turnState);
|
||||||
renderSystem->render(*entityManager, *renderer);
|
renderSystem->render(*entityManager, *renderer);
|
||||||
|
|
||||||
renderer->render(*light, *camera);
|
renderer->render(*light, *camera);
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
GameMode::GameMode() {
|
GameMode::GameMode() {
|
||||||
addPlayer(0, "Player 1");
|
addPlayer(0, "Player 1");
|
||||||
|
addPlayer(1, "Player 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameMode::canBuild(PlayerID player, BuildingType buildingType) {
|
bool GameMode::canBuild(PlayerID player, BuildingType buildingType) {
|
||||||
@ -66,4 +67,13 @@ void GameMode::setActiveBuilding(BuildingType buildingType) {
|
|||||||
activeBuilding = buildingType;
|
activeBuilding = buildingType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t GameMode::getPlayerCount() const {
|
||||||
|
return players.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameMode::hasTurn(PlayerID playerID, int turn) const {
|
||||||
|
printf("Turn: %d, PlayerCount: %lu, playerID: %u\n, Modulo Result: %lu", turn, getPlayerCount(), playerID, turn % getPlayerCount());
|
||||||
|
return turn % static_cast<int>(getPlayerCount()) == static_cast<int>(playerID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,11 @@ public:
|
|||||||
std::optional<BuildingType> getActiveBuilding() const;
|
std::optional<BuildingType> getActiveBuilding() const;
|
||||||
void clearActiveBuilding();
|
void clearActiveBuilding();
|
||||||
void setActiveBuilding(BuildingType buildingType);
|
void setActiveBuilding(BuildingType buildingType);
|
||||||
|
size_t getPlayerCount() const;
|
||||||
|
|
||||||
|
bool hasTurn(PlayerID playerID, int turn) const;
|
||||||
|
|
||||||
|
bool getCurrentTurnPlayer(int turn) const;
|
||||||
private:
|
private:
|
||||||
std::unordered_map<PlayerID, Player> players;
|
std::unordered_map<PlayerID, Player> players;
|
||||||
std::optional<BuildingType> activeBuilding;
|
std::optional<BuildingType> activeBuilding;
|
||||||
|
|||||||
@ -14,11 +14,16 @@
|
|||||||
#include "../../building/BuildingConfig.h"
|
#include "../../building/BuildingConfig.h"
|
||||||
#include "../../building/BuildingFactory.h"
|
#include "../../building/BuildingFactory.h"
|
||||||
#include "../../building/BuildingRules.h"
|
#include "../../building/BuildingRules.h"
|
||||||
|
#include "../../gameplay/TurnState.h"
|
||||||
#include "../components/BuildingComponent.h"
|
#include "../components/BuildingComponent.h"
|
||||||
#include "../components/TileGameplayComponent.h"
|
#include "../components/TileGameplayComponent.h"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gameMode, PlayerID player) {
|
void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gameMode, PlayerID player, const TurnState& turnState) {
|
||||||
|
if (!gameMode.hasTurn(player, turnState.currentTurn)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_LEFT)) {
|
if (!InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_LEFT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,11 +6,12 @@
|
|||||||
#define BUILDINGPLACEMENTSYSTEM_H
|
#define BUILDINGPLACEMENTSYSTEM_H
|
||||||
#include "../../../GameMode.h"
|
#include "../../../GameMode.h"
|
||||||
#include "../../../../engine/core/ECS/EntityManager.h"
|
#include "../../../../engine/core/ECS/EntityManager.h"
|
||||||
|
#include "../../gameplay/TurnState.h"
|
||||||
|
|
||||||
|
|
||||||
class BuildingPlacementSystem {
|
class BuildingPlacementSystem {
|
||||||
public:
|
public:
|
||||||
void update(EntityManager &entityManager, GameMode &gameMode, EntityID player);
|
void update(EntityManager &entityManager, GameMode &gameMode, EntityID player, const TurnState &turnState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user