From da23125f923755741825d024bdd6e8a103e2b1aa Mon Sep 17 00:00:00 2001 From: serk Date: Sat, 21 Jan 2017 13:57:32 +0100 Subject: [PATCH] add error feature --- VaporWaveWars/actor.cpp | 18 ++++++++++++++++-- VaporWaveWars/actor.hpp | 5 ++++- VaporWaveWars/combat.cpp | 12 ++++++++++-- VaporWaveWars/iaenemy.cpp | 2 +- VaporWaveWars/player.cpp | 17 +++++++++++++---- VaporWaveWars/player.hpp | 2 ++ 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/VaporWaveWars/actor.cpp b/VaporWaveWars/actor.cpp index 939d73a..cbd6f6d 100644 --- a/VaporWaveWars/actor.cpp +++ b/VaporWaveWars/actor.cpp @@ -1,7 +1,12 @@ #include "actor.hpp" -Actor::Actor() {} +Actor::Actor() { + score = 0; + animate = PlayerState::attacking; + this->character = new Character(0); +} Actor::Actor(int num) { + score = 0; animate = PlayerState::attacking; this->character = new Character(num); } @@ -22,11 +27,20 @@ bool Actor::update(float deltaTime, sf::RenderWindow *window) { 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 2edee17..6d465ac 100644 --- a/VaporWaveWars/actor.hpp +++ b/VaporWaveWars/actor.hpp @@ -12,10 +12,13 @@ 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; PlayerState::playerState animate; virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0; diff --git a/VaporWaveWars/combat.cpp b/VaporWaveWars/combat.cpp index bd904b3..322130e 100644 --- a/VaporWaveWars/combat.cpp +++ b/VaporWaveWars/combat.cpp @@ -45,7 +45,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; } @@ -58,7 +62,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/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 10a63d4..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,11 +18,18 @@ 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) { - if (compas.isPressed() && animate == PlayerState::idle) { + if (animate == PlayerState::idle && !error) { compas.add(); - animate = PlayerState::attacking; + if (compas.isPressed()) animate = PlayerState::attacking; + } + else { + compas.end(); + error = true; //weird? } } break; 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