vaporwave

This commit is contained in:
marti.lloveras 2017-01-21 14:02:19 +01:00
parent 1184a03f5f
commit 6258dc8e7d
3 changed files with 11 additions and 4 deletions

View file

@ -5,7 +5,7 @@ Character::Character(int player){
ASSERT(texture.loadFromFile(spriteFile)); ASSERT(texture.loadFromFile(spriteFile));
height = texture.getSize().y/6; height = texture.getSize().y/6;
width = texture.getSize().x/4; width = texture.getSize().x/4;
timestamp = indexX = 0; timestamp = indexX = idleFrame = 0;
indexY = magicNumber; indexY = magicNumber;
setTexture(texture); setTexture(texture);
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height); sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
@ -26,26 +26,31 @@ void Character::update(float deltaTime){
timestamp += deltaTime; timestamp += deltaTime;
if (timestamp >= frameTime){ if (timestamp >= frameTime){
timestamp = 0; timestamp = 0;
std::cout << "PLAYER" << playerNum << ": indexX: " << indexX << ", idleFrame: " << idleFrame << std::endl;
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height); sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
setTextureRect(rect); setTextureRect(rect);
//Acabar automaticament la animacio de attack //Acabar automaticament la animacio de attack
if (actualState == PlayerState::attacking and indexX >= 3){ if (actualState == PlayerState::attacking and indexX%4 == 3){
setState(PlayerState::idle); setState(PlayerState::idle);
} }
else { else {
indexX = (indexX+1)%4; indexX = (indexX+1)%4;
} }
idleFrame = (idleFrame+1)%4;
} }
} }
void Character::setState(PlayerState::playerState state){ void Character::setState(PlayerState::playerState state){
actualState = state; actualState = state;
if (state == PlayerState::idle){ if (state == PlayerState::idle){
indexX = 0; indexX = idleFrame;
indexY = 0 + magicNumber; indexY = 0 + magicNumber;
} }
else if (state == PlayerState::attacking){ else if (state == PlayerState::attacking){
idleFrame = indexX;
indexX = 0; indexX = 0;
indexY = 1 + magicNumber; indexY = 1 + magicNumber;
} }

View file

@ -5,7 +5,7 @@
class Character : public sf::Sprite{ class Character : public sf::Sprite{
private: private:
//CONFIG //CONFIG
const double frameTime = 0.15; const double frameTime = 0.2;
const int numFrames = 4; const int numFrames = 4;
const std::string spriteFile = WORK_DIR+"Resources/spreadsheet.png"; const std::string spriteFile = WORK_DIR+"Resources/spreadsheet.png";
//POSICIO PLAYER 1 //POSICIO PLAYER 1
@ -23,6 +23,8 @@ private:
float timestamp; float timestamp;
public: public:
int idleFrame;
Character(); Character();
Character(int player); Character(int player);
void update(float deltaTime); void update(float deltaTime);