]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Working on animations
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 30 Nov 2015 13:47:24 +0000 (08:47 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 30 Nov 2015 13:47:24 +0000 (08:47 -0500)
config/items.h
include/common.h
include/inventory.h
src/Texture.cpp
src/entities.cpp
src/inventory.cpp

index 62db07172336b144e1668ade7ba0bd0c6c801630..fc0ca96a7fe7f59650a78869265badce632c8ea0 100644 (file)
@@ -1,6 +1,6 @@
 
 ID DEBUG_ITEM
-       NAME "Debug\0"
+       NAME "Debug"
        TYPE TOOL 
        WIDTH 1 
        HEIGHT 1 
@@ -9,7 +9,7 @@ ID DEBUG_ITEM
        ENI
 
 ID TEST_ITEM   
-       NAME "Dank MayMay\0
+       NAME "Dank MayMay" 
        TYPE TOOL 
        WIDTH HLINE 
        HEIGHT HLINE 
@@ -18,7 +18,7 @@ ID TEST_ITEM
        ENI
 
 ID PLAYER_BAG  
-       NAME "Your Bag\0
+       NAME "Your Bag" 
        TYPE EQUIP 
        WIDTH HLINE*5 
        HEIGHT HLINE*5 
@@ -27,7 +27,7 @@ ID PLAYER_BAG
        ENI
 
 ID FLASHLIGHT  
-       NAME "Flashlight\0
+       NAME "Flashlight" 
        TYPE TOOL 
        WIDTH HLINE*2 
        HEIGHT HLINE*4 
@@ -36,7 +36,7 @@ ID FLASHLIGHT
        ENI
 
 ID SWORD_WOOD  
-       NAME "Wood Sword\0
+       NAME "Wood Sword" 
        TYPE SWORD 
        WIDTH HLINE*4 
        HEIGHT HLINE*10 
index 525a4cd420a006a977175700ba173bb8ba5bcf8f..869c81162a5734c7527933daea42249fb0845d1f 100644 (file)
@@ -123,6 +123,8 @@ extern float handAngle;
  * 
 */
 
+ extern unsigned int loops;
+
 //GLuint loadTexture(const char *fileName);
 
 /*
index 2793ad7dcf9d265e6accd94de352a7c23c619469..3b4c260d8d1ef22f0a4f74f5ad89129df3ef8d42 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <common.h>
 #include <string.h>
+#include <boost/range/adaptor/reversed.hpp>
 
 #define DEBUG
 
@@ -49,24 +50,30 @@ public:
        int maxStackSize;
        char* textureLoc;
        Texturec *tex;
+       GLuint text;
        int count;
        Item(ITEM_ID i, char* n, ITEM_TYPE t, float w, float h, int m, char* tl):
                id(i), type(t), width(w), height(h), maxStackSize(m){
                count = 0;
 
-               name            = (char*)calloc(strlen(n ),sizeof(char));
-               textureLoc      = (char*)calloc(strlen(tl),sizeof(char));
+               name            = (char*)calloc(strlen(n )+1,sizeof(char));
+               textureLoc      = (char*)calloc(strlen(tl)+1,sizeof(char));
 
                strcpy(name,n);
                strcpy(textureLoc,tl);
 
                tex= new Texturec(1,textureLoc);
+               text = Texture::loadTexture(textureLoc);
        }
        GLuint rtex(){
                return tex->image[0];
        }
 };
 
+static Item item[5]= {
+       #include "../config/items.h"
+};
+
 struct item_t{
        int count;
        ITEM_ID id;
index 82baa71767b77a8e4dba9d655a9b1fd7713efddb..586f5fd7469dff42b140e0666655a54cf6aa21fe 100644 (file)
@@ -13,7 +13,6 @@ namespace Texture{
        GLuint loadTexture(const char *fileName){
                SDL_Surface *image;
                GLuint object = 0;
-               unsigned int i;
 
                for(unsigned int i=0;i<LoadedTextureCounter;i++){
                        if(!strcmp(LoadedTexture[i]->name,fileName)){
index 97b4d352c95ea10ebbc079e7887b498d0407ae52..c2c560aecb4c2a4a14023ed3a3c293555e4521ed 100644 (file)
@@ -108,7 +108,7 @@ Object::Object(int id):identifier(id){
        height = HLINE * 8;
 
        maxHealth = health = 1;
-       //tex = new Texturec(1, item[id].textureLoc);
+       tex = new Texturec(1, item[id].textureLoc);
 
        questObject = false;
        pickupDialog="\0";
@@ -122,7 +122,7 @@ Object::Object(int id, bool qo, char *pd):identifier(id),questObject(qo),pickupD
        height = HLINE * 8;
 
        maxHealth = health = 1;
-       //tex = new Texturec(1, item[id].textureLoc);   
+       tex = new Texturec(1, item[id].textureLoc);     
 }
 
 
index 45d5bcee309fbb51db60b7ab7bd740a5703abe5d..ed22fb698159f94c2b317a7a26b52710be719add 100644 (file)
@@ -7,10 +7,6 @@
 extern Player *player;
 extern GLuint invUI;
 
-static Item item[5]= {
-       #include "../config/items.h"
-};
-
 void itemDraw(Player *p,ITEM_ID id);
 
 Inventory::Inventory(unsigned int s){
@@ -63,6 +59,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
 void Inventory::draw(void){
        ui::putText(offset.x-SCREEN_WIDTH/2,480,"%d",sel);
        unsigned int i=0;
+       static unsigned int lop = 0;
        float y,xoff;
 
 
@@ -81,7 +78,7 @@ void Inventory::draw(void){
                //dfp[a] = 0;
                a++;
        }a=0;
-       if(invOpening){
+       if(invOpening && lop % 1 == 0){
                end = 0;
                for(auto &d : dfp){
                        if(a != 0){
@@ -94,18 +91,12 @@ void Inventory::draw(void){
                        a++;
                }a=0;
                if(end < numSlot)invOpen=true;
-       }else if(!invOpening){
-               for(auto &d : dfp){
+       }else if(!invOpening && lop % 1 == 0){
+               for(auto &d : boost::adaptors::reverse(dfp)){
                        if(d > 0){
-                               if(a != 0){
-                                       //d-=25;
-                                       if(dfp[a-1]+25<d || dfp[a-1]<=0)d-=25;
-                               }else{
-                                       d-=25;
-                               }
+                               d-=25;
                        }else end++;
-                       a++;
-               }a=0;
+               }
                if(end >= numSlot)invOpen=false;
        }
        if(invOpen){
@@ -115,14 +106,24 @@ void Inventory::draw(void){
                        curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
                        r.end = curCoord[a];
 
-                       item[inv[i].id].tex->bind(0);                   
-                       glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+                       glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range));
                        glBegin(GL_QUADS);
-                               glTexCoord2i(0,1);glVertex2i(r.end.x,           r.end.y);
-                               glTexCoord2i(1,1);glVertex2i(r.end.x+45,        r.end.y);
-                               glTexCoord2i(1,0);glVertex2i(r.end.x+45,        r.end.y+45);
-                               glTexCoord2i(0,0);glVertex2i(r.end.x,           r.end.y+45);
+                               glVertex2i(r.end.x,             r.end.y);
+                               glVertex2i(r.end.x+45,  r.end.y);
+                               glVertex2i(r.end.x+45,  r.end.y+45);
+                               glVertex2i(r.end.x,             r.end.y+45);
                        glEnd();
+
+                       if(inv[a].count > 0){
+                               glBindTexture(GL_TEXTURE_2D, item[inv[a].id].text);                     
+                               glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+                               glBegin(GL_QUADS);
+                                       glTexCoord2i(0,1);glVertex2i(r.end.x,           r.end.y);
+                                       glTexCoord2i(1,1);glVertex2i(r.end.x+45,        r.end.y);
+                                       glTexCoord2i(1,0);glVertex2i(r.end.x+45,        r.end.y+45);
+                                       glTexCoord2i(0,0);glVertex2i(r.end.x,           r.end.y+45);
+                               glEnd();
+                       }
                        a++;
                }
        }
@@ -159,6 +160,7 @@ void Inventory::draw(void){
                }
        }*/
        if(inv[sel].count)itemDraw(player,inv[sel].id);
+       lop++;
 }
 
 static vec2 item_coord = {0,0};