diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-07 08:40:43 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-07 08:40:43 -0400 |
commit | 40efc2db79c205d122ca9557c9cd0d5679a37446 (patch) | |
tree | d6a227b598ca890de6ecf566a2c6dd2350d17e74 | |
parent | f28fda996331de5dac8fc2f20ea0898527239fe5 (diff) | |
parent | aad308a8938135a9fd2614f2cf47774918539847 (diff) |
world improvement
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | assets/player1.png | bin | 0 -> 586 bytes | |||
-rw-r--r-- | assets/player2.png | bin | 0 -> 590 bytes | |||
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | include/entities.h | 2 | ||||
-rw-r--r-- | main.cpp | 5 | ||||
-rw-r--r-- | out/Quest.o | bin | 0 -> 32596 bytes | |||
-rw-r--r-- | out/common.o | bin | 0 -> 2188 bytes | |||
-rw-r--r-- | out/entities.o | bin | 0 -> 93560 bytes | |||
-rw-r--r-- | out/gameplay.o | bin | 0 -> 43748 bytes | |||
-rw-r--r-- | out/inventory.o | bin | 0 -> 3156 bytes | |||
-rw-r--r-- | out/ui.o | bin | 0 -> 9844 bytes | |||
-rw-r--r-- | out/world.o | bin | 0 -> 37540 bytes | |||
-rw-r--r-- | src/common.cpp | 2 | ||||
-rw-r--r-- | src/entities.cpp | 40 | ||||
-rw-r--r-- | src/ui.cpp | 3 |
16 files changed, 46 insertions, 11 deletions
@@ -2,8 +2,8 @@ LIBS = -lGL -lSDL2_image -lSDL2_mixer FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype
-all:
- @rm -f out/*.o
+all: + @rm -f out/*.o @cd src; $(MAKE) $(MFLAGS)
@echo " CXX main.cpp"
@g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS)
diff --git a/assets/player1.png b/assets/player1.png Binary files differnew file mode 100644 index 0000000..5d8fbc6 --- /dev/null +++ b/assets/player1.png diff --git a/assets/player2.png b/assets/player2.png Binary files differnew file mode 100644 index 0000000..7f14884 --- /dev/null +++ b/assets/player2.png diff --git a/include/common.h b/include/common.h index 03385cd..3015b11 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); @@ -27,6 +27,7 @@ FILE* names; Mix_Music *music; Mix_Chunk *horn; +unsigned int loops = 0; extern void initEverything(void); @@ -58,8 +59,7 @@ int main(int argc, char *argv[]){ std::cout << "SDL_mixer could not initialize! SDL_mixer Error: " << Mix_GetError() << std::endl; } atexit(Mix_Quit); - -// Turn on double buffering + // Turn on double buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Create the window window = SDL_CreateWindow("Independent Study v.0.2 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL @@ -246,4 +246,5 @@ void logic(){ } } } + loops++; } diff --git a/out/Quest.o b/out/Quest.o Binary files differnew file mode 100644 index 0000000..50fd936 --- /dev/null +++ b/out/Quest.o diff --git a/out/common.o b/out/common.o Binary files differnew file mode 100644 index 0000000..044750a --- /dev/null +++ b/out/common.o diff --git a/out/entities.o b/out/entities.o Binary files differnew file mode 100644 index 0000000..db0a4aa --- /dev/null +++ b/out/entities.o diff --git a/out/gameplay.o b/out/gameplay.o Binary files differnew file mode 100644 index 0000000..6894853 --- /dev/null +++ b/out/gameplay.o diff --git a/out/inventory.o b/out/inventory.o Binary files differnew file mode 100644 index 0000000..559aff1 --- /dev/null +++ b/out/inventory.o diff --git a/out/ui.o b/out/ui.o Binary files differnew file mode 100644 index 0000000..73dddad --- /dev/null +++ b/out/ui.o diff --git a/out/world.o b/out/world.o Binary files differnew file mode 100644 index 0000000..6f79983 --- /dev/null +++ b/out/world.o diff --git a/src/common.cpp b/src/common.cpp index 373c08c..1152be7 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -4,7 +4,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 49fce0f..13c042b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -42,7 +42,33 @@ 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; + } + }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 +137,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 +156,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 +182,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 @@ -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; |