This repository has been archived on 2022-12-14. You can view files and clone it, but cannot push or open issues or pull requests.
WaveGGJ17/VaporWaveWars/actor.cpp
2017-01-21 18:10:31 +01:00

45 lines
1.2 KiB
C++

#include "actor.hpp"
Actor::Actor() {
animate = PlayerState::attacking;
this->character = new Character(0);
}
Actor::Actor(int num) {
animate = PlayerState::attacking;
this->character = new Character(num);
}
void Actor::draw(sf::RenderWindow *window) {
window->draw(*character);
}
bool Actor::update(float deltaTime, sf::RenderWindow *window) {
character->update(deltaTime);
if (animate == PlayerState::attacking) {
character->setState(PlayerState::attacking);
animate = PlayerState::inMidle;
}
else if (animate == PlayerState::hurt) {
character->setState(PlayerState::hurt);
animate = PlayerState::inMidle;
}
else if (animate == PlayerState::inMidle) {
if (character->isLastFrame()) animate = PlayerState::idle;
}
return this->updateLogic(deltaTime, window);
}
bool Actor::hitBy(Compas enemy) {
bool hit = enemy == compas;
if (hit) std::cout << "dodge" << std::endl;
else std::cout << "hit" << std::endl;
if (!hit) {
character->setState(PlayerState::hurt);
animate = PlayerState::inMidle;
}
return hit;
}
Compas Actor::getAttack() const {
return compas;
}