Character funcionaaa
This commit is contained in:
parent
74d7b3aa73
commit
96b44d2506
4 changed files with 45 additions and 26 deletions
|
@ -1,7 +1,6 @@
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
|
|
||||||
Character::Character(){
|
Character::Character(){
|
||||||
sf::Texture texture;
|
|
||||||
ASSERT(texture.loadFromFile(spriteFile));
|
ASSERT(texture.loadFromFile(spriteFile));
|
||||||
height = texture.getSize().y;
|
height = texture.getSize().y;
|
||||||
width = texture.getSize().x;
|
width = texture.getSize().x;
|
||||||
|
@ -16,28 +15,13 @@ void Character::update(float deltaTime){
|
||||||
timestamp += deltaTime;
|
timestamp += deltaTime;
|
||||||
if (timestamp >= frameTime){
|
if (timestamp >= frameTime){
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
if (actualState == previousState){
|
|
||||||
if (actualState == PlayerState::idle){
|
if (actualState == PlayerState::attacking and indexX >= 3){
|
||||||
indexX = (indexX+1)%numFrames;
|
|
||||||
}
|
|
||||||
else if (actualState == PlayerState::attacking){
|
|
||||||
if (indexX == width){
|
|
||||||
indexX = 0;
|
|
||||||
actualState = PlayerState::idle;
|
actualState = PlayerState::idle;
|
||||||
}
|
indexX = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
indexX = 0;
|
indexX = (indexX+1)%4;
|
||||||
if (actualState == PlayerState::idle){
|
|
||||||
indexY = 1;
|
|
||||||
actualState = PlayerState::attacking;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (actualState == PlayerState::attacking){
|
|
||||||
indexY = 0;
|
|
||||||
actualState = PlayerState::idle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
|
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
|
||||||
|
@ -48,5 +32,13 @@ void Character::update(float deltaTime){
|
||||||
void Character::setState(PlayerState::playerState state){
|
void Character::setState(PlayerState::playerState state){
|
||||||
previousState = actualState;
|
previousState = actualState;
|
||||||
actualState = state;
|
actualState = state;
|
||||||
|
if (state == PlayerState::idle){
|
||||||
|
indexX = 0;
|
||||||
|
indexY = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
indexX = 0;
|
||||||
|
indexY = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ private:
|
||||||
const std::string spriteFile = "";
|
const std::string spriteFile = "";
|
||||||
//CONSTS
|
//CONSTS
|
||||||
|
|
||||||
|
sf::Texture texture;
|
||||||
int indexX, indexY, width, height;
|
int indexX, indexY, width, height;
|
||||||
int posX, posY;
|
int posX, posY;
|
||||||
PlayerState::playerState actualState, previousState;
|
PlayerState::playerState actualState, previousState;
|
||||||
|
|
|
@ -53,13 +53,17 @@ SOURCES = ../VaporWaveWars/main.cpp \
|
||||||
../VaporWaveWars/mygame.cpp \
|
../VaporWaveWars/mygame.cpp \
|
||||||
../VaporWaveWars/button.cpp \
|
../VaporWaveWars/button.cpp \
|
||||||
../VaporWaveWars/character.cpp \
|
../VaporWaveWars/character.cpp \
|
||||||
../VaporWaveWars/compas.cpp
|
../VaporWaveWars/compas.cpp \
|
||||||
|
../VaporWaveWars/scene.cpp \
|
||||||
|
../VaporWaveWars/menu.cpp
|
||||||
OBJECTS = main.o \
|
OBJECTS = main.o \
|
||||||
game.o \
|
game.o \
|
||||||
mygame.o \
|
mygame.o \
|
||||||
button.o \
|
button.o \
|
||||||
character.o \
|
character.o \
|
||||||
compas.o
|
compas.o \
|
||||||
|
scene.o \
|
||||||
|
menu.o
|
||||||
DIST = ../../../Qt/5.7/gcc_64/mkspecs/features/spec_pre.prf \
|
DIST = ../../../Qt/5.7/gcc_64/mkspecs/features/spec_pre.prf \
|
||||||
../../../Qt/5.7/gcc_64/mkspecs/common/unix.conf \
|
../../../Qt/5.7/gcc_64/mkspecs/common/unix.conf \
|
||||||
../../../Qt/5.7/gcc_64/mkspecs/common/linux.conf \
|
../../../Qt/5.7/gcc_64/mkspecs/common/linux.conf \
|
||||||
|
@ -208,12 +212,16 @@ DIST = ../../../Qt/5.7/gcc_64/mkspecs/features/spec_pre.prf \
|
||||||
commons.hpp \
|
commons.hpp \
|
||||||
button.hpp \
|
button.hpp \
|
||||||
character.hpp \
|
character.hpp \
|
||||||
compas.hpp ../VaporWaveWars/main.cpp \
|
compas.hpp \
|
||||||
|
scene.hpp \
|
||||||
|
menu.hpp ../VaporWaveWars/main.cpp \
|
||||||
../VaporWaveWars/game.cpp \
|
../VaporWaveWars/game.cpp \
|
||||||
../VaporWaveWars/mygame.cpp \
|
../VaporWaveWars/mygame.cpp \
|
||||||
../VaporWaveWars/button.cpp \
|
../VaporWaveWars/button.cpp \
|
||||||
../VaporWaveWars/character.cpp \
|
../VaporWaveWars/character.cpp \
|
||||||
../VaporWaveWars/compas.cpp
|
../VaporWaveWars/compas.cpp \
|
||||||
|
../VaporWaveWars/scene.cpp \
|
||||||
|
../VaporWaveWars/menu.cpp
|
||||||
QMAKE_TARGET = VaporWaveWars
|
QMAKE_TARGET = VaporWaveWars
|
||||||
DESTDIR =
|
DESTDIR =
|
||||||
TARGET = VaporWaveWars
|
TARGET = VaporWaveWars
|
||||||
|
@ -560,6 +568,9 @@ compiler_clean:
|
||||||
main.o: ../VaporWaveWars/main.cpp ../VaporWaveWars/mygame.hpp \
|
main.o: ../VaporWaveWars/main.cpp ../VaporWaveWars/mygame.hpp \
|
||||||
../VaporWaveWars/game.hpp \
|
../VaporWaveWars/game.hpp \
|
||||||
../VaporWaveWars/commons.hpp \
|
../VaporWaveWars/commons.hpp \
|
||||||
|
../VaporWaveWars/menu.hpp \
|
||||||
|
../VaporWaveWars/scene.hpp \
|
||||||
|
../VaporWaveWars/button.hpp \
|
||||||
../VaporWaveWars/compas.hpp
|
../VaporWaveWars/compas.hpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../VaporWaveWars/main.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../VaporWaveWars/main.cpp
|
||||||
|
|
||||||
|
@ -570,7 +581,9 @@ game.o: ../VaporWaveWars/game.cpp ../VaporWaveWars/game.hpp \
|
||||||
mygame.o: ../VaporWaveWars/mygame.cpp ../VaporWaveWars/mygame.hpp \
|
mygame.o: ../VaporWaveWars/mygame.cpp ../VaporWaveWars/mygame.hpp \
|
||||||
../VaporWaveWars/game.hpp \
|
../VaporWaveWars/game.hpp \
|
||||||
../VaporWaveWars/commons.hpp \
|
../VaporWaveWars/commons.hpp \
|
||||||
../VaporWaveWars/compas.hpp
|
../VaporWaveWars/menu.hpp \
|
||||||
|
../VaporWaveWars/scene.hpp \
|
||||||
|
../VaporWaveWars/button.hpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mygame.o ../VaporWaveWars/mygame.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mygame.o ../VaporWaveWars/mygame.cpp
|
||||||
|
|
||||||
button.o: ../VaporWaveWars/button.cpp ../VaporWaveWars/button.hpp \
|
button.o: ../VaporWaveWars/button.cpp ../VaporWaveWars/button.hpp \
|
||||||
|
@ -585,6 +598,19 @@ compas.o: ../VaporWaveWars/compas.cpp ../VaporWaveWars/compas.hpp \
|
||||||
../VaporWaveWars/commons.hpp
|
../VaporWaveWars/commons.hpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o compas.o ../VaporWaveWars/compas.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o compas.o ../VaporWaveWars/compas.cpp
|
||||||
|
|
||||||
|
scene.o: ../VaporWaveWars/scene.cpp ../VaporWaveWars/scene.hpp \
|
||||||
|
../VaporWaveWars/commons.hpp \
|
||||||
|
../VaporWaveWars/game.hpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o scene.o ../VaporWaveWars/scene.cpp
|
||||||
|
|
||||||
|
menu.o: ../VaporWaveWars/menu.cpp ../VaporWaveWars/menu.hpp \
|
||||||
|
../VaporWaveWars/commons.hpp \
|
||||||
|
../VaporWaveWars/scene.hpp \
|
||||||
|
../VaporWaveWars/game.hpp \
|
||||||
|
../VaporWaveWars/button.hpp \
|
||||||
|
../VaporWaveWars/mygame.hpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o menu.o ../VaporWaveWars/menu.cpp
|
||||||
|
|
||||||
####### Install
|
####### Install
|
||||||
|
|
||||||
install: FORCE
|
install: FORCE
|
||||||
|
|
Binary file not shown.
Reference in a new issue