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));
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;
}

View file

@ -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);