]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added rabbit, and player health
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 13 Oct 2015 12:50:54 +0000 (08:50 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 13 Oct 2015 12:50:54 +0000 (08:50 -0400)
assets/cloud1.png [new file with mode: 0644]
assets/rabbit.png [new file with mode: 0644]
assets/rabbit1.png [new file with mode: 0644]
assets/skirl.png [new file with mode: 0644]
include/entities.h
main.cpp
src/entities.cpp
src/ui.cpp

diff --git a/assets/cloud1.png b/assets/cloud1.png
new file mode 100644 (file)
index 0000000..0a683e6
Binary files /dev/null and b/assets/cloud1.png differ
diff --git a/assets/rabbit.png b/assets/rabbit.png
new file mode 100644 (file)
index 0000000..6f35e9d
Binary files /dev/null and b/assets/rabbit.png differ
diff --git a/assets/rabbit1.png b/assets/rabbit1.png
new file mode 100644 (file)
index 0000000..6f32c96
Binary files /dev/null and b/assets/rabbit1.png differ
diff --git a/assets/skirl.png b/assets/skirl.png
new file mode 100644 (file)
index 0000000..263607b
Binary files /dev/null and b/assets/skirl.png differ
index ecfe539285e0993287f43e239188badf0be7a463..2a9a62b89767062347db363351d69b5e2ccbc88b 100644 (file)
@@ -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
index 386d4191735d531381ee83b683b3a984d2190fd4..afcaa5775fe71fd2cadc50cb467d8c1dc2c26ed7 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -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
index a7bbff5694a31787c0584cbddf4799c8dd3a3123..0457ba17f09bc66f988de680edcb46f2a3b5816e 100644 (file)
@@ -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);
index 25b792b6a47d2e3fa5edd25c31ce34b2a2a36770..fe5414cdb14ba26e65ca2b574c0b0835f6a2cd5d 100644 (file)
@@ -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;