diff --git a/VaporWaveWars/character.cpp b/VaporWaveWars/character.cpp index cf12d83..222f4e7 100644 --- a/VaporWaveWars/character.cpp +++ b/VaporWaveWars/character.cpp @@ -5,8 +5,11 @@ Character::Character(){ ASSERT(texture.loadFromFile(spriteFile)); height = texture.getSize().y; width = texture.getSize().x; - next = 0; + 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){ @@ -26,11 +29,15 @@ void Character::update(float deltaTime){ } else { indexX = 0; - if (actualState == PlayerState::idle) + if (actualState == PlayerState::idle){ + indexY = 1; actualState = PlayerState::attacking; + } - else if (actualState == PlayerState::attacking) + else if (actualState == PlayerState::attacking){ + indexY = 0; actualState = PlayerState::idle; + } } sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height); @@ -38,3 +45,8 @@ void Character::update(float deltaTime){ } } +void Character::setState(PlayerState::playerState state){ + previousState = actualState; + actualState = state; +} + diff --git a/VaporWaveWars/character.hpp b/VaporWaveWars/character.hpp index 43c18bb..c1eb269 100644 --- a/VaporWaveWars/character.hpp +++ b/VaporWaveWars/character.hpp @@ -4,9 +4,11 @@ class Character : public sf::Sprite{ private: + //CONSTS const double frameTime = 0.2; const int numFrames = 4; const std::string spriteFile = ""; + //CONSTS int indexX, indexY, width, height; int posX, posY;