add error feature
This commit is contained in:
parent
a843c0faca
commit
da23125f92
6 changed files with 46 additions and 10 deletions
|
@ -1,7 +1,12 @@
|
||||||
#include "actor.hpp"
|
#include "actor.hpp"
|
||||||
Actor::Actor() {}
|
Actor::Actor() {
|
||||||
|
score = 0;
|
||||||
|
animate = PlayerState::attacking;
|
||||||
|
this->character = new Character(0);
|
||||||
|
}
|
||||||
|
|
||||||
Actor::Actor(int num) {
|
Actor::Actor(int num) {
|
||||||
|
score = 0;
|
||||||
animate = PlayerState::attacking;
|
animate = PlayerState::attacking;
|
||||||
this->character = new Character(num);
|
this->character = new Character(num);
|
||||||
}
|
}
|
||||||
|
@ -22,11 +27,20 @@ bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
return this->updateLogic(deltaTime, 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;
|
if (enemy == compas) std::cout << "dodge" << std::endl;
|
||||||
else std::cout << "hit" << std::endl;
|
else std::cout << "hit" << std::endl;
|
||||||
|
return enemy == compas;
|
||||||
}
|
}
|
||||||
|
|
||||||
Compas Actor::getAttack() const {
|
Compas Actor::getAttack() const {
|
||||||
return compas;
|
return compas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Actor::upScore() {
|
||||||
|
++score;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Actor::getScore() const {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
|
@ -12,10 +12,13 @@ public:
|
||||||
Actor(int num);
|
Actor(int num);
|
||||||
bool update(float deltaTime, sf::RenderWindow *window);
|
bool update(float deltaTime, sf::RenderWindow *window);
|
||||||
void draw(sf::RenderWindow *window);
|
void draw(sf::RenderWindow *window);
|
||||||
void hitBy(Compas enemy) const;
|
bool hitBy(Compas enemy) const;
|
||||||
Compas getAttack() const;
|
Compas getAttack() const;
|
||||||
virtual bool event(sf::Event e) = 0;
|
virtual bool event(sf::Event e) = 0;
|
||||||
|
void upScore();
|
||||||
|
int getScore() const;
|
||||||
protected:
|
protected:
|
||||||
|
int score;
|
||||||
Compas compas;
|
Compas compas;
|
||||||
PlayerState::playerState animate;
|
PlayerState::playerState animate;
|
||||||
virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0;
|
virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0;
|
||||||
|
|
|
@ -45,7 +45,11 @@ void Combat::updateEvents(sf::Event e) {
|
||||||
if (playerOneTurn) {
|
if (playerOneTurn) {
|
||||||
bool aux = player->event(e);
|
bool aux = player->event(e);
|
||||||
if (!aux) { //end of player one ritm
|
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;
|
else playerOneTurn = aux;
|
||||||
attacking = !attacking;
|
attacking = !attacking;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +62,11 @@ void Combat::updateEvents(sf::Event e) {
|
||||||
|
|
||||||
void Combat::enemyManager(bool aux) {
|
void Combat::enemyManager(bool aux) {
|
||||||
if (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;
|
else playerOneTurn = aux;
|
||||||
attacking = !attacking;
|
attacking = !attacking;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "iaenemy.hpp"
|
#include "iaenemy.hpp"
|
||||||
|
|
||||||
IaEnemy::IaEnemy() : Actor(1) {}
|
IaEnemy::IaEnemy() : Actor() {}
|
||||||
IaEnemy::IaEnemy(int numplayer): Actor(numplayer) {}
|
IaEnemy::IaEnemy(int numplayer): Actor(numplayer) {}
|
||||||
bool IaEnemy::updateLogic(float deltaTime, sf::RenderWindow *window) {
|
bool IaEnemy::updateLogic(float deltaTime, sf::RenderWindow *window) {
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
Player::Player(int num) : Actor(num) {
|
Player::Player(int num) : Actor(num) {
|
||||||
compas = Compas();
|
compas = Compas();
|
||||||
|
error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::Player() : Actor(1) {
|
Player::Player() : Actor() {
|
||||||
compas = Compas();
|
compas = Compas();
|
||||||
|
error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) {
|
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) {
|
bool Player::event(sf::Event e) {
|
||||||
switch(e.type) {
|
switch(e.type) {
|
||||||
case (sf::Event::KeyPressed):
|
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(e.key.code == sf::Keyboard::Space) {
|
||||||
if (compas.isPressed() && animate == PlayerState::idle) {
|
if (animate == PlayerState::idle && !error) {
|
||||||
compas.add();
|
compas.add();
|
||||||
animate = PlayerState::attacking;
|
if (compas.isPressed()) animate = PlayerState::attacking;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
compas.end();
|
||||||
|
error = true; //weird?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -12,6 +12,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
bool updateLogic(float deltaTime, sf::RenderWindow *window);
|
bool updateLogic(float deltaTime, sf::RenderWindow *window);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool error;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYER_H
|
#endif // PLAYER_H
|
||||||
|
|
Reference in a new issue