2 players?

This commit is contained in:
marti.lloveras 2017-01-21 05:08:43 +01:00
parent 7f79a87e7f
commit bd87393e9b
3 changed files with 16 additions and 5 deletions

View file

@ -1,6 +1,7 @@
#include "character.hpp" #include "character.hpp"
Character::Character(){ Character::Character(int player){
playerNum = player;
ASSERT(texture.loadFromFile(spriteFile)); ASSERT(texture.loadFromFile(spriteFile));
height = texture.getSize().y/5; height = texture.getSize().y/5;
width = texture.getSize().x/5; width = texture.getSize().x/5;
@ -9,6 +10,13 @@ Character::Character(){
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);
actualState = previousState = PlayerState::idle; actualState = previousState = PlayerState::idle;
if (playerNum == 0){
setPosition(posX1, posY1);
}
else{
setPosition(posX2, posY2);
}
} }
void Character::update(float deltaTime){ void Character::update(float deltaTime){
@ -17,8 +25,7 @@ void Character::update(float deltaTime){
timestamp = 0; timestamp = 0;
if (actualState == PlayerState::attacking and indexX >= 3){ if (actualState == PlayerState::attacking and indexX >= 3){
actualState = PlayerState::idle; setState(PlayerState::idle);
indexX = 0;
} }
else { else {
indexX = (indexX+1)%4; indexX = (indexX+1)%4;

View file

@ -8,16 +8,20 @@ private:
const double frameTime = 0.2; const double frameTime = 0.2;
const int numFrames = 4; const int numFrames = 4;
const std::string spriteFile = "./Resources/spreadsheet.png"; const std::string spriteFile = "./Resources/spreadsheet.png";
//POSICIO PLAYER 1
float posX1 = 0, posY1 = 0;
//POSICIO PLAYER 2
float posX2 = 300, posY2 = 0;
//END CONFIG //END CONFIG
sf::Texture texture; sf::Texture texture;
int indexX, indexY, width, height; int indexX, indexY, width, height;
int posX, posY; int playerNum;
PlayerState::playerState actualState, previousState; PlayerState::playerState actualState, previousState;
float timestamp, next; float timestamp, next;
public: public:
Character(); Character(int player);
void update(float deltaTime); void update(float deltaTime);
void setState(PlayerState::playerState state); void setState(PlayerState::playerState state);