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

View file

@ -8,16 +8,20 @@ private:
const double frameTime = 0.2;
const int numFrames = 4;
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
sf::Texture texture;
int indexX, indexY, width, height;
int posX, posY;
int playerNum;
PlayerState::playerState actualState, previousState;
float timestamp, next;
public:
Character();
Character(int player);
void update(float deltaTime);
void setState(PlayerState::playerState state);