diff --git a/VaporWaveWars/actor.cpp b/VaporWaveWars/actor.cpp index 5a3b5bc..cbd6f6d 100644 --- a/VaporWaveWars/actor.cpp +++ b/VaporWaveWars/actor.cpp @@ -1,8 +1,13 @@ #include "actor.hpp" -Actor::Actor() {} +Actor::Actor() { + score = 0; + animate = PlayerState::attacking; + this->character = new Character(0); +} Actor::Actor(int num) { - animate = true; + score = 0; + animate = PlayerState::attacking; this->character = new Character(num); } @@ -12,18 +17,30 @@ void Actor::draw(sf::RenderWindow *window) { bool Actor::update(float deltaTime, sf::RenderWindow *window) { character->update(deltaTime); - if (animate) { + if (animate == PlayerState::attacking) { character->setState(PlayerState::attacking); - animate = false; + animate = PlayerState::inMidle; + } + else if (animate == PlayerState::inMidle) { + if (character->isLastFrame()) animate = PlayerState::idle; } return this->updateLogic(deltaTime, window); } -void Actor::hitBy(Compas enemy) const { +bool Actor::hitBy(Compas enemy) const { if (enemy == compas) std::cout << "dodge" << std::endl; else std::cout << "hit" << std::endl; + return enemy == compas; } Compas Actor::getAttack() const { return compas; } + +void Actor::upScore() { + ++score; +} + +int Actor::getScore() const { + return score; +} diff --git a/VaporWaveWars/actor.hpp b/VaporWaveWars/actor.hpp index f876f70..6d465ac 100644 --- a/VaporWaveWars/actor.hpp +++ b/VaporWaveWars/actor.hpp @@ -12,12 +12,15 @@ public: Actor(int num); bool update(float deltaTime, sf::RenderWindow *window); void draw(sf::RenderWindow *window); - void hitBy(Compas enemy) const; + bool hitBy(Compas enemy) const; Compas getAttack() const; virtual bool event(sf::Event e) = 0; + void upScore(); + int getScore() const; protected: + int score; Compas compas; - bool animate; + PlayerState::playerState animate; virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0; private: Character *character; diff --git a/VaporWaveWars/combat.cpp b/VaporWaveWars/combat.cpp index e3f55cf..6ea3627 100644 --- a/VaporWaveWars/combat.cpp +++ b/VaporWaveWars/combat.cpp @@ -47,7 +47,11 @@ void Combat::updateEvents(sf::Event e) { if (playerOneTurn) { bool aux = player->event(e); if (!aux) { //end of player one ritm - if (!attacking) player->hitBy(enemy->getAttack()); + if (!attacking) { + if(!player->hitBy(enemy->getAttack())) enemy->upScore(); + std::cout << "player1: " << player->getScore() << std::endl; + std::cout << "player2: " << enemy->getScore() << std::endl; + } else playerOneTurn = aux; attacking = !attacking; } @@ -60,7 +64,11 @@ void Combat::updateEvents(sf::Event e) { void Combat::enemyManager(bool aux) { if (aux) { - if (!attacking) enemy->hitBy(player->getAttack()); + if (!attacking) { + if(!enemy->hitBy(player->getAttack())) player->upScore(); + std::cout << "player1: " << player->getScore() << std::endl; + std::cout << "player2: " << enemy->getScore() << std::endl; + } else playerOneTurn = aux; attacking = !attacking; } diff --git a/VaporWaveWars/commons.hpp b/VaporWaveWars/commons.hpp index 5911ea7..56bd793 100644 --- a/VaporWaveWars/commons.hpp +++ b/VaporWaveWars/commons.hpp @@ -41,7 +41,7 @@ namespace GameScene { } namespace PlayerState { - enum playerState{idle, attacking}; + enum playerState{idle, attacking, inMidle}; } #endif // COMMONS_HPP diff --git a/VaporWaveWars/iaenemy.cpp b/VaporWaveWars/iaenemy.cpp index 45b41bb..36944f3 100644 --- a/VaporWaveWars/iaenemy.cpp +++ b/VaporWaveWars/iaenemy.cpp @@ -1,6 +1,6 @@ #include "iaenemy.hpp" -IaEnemy::IaEnemy() : Actor(1) {} +IaEnemy::IaEnemy() : Actor() {} IaEnemy::IaEnemy(int numplayer): Actor(numplayer) {} bool IaEnemy::updateLogic(float deltaTime, sf::RenderWindow *window) { diff --git a/VaporWaveWars/player.cpp b/VaporWaveWars/player.cpp index d1c8520..5b17cb7 100644 --- a/VaporWaveWars/player.cpp +++ b/VaporWaveWars/player.cpp @@ -2,10 +2,12 @@ Player::Player(int num) : Actor(num) { compas = Compas(); + error = false; } -Player::Player() : Actor(1) { +Player::Player() : Actor() { compas = Compas(); + error = false; } bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) { @@ -16,10 +18,19 @@ bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) { bool Player::event(sf::Event e) { switch(e.type) { case (sf::Event::KeyPressed): - if(e.key.code == sf::Keyboard::C) compas.start(); + if(e.key.code == sf::Keyboard::C) { + compas.start(); + error = false; + } if(e.key.code == sf::Keyboard::Space) { - compas.add(); - if (compas.isPressed() && !animate) animate = true; + if (animate == PlayerState::idle && !error) { + compas.add(); + if (compas.isPressed()) animate = PlayerState::attacking; + } + else { + compas.end(); + error = true; //weird? + } } break; case (sf::Event::KeyReleased): diff --git a/VaporWaveWars/player.hpp b/VaporWaveWars/player.hpp index 50f3d80..c3883aa 100644 --- a/VaporWaveWars/player.hpp +++ b/VaporWaveWars/player.hpp @@ -12,6 +12,8 @@ public: protected: bool updateLogic(float deltaTime, sf::RenderWindow *window); +private: + bool error; }; #endif // PLAYER_H