aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2015-10-07 08:35:15 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2015-10-07 08:35:15 -0400
commitf49eb15dbc7b8d77ff9580ccd44d42b9969969fc (patch)
tree825f84366d9f9212369a3ab10743873eb7a405f6
parent6986331694adb60265c815af6637caf2dbc23ede (diff)
Added walking animation to player
-rw-r--r--Makefile1
-rw-r--r--include/common.h1
-rw-r--r--include/entities.h2
-rw-r--r--main.cpp17
-rw-r--r--src/common.cpp2
-rw-r--r--src/entities.cpp42
-rw-r--r--src/ui.cpp3
7 files changed, 47 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 983f636..983bf30 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ LIBS = -lGL -lSDL2_image -lSDL2_mixer
FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype
all:
+ @rm out/*.o -f
@cd src; $(MAKE) $(MFLAGS)
@echo " CXX main.cpp"
@g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS)
diff --git a/include/common.h b/include/common.h
index b283ec8..7472edf 100644
--- a/include/common.h
+++ b/include/common.h
@@ -45,6 +45,7 @@ GLuint loadTexture(const char *fileName);
extern bool gameRunning;
extern unsigned int deltaTime;
+extern unsigned int loops;
extern FILE* config;
extern FILE* names;
diff --git a/include/entities.h b/include/entities.h
index eeb58e4..dacf394 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -39,7 +39,7 @@ public:
char* name;
GENDER gender;
- unsigned int texture; //TODO: ADD TEXTURES
+ GLuint texture[3]; //TODO: ADD TEXTURES
void spawn(float, float);
diff --git a/main.cpp b/main.cpp
index 4aaf161..c11da6d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -26,6 +26,7 @@ FILE* names;
Mix_Music *music;
Mix_Chunk *horn;
+unsigned int loops = 0;
extern void initEverything(void);
@@ -57,20 +58,6 @@ int main(int argc, char *argv[]){
std::cout << "SDL_mixer could not initialize! SDL_mixer Error: " << Mix_GetError() << std::endl;
}
atexit(Mix_Quit);
-
-<<<<<<< HEAD
- //Load music
- music = Mix_LoadMUS("assets/BennyHillTheme.wav");
- horn = Mix_LoadWAV("assets/air-horn-club-sample_1.wav");
- if( music == NULL ){
- printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
- }
- //Mix_PlayMusic( music, -1 );
-
-
-
-=======
->>>>>>> 1c0767766506407babdfefea9efe2b5627569244
// Turn on double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// Create the window
@@ -247,4 +234,6 @@ void logic(){
}
}
}
+ loops++;
+ //std::cout << loops << std::endl;
}
diff --git a/src/common.cpp b/src/common.cpp
index 124d999..62dc6af 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -19,7 +19,7 @@ GLuint loadTexture(const char *fileName){
SDL_Surface *image = IMG_Load(fileName);
//SDL_DisplayFormatAlpha(image);
-
+
unsigned object(0);
glGenTextures(1, &object);
diff --git a/src/entities.cpp b/src/entities.cpp
index 46d445b..197bea0 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -42,7 +42,35 @@ void Entity::draw(void){ //draws the entities
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,texture);
+ if(type == PLAYERT){
+ static int texState = 0;
+ static bool up = true;
+ if(loops % (int)((float)5 / (float)speed) == 0){
+ if(up){
+ texState+=1;
+ if(texState==2)up=false;
+ }else if(!up){
+ texState-=1;
+ if(texState==0)up=true;
+ }
+ }
+ std::cout << texState << std::endl;
+ if(vel.x != 0){
+ switch(texState){
+ case 0:
+ glBindTexture(GL_TEXTURE_2D,texture[1]);
+ break;
+ case 1:
+ glBindTexture(GL_TEXTURE_2D,texture[0]);
+ break;
+ case 2:
+ glBindTexture(GL_TEXTURE_2D,texture[2]);
+ break;
+ }
+ }else glBindTexture(GL_TEXTURE_2D,texture[0]);
+ }else{
+ glBindTexture(GL_TEXTURE_2D,texture[0]);
+ }
glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
@@ -111,7 +139,9 @@ Player::Player(){ //sets all of the player specific traits on object creation
alive = true;
ground = false;
near = true;
- texture = loadTexture("assets/player.png");
+ texture[0] = loadTexture("assets/player.png");
+ texture[1] = loadTexture("assets/player1.png");
+ texture[2] = loadTexture("assets/player2.png");
inv = new Inventory(PLAYER_INV_SIZE);
}
@@ -128,7 +158,9 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
alive = true;
canMove = true;
near = false;
- texture = loadTexture("assets/NPC.png");
+ texture[0] = loadTexture("assets/NPC.png");
+ texture[1] = 0;
+ texture[2] = 0;
inv = new Inventory(NPC_INV_SIZE);
}
@@ -152,7 +184,9 @@ Structures::Structures(){ //sets the structure type
speed = 0;
alive = true;
near = false;
- texture = loadTexture("assets/house1.png");
+ texture[0] = loadTexture("assets/house1.png");
+ texture[1] = 0;
+ texture[2] = 0;
}
unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure based off of type and coords
diff --git a/src/ui.cpp b/src/ui.cpp
index cd5de15..e4af3e2 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -214,6 +214,7 @@ namespace ui {
if(SDL_KEY==SDLK_i)currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
if(SDL_KEY==SDLK_k)currentWorld=currentWorld->goWorldFront(player); // Go forward a layer if possible
if(SDL_KEY==SDLK_LSHIFT)player->speed = 3; // Sprint
+ if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
}
if(SDL_KEY==SDLK_F3)debug^=true;
break;
@@ -225,7 +226,7 @@ namespace ui {
if(SDL_KEY==SDLK_d){right=false;}
if(!left&&!right)player->vel.x=0;
if(SDL_KEY==SDLK_LSHIFT)player->speed = 1;
-
+ if(SDL_KEY==SDLK_LCTRL)player->speed = 1;
break;
default:
break;