diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-10-13 08:50:54 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-10-13 08:50:54 -0400 |
commit | 3d375c17982f9f459c82364117687d145540fe75 (patch) | |
tree | 47638e15f9d3f26f8a43c89c4566d4794b08ba4d | |
parent | 8f2f66a7b90f97911bbffce3ccc8c7ad01ba61ad (diff) |
Added rabbit, and player health
-rw-r--r-- | assets/cloud1.png | bin | 0 -> 1152 bytes | |||
-rw-r--r-- | assets/rabbit.png | bin | 0 -> 296 bytes | |||
-rw-r--r-- | assets/rabbit1.png | bin | 0 -> 341 bytes | |||
-rw-r--r-- | assets/skirl.png | bin | 0 -> 436 bytes | |||
-rw-r--r-- | include/entities.h | 5 | ||||
-rw-r--r-- | main.cpp | 3 | ||||
-rw-r--r-- | src/entities.cpp | 27 | ||||
-rw-r--r-- | src/ui.cpp | 1 |
8 files changed, 30 insertions, 6 deletions
diff --git a/assets/cloud1.png b/assets/cloud1.png Binary files differnew file mode 100644 index 0000000..0a683e6 --- /dev/null +++ b/assets/cloud1.png diff --git a/assets/rabbit.png b/assets/rabbit.png Binary files differnew file mode 100644 index 0000000..6f35e9d --- /dev/null +++ b/assets/rabbit.png diff --git a/assets/rabbit1.png b/assets/rabbit1.png Binary files differnew file mode 100644 index 0000000..6f32c96 --- /dev/null +++ b/assets/rabbit1.png diff --git a/assets/skirl.png b/assets/skirl.png Binary files differnew file mode 100644 index 0000000..263607b --- /dev/null +++ b/assets/skirl.png diff --git a/include/entities.h b/include/entities.h index ecfe539..2a9a62b 100644 --- a/include/entities.h +++ b/include/entities.h @@ -20,6 +20,9 @@ public: float width; //width and height of the player float height; float speed; //speed of the play + + int health; + int maxHealth; int subtype; _TYPE type; @@ -94,5 +97,5 @@ ENTITY TYPES |->1 Merchant | 2 MOBS -|->1 Skirl +|->1 Rabbit **/
\ No newline at end of file @@ -134,7 +134,7 @@ static float debugY=0; void mainLoop(void){ static unsigned int debugDiv=0; - unsigned int i, + static unsigned int i, prevTime = 0, currentTime = 0; @@ -201,7 +201,6 @@ void render(){ player->near=true; // Ensure the player's name is always drawn currentWorld->draw(player); // Draw the world & the player - glColor3ub(255,255,255); // Draw the player's inventory player->inv->draw(); // ui::draw(); // Draw any UI elements if they need to be diff --git a/src/entities.cpp b/src/entities.cpp index a7bbff5..0457ba1 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -25,7 +25,9 @@ Player::Player(){ //sets all of the player specific traits on object creation height = HLINE * 16; speed = 1; type = PLAYERT; //set type to player - subtype = 5; + subtype = 0; + maxHealth = 100; + health = maxHealth; alive = true; ground = false; near = true; @@ -69,8 +71,8 @@ Mob::Mob(){ alive = true; canMove = true; near = false; - texture[0] = loadTexture("assets/NPC.png"); - texture[1] = 0; + texture[0] = loadTexture("assets/rabbit.png"); + texture[1] = loadTexture("assets/rabbit1.png"); texture[2] = 0; inv = new Inventory(NPC_INV_SIZE); } @@ -125,9 +127,22 @@ void Entity::draw(void){ //draws the entities }else{ glBindTexture(GL_TEXTURE_2D,texture[0]); } + }else if(type == MOBT){ + switch(subtype){ + case 1: //RABBIT + if(ground == 0){ + glBindTexture(GL_TEXTURE_2D, texture[1]); + }else if(ground == 1){ + glBindTexture(GL_TEXTURE_2D, texture[0]); + } + break; + default: + break; + } }else{ glBindTexture(GL_TEXTURE_2D,texture[0]); } + glColor3ub(255,255,255); glBegin(GL_QUADS); glTexCoord2i(0,1);glVertex2i(loc.x, loc.y); glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y); @@ -137,6 +152,12 @@ void Entity::draw(void){ //draws the entities glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glPopMatrix(); + if(type == PLAYERT){ + ui::setFontSize(16); + ui::putText(((SCREEN_WIDTH / 2 ) + loc.x) - 125, SCREEN_HEIGHT - ui::fontSize, "Health: %d/%d",health,maxHealth); + glColor3ub(255,0,0); + glRectf((SCREEN_WIDTH / 2 + loc.x) - 125, SCREEN_HEIGHT - 32, ((SCREEN_WIDTH / 2 + loc.x) - 125) + (int)((int)(health / maxHealth) * 100), SCREEN_HEIGHT - 32 + 12); + } if(near){ ui::setFontSize(14); ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name); @@ -236,6 +236,7 @@ namespace ui { if(!left&&!right)player->vel.x=0; if(SDL_KEY==SDLK_LSHIFT)player->speed = 1; if(SDL_KEY==SDLK_LCTRL)player->speed = 1; + if(SDL_KEY==SDLK_h)player->health-=5; break; default: break; |