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
marti.lloveras a738f260ef Character
2017-01-21 01:53:45 +01:00

40 lines
1.1 KiB
C++

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