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"
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -12,6 +12,8 @@ public:
|
|||
protected:
|
||||
bool updateLogic(float deltaTime, sf::RenderWindow *window);
|
||||
|
||||
private:
|
||||
bool error;
|
||||
};
|
||||
|
||||
#endif // PLAYER_H
|
||||
|
|
Reference in a new issue