-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: Process in Controller rework * feat: Added the foundation for AI and MP controllers * fix: Resolved build problems, more progress on controllers * lint: The Fallen Green Tick * fix: First working version with team-scoped controllers * fix: Cells not rendering after the first turn Turns out I forgot that cells are drawn as soon as finish is called * fix: Resolved crash when all the units from a team die * fix: Resolved some critical bugs
- Loading branch information
Showing
15 changed files
with
316 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2019 the Drakhtar authors. All rights reserved. MIT license. | ||
|
||
#include "PlayerHandler.h" | ||
#include "Controllers/PlayerController.h" | ||
#include "GameObjects/Board.h" | ||
#include "GameObjects/Box.h" | ||
#include "GameObjects/Unit.h" | ||
#include "Managers/Input.h" | ||
|
||
PlayerHandler::PlayerHandler(PlayerController* controller) | ||
: EventListener(nullptr), controller_(controller) {} | ||
|
||
void PlayerHandler::run(const SDL_Event) { | ||
if (controller_->getLocked() || !Input::isMouseButtonUp(MouseKey::LEFT)) | ||
return; | ||
|
||
const auto gameObject = Input::screenMouseToRay(); | ||
if (!gameObject) return; | ||
|
||
// Ignore Unit's "hitboxes" and assume it's a click to the board, so get the | ||
// box at the mouse's coordinates | ||
const auto unit = dynamic_cast<Unit*>(gameObject); | ||
const auto box = unit ? controller_->getBoard()->getBoxAtCoordinates( | ||
Input::getMousePosition()) | ||
: dynamic_cast<Box*>(gameObject); | ||
if (!box) return; | ||
|
||
if (!controller_->hasMoved() && box->isEmpty()) { | ||
controller_->onClickMove(box); | ||
} else if (!controller_->hasAttacked()) { | ||
controller_->onClickAttack(box); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2019 the Drakhtar authors. All rights reserved. MIT license. | ||
|
||
#pragma once | ||
#include "EventListeners/EventListener.h" | ||
|
||
class PlayerController; | ||
|
||
class PlayerHandler : public EventListener { | ||
private: | ||
PlayerController* controller_; | ||
|
||
public: | ||
explicit PlayerHandler(PlayerController* controller); | ||
void run(SDL_Event event) override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
// Copyright 2019 the Drakhtar authors. All rights reserved. MIT license. | ||
|
||
#pragma once | ||
#include "UnitsController.h" | ||
#include "EventListeners/ListenerOnClick.h" | ||
#include "UnitsController.h" | ||
|
||
class PlayerController final : public UnitsController, public ListenerOnClick { | ||
public: | ||
PlayerController(Board *board, TurnBar *turnBar, GameScene *scene); | ||
class PlayerController final : public UnitsController { | ||
bool locked_ = false; | ||
|
||
/** | ||
* \brief Is called every time an event is capture to process it. | ||
* \param event: The event to be processed. | ||
*/ | ||
void run(SDL_Event event) override; | ||
public: | ||
PlayerController(Board* board, TurnBar* turnBar, GameScene* scene, Team* team, | ||
Team* oppositeTeam); | ||
|
||
/** | ||
* \brief Moves active unit to an empty cell within range. | ||
* \param boxClicked: The box where the unit should move. | ||
*/ | ||
void onClickMove(Box *boxClicked); | ||
void onClickMove(Box* boxClicked); | ||
|
||
/** | ||
* \brief Makes active unit attack another unit clicked | ||
* \param boxClicked: The box containing the unit that will receive the | ||
* attack. | ||
*/ | ||
void onClickAttack(Box *boxClicked); | ||
void onClickAttack(Box* boxClicked); | ||
|
||
/** | ||
* \brief Resets board textures, ends unit's turn and updates active unit. | ||
*/ | ||
void advanceTurn(); | ||
void start() override; | ||
void finish() override; | ||
|
||
bool getLocked() const; | ||
}; |
Oops, something went wrong.