diff --git a/VaporWaveWars/character.cpp b/VaporWaveWars/character.cpp index 61c226d..4640424 100644 --- a/VaporWaveWars/character.cpp +++ b/VaporWaveWars/character.cpp @@ -5,7 +5,7 @@ Character::Character(int player){ ASSERT(texture.loadFromFile(spriteFile)); height = texture.getSize().y/6; width = texture.getSize().x/4; - timestamp = indexX = 0; + timestamp = indexX = idleFrame = 0; indexY = magicNumber; setTexture(texture); sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height); @@ -26,26 +26,31 @@ void Character::update(float deltaTime){ timestamp += deltaTime; if (timestamp >= frameTime){ timestamp = 0; + + std::cout << "PLAYER" << playerNum << ": indexX: " << indexX << ", idleFrame: " << idleFrame << std::endl; sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height); setTextureRect(rect); //Acabar automaticament la animacio de attack - if (actualState == PlayerState::attacking and indexX >= 3){ + if (actualState == PlayerState::attacking and indexX%4 == 3){ setState(PlayerState::idle); } else { indexX = (indexX+1)%4; } + + idleFrame = (idleFrame+1)%4; } } void Character::setState(PlayerState::playerState state){ actualState = state; if (state == PlayerState::idle){ - indexX = 0; + indexX = idleFrame; indexY = 0 + magicNumber; } else if (state == PlayerState::attacking){ + idleFrame = indexX; indexX = 0; indexY = 1 + magicNumber; } diff --git a/VaporWaveWars/character.hpp b/VaporWaveWars/character.hpp index 0d62351..e55a2da 100644 --- a/VaporWaveWars/character.hpp +++ b/VaporWaveWars/character.hpp @@ -5,7 +5,7 @@ class Character : public sf::Sprite{ private: //CONFIG - const double frameTime = 0.15; + const double frameTime = 0.2; const int numFrames = 4; const std::string spriteFile = WORK_DIR+"Resources/spreadsheet.png"; //POSICIO PLAYER 1 @@ -23,6 +23,8 @@ private: float timestamp; public: + int idleFrame; + Character(); Character(int player); void update(float deltaTime); diff --git a/build-VaporWaveWars-Desktop_Qt_5_7_0_GCC_64bit-Debug/VaporWaveWars b/build-VaporWaveWars-Desktop_Qt_5_7_0_GCC_64bit-Debug/VaporWaveWars index d1ece01..791b5e0 100755 Binary files a/build-VaporWaveWars-Desktop_Qt_5_7_0_GCC_64bit-Debug/VaporWaveWars and b/build-VaporWaveWars-Desktop_Qt_5_7_0_GCC_64bit-Debug/VaporWaveWars differ