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"
|
||||
|
||||
Character::Character(){
|
||||
sf::Texture texture;
|
||||
ASSERT(texture.loadFromFile(spriteFile));
|
||||
height = texture.getSize().y;
|
||||
width = texture.getSize().x;
|
||||
|
@ -16,28 +15,13 @@ void Character::update(float deltaTime){
|
|||
timestamp += deltaTime;
|
||||
if (timestamp >= frameTime){
|
||||
timestamp = 0;
|
||||
if (actualState == previousState){
|
||||
if (actualState == PlayerState::idle){
|
||||
indexX = (indexX+1)%numFrames;
|
||||
}
|
||||
else if (actualState == PlayerState::attacking){
|
||||
if (indexX == width){
|
||||
indexX = 0;
|
||||
|
||||
if (actualState == PlayerState::attacking and indexX >= 3){
|
||||
actualState = PlayerState::idle;
|
||||
}
|
||||
}
|
||||
indexX = 0;
|
||||
}
|
||||
else {
|
||||
indexX = 0;
|
||||
if (actualState == PlayerState::idle){
|
||||
indexY = 1;
|
||||
actualState = PlayerState::attacking;
|
||||
}
|
||||
|
||||
else if (actualState == PlayerState::attacking){
|
||||
indexY = 0;
|
||||
actualState = PlayerState::idle;
|
||||
}
|
||||
indexX = (indexX+1)%4;
|
||||
}
|
||||
|
||||
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){
|
||||
previousState = actualState;
|
||||
actualState = state;
|
||||
if (state == PlayerState::idle){
|
||||
indexX = 0;
|
||||
indexY = 0;
|
||||
}
|
||||
else{
|
||||
indexX = 0;
|
||||
indexY = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ private:
|
|||
const std::string spriteFile = "";
|
||||
//CONSTS
|
||||
|
||||
sf::Texture texture;
|
||||
int indexX, indexY, width, height;
|
||||
int posX, posY;
|
||||
PlayerState::playerState actualState, previousState;
|
||||
|
|
|
@ -53,13 +53,17 @@ SOURCES = ../VaporWaveWars/main.cpp \
|
|||
../VaporWaveWars/mygame.cpp \
|
||||
../VaporWaveWars/button.cpp \
|
||||
../VaporWaveWars/character.cpp \
|
||||
../VaporWaveWars/compas.cpp
|
||||
../VaporWaveWars/compas.cpp \
|
||||
../VaporWaveWars/scene.cpp \
|
||||
../VaporWaveWars/menu.cpp
|
||||
OBJECTS = main.o \
|
||||
game.o \
|
||||
mygame.o \
|
||||
button.o \
|
||||
character.o \
|
||||
compas.o
|
||||
compas.o \
|
||||
scene.o \
|
||||
menu.o
|
||||
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/linux.conf \
|
||||
|
@ -208,12 +212,16 @@ DIST = ../../../Qt/5.7/gcc_64/mkspecs/features/spec_pre.prf \
|
|||
commons.hpp \
|
||||
button.hpp \
|
||||
character.hpp \
|
||||
compas.hpp ../VaporWaveWars/main.cpp \
|
||||
compas.hpp \
|
||||
scene.hpp \
|
||||
menu.hpp ../VaporWaveWars/main.cpp \
|
||||
../VaporWaveWars/game.cpp \
|
||||
../VaporWaveWars/mygame.cpp \
|
||||
../VaporWaveWars/button.cpp \
|
||||
../VaporWaveWars/character.cpp \
|
||||
../VaporWaveWars/compas.cpp
|
||||
../VaporWaveWars/compas.cpp \
|
||||
../VaporWaveWars/scene.cpp \
|
||||
../VaporWaveWars/menu.cpp
|
||||
QMAKE_TARGET = VaporWaveWars
|
||||
DESTDIR =
|
||||
TARGET = VaporWaveWars
|
||||
|
@ -560,6 +568,9 @@ compiler_clean:
|
|||
main.o: ../VaporWaveWars/main.cpp ../VaporWaveWars/mygame.hpp \
|
||||
../VaporWaveWars/game.hpp \
|
||||
../VaporWaveWars/commons.hpp \
|
||||
../VaporWaveWars/menu.hpp \
|
||||
../VaporWaveWars/scene.hpp \
|
||||
../VaporWaveWars/button.hpp \
|
||||
../VaporWaveWars/compas.hpp
|
||||
$(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 \
|
||||
../VaporWaveWars/game.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
|
||||
|
||||
button.o: ../VaporWaveWars/button.cpp ../VaporWaveWars/button.hpp \
|
||||
|
@ -585,6 +598,19 @@ compas.o: ../VaporWaveWars/compas.cpp ../VaporWaveWars/compas.hpp \
|
|||
../VaporWaveWars/commons.hpp
|
||||
$(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: FORCE
|
||||
|
|
Binary file not shown.
Reference in a new issue