From f49eb15dbc7b8d77ff9580ccd44d42b9969969fc Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Wed, 7 Oct 2015 08:35:15 -0400 Subject: Added walking animation to player --- Makefile | 1 + include/common.h | 1 + include/entities.h | 2 +- main.cpp | 17 +++-------------- src/common.cpp | 2 +- src/entities.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- src/ui.cpp | 3 ++- 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; -- cgit v1.2.3 From 4244e4e535bcc2690e96468c4ac688a8a6002e2e Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Wed, 7 Oct 2015 08:35:51 -0400 Subject: Added walking animation to player --- assets/player1.png | Bin 0 -> 586 bytes assets/player2.png | Bin 0 -> 590 bytes out/Quest.o | Bin 0 -> 32596 bytes out/common.o | Bin 0 -> 2188 bytes out/entities.o | Bin 0 -> 93800 bytes out/gameplay.o | Bin 0 -> 43748 bytes out/inventory.o | Bin 0 -> 3156 bytes out/ui.o | Bin 0 -> 9844 bytes out/world.o | Bin 0 -> 37540 bytes 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/player1.png create mode 100644 assets/player2.png create mode 100644 out/Quest.o create mode 100644 out/common.o create mode 100644 out/entities.o create mode 100644 out/gameplay.o create mode 100644 out/inventory.o create mode 100644 out/ui.o create mode 100644 out/world.o diff --git a/assets/player1.png b/assets/player1.png new file mode 100644 index 0000000..5d8fbc6 Binary files /dev/null and b/assets/player1.png differ diff --git a/assets/player2.png b/assets/player2.png new file mode 100644 index 0000000..7f14884 Binary files /dev/null and b/assets/player2.png differ diff --git a/out/Quest.o b/out/Quest.o new file mode 100644 index 0000000..50fd936 Binary files /dev/null and b/out/Quest.o differ diff --git a/out/common.o b/out/common.o new file mode 100644 index 0000000..044750a Binary files /dev/null and b/out/common.o differ diff --git a/out/entities.o b/out/entities.o new file mode 100644 index 0000000..2fe8908 Binary files /dev/null and b/out/entities.o differ diff --git a/out/gameplay.o b/out/gameplay.o new file mode 100644 index 0000000..6894853 Binary files /dev/null and b/out/gameplay.o differ diff --git a/out/inventory.o b/out/inventory.o new file mode 100644 index 0000000..559aff1 Binary files /dev/null and b/out/inventory.o differ diff --git a/out/ui.o b/out/ui.o new file mode 100644 index 0000000..73dddad Binary files /dev/null and b/out/ui.o differ diff --git a/out/world.o b/out/world.o new file mode 100644 index 0000000..6f79983 Binary files /dev/null and b/out/world.o differ -- cgit v1.2.3