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/character.cpp
2017-01-21 04:30:12 +01:00

44 lines
1.1 KiB
C++

#include "character.hpp"
Character::Character(){
ASSERT(texture.loadFromFile(spriteFile));
height = texture.getSize().y;
width = texture.getSize().x;
next = timestamp = indexX = indexY = 0;
setTexture(texture);
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
setTextureRect(rect);
actualState = previousState = PlayerState::idle;
}
void Character::update(float deltaTime){
timestamp += deltaTime;
if (timestamp >= frameTime){
timestamp = 0;
if (actualState == PlayerState::attacking and indexX >= 3){
actualState = PlayerState::idle;
indexX = 0;
}
else {
indexX = (indexX+1)%4;
}
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
setTextureRect(rect);
}
}
void Character::setState(PlayerState::playerState state){
previousState = actualState;
actualState = state;
if (state == PlayerState::idle){
indexX = 0;
indexY = 0;
}
else{
indexX = 0;
indexY = 1;
}
}