Skip to content

Commit

Permalink
Commander death (#95)
Browse files Browse the repository at this point in the history
* feat: Game ends on commander death

Memory leaks still pending to fix

* Requested changes

* Removing innecesary code

https://i.pinimg.com/736x/b4/1c/27/b41c27bddf4b52d0e69ad12d421dab14--an-idiot-funny-shit.jpg

* Moar requested changes
  • Loading branch information
onaranjoUCM authored and kyranet committed Apr 21, 2019
1 parent 85b06db commit 1954234
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
21 changes: 18 additions & 3 deletions Drakhtar/GameObjects/Commanders/Commander.cpp
@@ -1,13 +1,18 @@
// Copyright 2019 the Drakhtar authors. All rights reserved. MIT license.

#include "Commander.h"

#include "../../GameObjects/Box.h"
#include "../../Managers/TextureManager.h"
#include "Scenes/GameScene.h"
#include "Scenes/Scene.h"
#include "Scenes/TransitionScene.h"
#include "Structures/Game.h"
#include "Structures/Team.h"

Commander::Commander(Scene *scene, Texture *texture, Box *box,
Commander::Commander(Scene* scene, Texture* texture, Box* box,
const UnitStats commanderStats)
: Unit(scene, texture, box, commanderStats, "") {

const auto rect = box_->getRect();

commanderIcon_ =
Expand Down Expand Up @@ -53,7 +58,17 @@ void Commander::onSelect() {
}
}

void Commander::moveToBox(Box *box) {
void Commander::kill() {
Unit::kill();
int currentScene = reinterpret_cast<GameScene*>(getScene())->getBattleInd();
if (getTeam()->getColor() == Color::BLUE) {
Game::getSceneMachine()->changeScene(new GameScene(currentScene));
} else {
Game::getSceneMachine()->changeScene(new TransitionScene(currentScene + 1));
}
}

void Commander::moveToBox(Box* box) {
Unit::moveToBox(box);
const auto rect = box_->getRect();
commanderIcon_->setPosition(Vector2D<int>(rect.x, rect.y - rect.h / 3));
Expand Down
16 changes: 10 additions & 6 deletions Drakhtar/GameObjects/Commanders/Commander.h
@@ -1,9 +1,10 @@
// Copyright 2019 the Drakhtar authors. All rights reserved. MIT license.

#pragma once
#include <vector>

#include "../Skill.h"
#include "../Unit.h"
#include <vector>

class Scene;
class Box;
Expand All @@ -13,24 +14,27 @@ class Commander : public Unit {
/**
* \brief A vector of all the skills the commander can cast.
*/
std::vector<Skill *> skills_;
std::vector<Skill*> skills_;

GameObject *commanderIcon_ = nullptr;
GameObject* commanderIcon_ = nullptr;

public:
Commander(Scene *scene, Texture *texture, Box *box, UnitStats commanderStats);
Commander(Scene* scene, Texture* texture, Box* box, UnitStats commanderStats);
virtual ~Commander();
void render() const override;

/**
* \return A vector of all the skills the commander can cast.
*/
std::vector<Skill *> getSkills() const { return skills_; }
std::vector<Skill*> getSkills() const { return skills_; }

/**
* \brief Is called every time it's the commander's turn to lower every
* skill's cooldown timer and duration timer.
*/
void onSelect() override;
void moveToBox(Box *box) override;

void moveToBox(Box* box) override;

void kill() override;
};
2 changes: 2 additions & 0 deletions Drakhtar/Scenes/GameScene.cpp
Expand Up @@ -201,3 +201,5 @@ void GameScene::loadRedTeam(UnitFactory& factory) {
}

Board* GameScene::getBoard() const { return board_; }

int GameScene::getBattleInd() { return battle_; }
1 change: 1 addition & 0 deletions Drakhtar/Scenes/GameScene.h
Expand Up @@ -22,4 +22,5 @@ class GameScene final : public Scene {
void loadRedTeam(UnitFactory& factory);

Board* getBoard() const;
int getBattleInd();
};
2 changes: 2 additions & 0 deletions Drakhtar/Scenes/TransitionScene.cpp
Expand Up @@ -21,3 +21,5 @@ void TransitionScene::preload() {
addGameObject(dialog);
setTransition(true);
}

int TransitionScene::getBattleInd() { return battle_; }
2 changes: 2 additions & 0 deletions Drakhtar/Scenes/TransitionScene.h
Expand Up @@ -8,6 +8,8 @@ class TransitionScene final : public Scene {
explicit TransitionScene(int battle);
void preload() override;
// void run();
int getBattleInd();

private:
int battle_;
// DialogScene dialog;
Expand Down

0 comments on commit 1954234

Please sign in to comment.