Merge branch 'master' of github.com:ralucado/WaveGGJ17
This commit is contained in:
commit
ccc203ad9f
7 changed files with 56 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace GameScene {
|
|||
}
|
||||
|
||||
namespace PlayerState {
|
||||
enum playerState{idle, attacking};
|
||||
enum playerState{idle, attacking, inMidle};
|
||||
}
|
||||
|
||||
#endif // COMMONS_HPP
|
||||
|
|
|
@ -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,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):
|
||||
|
|
|
@ -12,6 +12,8 @@ public:
|
|||
protected:
|
||||
bool updateLogic(float deltaTime, sf::RenderWindow *window);
|
||||
|
||||
private:
|
||||
bool error;
|
||||
};
|
||||
|
||||
#endif // PLAYER_H
|
||||
|
|
Reference in a new issue