From 3d375c17982f9f459c82364117687d145540fe75 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Tue, 13 Oct 2015 08:50:54 -0400 Subject: [PATCH] Added rabbit, and player health --- assets/cloud1.png | Bin 0 -> 1152 bytes assets/rabbit.png | Bin 0 -> 296 bytes assets/rabbit1.png | Bin 0 -> 341 bytes assets/skirl.png | Bin 0 -> 436 bytes include/entities.h | 5 ++++- main.cpp | 3 +-- src/entities.cpp | 27 ++++++++++++++++++++++++--- src/ui.cpp | 1 + 8 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 assets/cloud1.png create mode 100644 assets/rabbit.png create mode 100644 assets/rabbit1.png create mode 100644 assets/skirl.png diff --git a/assets/cloud1.png b/assets/cloud1.png new file mode 100644 index 0000000000000000000000000000000000000000..0a683e65730e66f7eeefd739dc5de25fde3d8211 GIT binary patch literal 1152 zcmeAS@N?(olHy`uVBq!ia0vp^CxEzugAGV-pS1TikYY>nc6R~NK=9LfcRi5eEbxdd zW?MX8A; zsVNHOnI#zt?w-B@DSD~w3=GUqJY5_^DsH{Kd%JIq1&_l;&z1lFPoKGb+AD>3Ek_Kq z_iqc~Jz~AhxxvWyay`SepF3C>92uGzSQt5&1XvU}90VE^fC5NNgdC=_CI*;}2DzHp zridv)dbOXjXDxg5%GN;6?x2|c4^C$Rr$5qn(*N@Za!hjW6T4pRE3rvHWsZ#Pdi_8l zE~Bcsa;|;0k>}?8zBVIe`dSw0Bk$OYOAkChE@x^iFZ%RUM9LJ^76sd;?A06h8lUb9 z*p%m4w5&X8SKCb$&Qkd$sRgoW2DFd?BZcFI;&xhhsN))0~u9 z1{_S0EeaD{IhaC@D{q%rB=UM|ijM%##eSK);_d=VM3dL%N8S>@?ltLN^~O8SC$wF+ zKHK}eH?n%;haD28$G?C79-T5VZ*|1H?mG6Z>iZ+jDr?esFE(pzoyWHse@*~X^C?eLm#s9rG-wBD=H76KN#9Cx_NSkM}DzfWM344D+ z;fcdGolljwdl({@bSs$2I!)HA2Bro`!U)q?T2V7o!9t14iYuv89GG5;c;DabJvp&D z=$D8j%P)bZ1p98CnvS*uYgrA0d&9F_Z^?r~w|5@dWyQhv?xxPA z&%tSn`+hI~q%cJ)KWn?Ph2PJsL46&o7xwS{_WVWnqcm}kBir~-2^<&t8g?*wb;M`k zxG2ZKpuM~INGAT7UGuaoU%Ts!pt6DV(L?W2epxwQQ&DvLKdV0b(<)QD=$T5t^m>-v z_xvx-lXPVD&+KlaO(OeiTF)eX*z@kr_Lh|wwR?8O_bX^GN}2M+XTg8gFLT``jdGGy zJ&r~eExGsD*RhU$wrKd16G~@lEblJnWZ9|eK8+!2*LjydN3S&)KB(za^>(K|C`Y^>~V=OaAhT-M8(^ z&DS$LKQcK+c?Tu)Uzk|URDNFZSNcRwA%`i;o8S5se63=aP>j>@Sbd<{>O|IDW=RgE m8x8^qB{`<3S+j{D@~8YRpQ1mvZNJrm3Ib18KbLh*2~7aPHQr$W literal 0 HcmV?d00001 diff --git a/assets/rabbit.png b/assets/rabbit.png new file mode 100644 index 0000000000000000000000000000000000000000..6f35e9d9a55fd2a674de1c72929cc7fb31449ecd GIT binary patch literal 296 zcmeAS@N?(olHy`uVBq!ia0vp^azHG>!3HGXX8P_2Qfx`y?k)^042K!!3QoBd4;0}n z@Q5sCVBi)8VMc~ob0mO*>?NMQuI%@@c)2aDRrdHt0)=EVLn2C?^K)}k^GbkR1_tM% z)Wnk16ovB4k_-iRPv3wPy;OFfc#o%xV~EG`r_(NS9Z=wKEnV~f|H{AD-!5dkof>J- z-mCXTp{2~oRM39mx@onS)f|J=gBZEyWEGw?JIUVrpeHe1&gF=F= zW})rlsPhZwa?e|Gw_)q#qr%nCXK+^9wd~8<`f7&1O_lQ6l_pnhx5?5bR& kU$r&Le$u^t29Lf@VGKQ{|Do96Pd&)Np00i_>zopr0MJ!wHUIzs literal 0 HcmV?d00001 diff --git a/assets/rabbit1.png b/assets/rabbit1.png new file mode 100644 index 0000000000000000000000000000000000000000..6f32c962bc55f5f1d06f76848a7b2455a1398c7e GIT binary patch literal 341 zcmeAS@N?(olHy`uVBq!ia0vp^azHG>!3HGXX8P_2Qfx`y?k)`fL2$v|<&%LToCO|{ z#S9GG!XV7ZFl&wkP>{XE)7O>#J{K`Ki;O^-gkfN8$4iw+%>EamTas25tM?NM+9@qG(krk}x7cKu7Q#|XV-n;|7 z#-4W@40$c2ycK?#x3Ere|E(#sOpssq_++M*%qe&7WH~Fd>Ia3gI=E~q_P*Ei<3AJo zd*0x@-|Bu>BfB?9Cox`WKJdzhhe76<<|gW!U_%O?XxI14-? ziy0WWg+Z8+Vb&Z8pdfpRr>`sfeJ&1O2@!*Zuakj7vY8S|xv6<2KrRD=b5Uwy zNotBhd1gt5g1e`0K#E=}I|Bowgr|#RNW|f*;f_Mh3Op)&^)I)|zo>Yf|4XX=a`bWj zFR!vMIk)qrb!-sSeX>j=W%3&}0ps2C&SrDFOmR7O=86!*B*_lh`a627w`RsIID4L9 zH3z|;v!)+*e!81;0qgU#DsBSHD<&}YeR2(Rs5m!u!FHGUJSllO z8GG-w9WxjHy51p~E?8(+zU|DCJGa}Xdq{4*BA>t)vG2Z-?x*vwf5e8L<6~^L+z`Gp zpeWrqz<8D^b3y(7Q@P!=d#Wzp$P!>`Kf>a literal 0 HcmV?d00001 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 diff --git a/main.cpp b/main.cpp index 386d419..afcaa57 100644 --- 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 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); diff --git a/src/ui.cpp b/src/ui.cpp index 25b792b..fe5414c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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; -- 2.39.5