From 0364fa8ef0b0a8fe661482af9a578f60e60b4596 Mon Sep 17 00:00:00 2001 From: "marti.lloveras" Date: Sat, 21 Jan 2017 03:18:55 +0100 Subject: [PATCH] CHaracter que no funxiona --- VaporWaveWars/character.cpp | 18 +++++++++++++++--- VaporWaveWars/character.hpp | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) 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;