]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added walking animation to player
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 7 Oct 2015 12:35:15 +0000 (08:35 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 7 Oct 2015 12:35:15 +0000 (08:35 -0400)
Makefile
include/common.h
include/entities.h
main.cpp
src/common.cpp
src/entities.cpp
src/ui.cpp

index 983f6365455310c3443f3ece46850d122525013e..983bf308994dd16d4e3d7eb600a96cc5c19a61d8 100644 (file)
--- 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\r
 \r
 all:\r
+       @rm out/*.o -f\r
        @cd src; $(MAKE) $(MFLAGS)\r
        @echo "  CXX main.cpp"\r
        @g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS)\r
index b283ec88e53f902291a304adaa47b6102b45e5db..7472edfef80a79fce3aaa6f93c50ea5edd429cee 100644 (file)
@@ -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;
index eeb58e494a13b41fb6eeb810f0ad7d2b8641ae76..dacf394de2e924b81bbc0817cfc40189162e6c40 100644 (file)
@@ -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);
index 4aaf1615d4416345138fe84e6b845bd06633d951..c11da6d692e7ba2f70a36f630c3549b9ff5eba1e 100644 (file)
--- 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;
 }
index 124d9990b145e12dc2c75086eb6cb53fb9888ce1..62dc6af7f67ed98200eeccae24dab7413451498c 100644 (file)
@@ -19,7 +19,7 @@ GLuint loadTexture(const char *fileName){
   SDL_Surface *image = IMG_Load(fileName);
  
   //SDL_DisplayFormatAlpha(image);
+
   unsigned object(0);
  
   glGenTextures(1, &object);
index 46d445b19b5ef8ca43566104f39555c7b308c661..197bea01d118addaf2307e778c4c590619a31fbb 100644 (file)
@@ -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
index cd5de15b06f15cf43b3dd9501a1f847914176b4a..e4af3e238c16712cf1c01f5fe82e5432a7b5f215 100644 (file)
@@ -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;