]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixed mouse
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 8 Oct 2015 13:29:22 +0000 (09:29 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 8 Oct 2015 13:29:22 +0000 (09:29 -0400)
Changelog
include/common.h
include/inventory.h
main.cpp
src/inventory.cpp
src/world.cpp

index a55b87200d5ee3b0792d225c9f6fbccf924b04e0..fa6608c0a80c2b9a291b849f0fedf9277d1ca9a7 100644 (file)
--- a/Changelog
+++ b/Changelog
        - added running textures to player
        - added crouching
        - improved world draw, world now draws player as well
+
+10/9/2015:
+==========
+
+       - improved player inventory
+       - improved quests
+       - added mobs
+       - added DEBUG flags and functions to inventory.cpp and ui.cpp
index b7c13e7b78f5502a0bbfac2161d1685d873118da..b57999dab17f325898a887c98bd2fda616a4e3ed 100644 (file)
@@ -30,8 +30,8 @@ enum GENDER{
 #include <Quest.h>
 #include <entities.h>
 
-#define SCREEN_WIDTH  1280
-#define SCREEN_HEIGHT 740
+#define SCREEN_WIDTH  640
+#define SCREEN_HEIGHT 480
 //#define FULLSCREEN
 
 #define HLINE 3                                                                //base unit of the world
index d68fed940d27cbbb73ec1e843af706f08ed1f500..c477b8eb92ad1d7ace7792ee25daa5b9cc7770ec 100644 (file)
@@ -7,7 +7,7 @@
 
 enum ITEM_ID {         // Contains item IDs for every item in the game, this is how items are stored. IDs are also used to lookup item strings
        TEST_ITEM = 1,  // A test item (duh)
-       SWORD_ITEM      
+       SWORD_ITEM      = 2
 };
 
 struct item_t {                                // Used to define entries in an entity's inventory
@@ -17,6 +17,7 @@ struct item_t {                               // Used to define entries in an entity's inventory
 
 class Inventory {
 private:
+       unsigned int sel;
        unsigned int size;              // Size of 'item' array
        struct item_t *item;    // An array of the items contained in this inventory.
 public:
@@ -26,6 +27,8 @@ public:
        int addItem(ITEM_ID id,unsigned char count);    // Add 'count' items with an id of 'id' to the inventory
        int takeItem(ITEM_ID id,unsigned char count);   // Take 'count' items with an id of 'id' from the inventory
        
+       void setSelection(unsigned int s);
+       
        void draw(void);        // Draws a text list of items in this inventory (should only be called for the player for now)
 };
 
index b8f82f09ddbf55197913533263e0d78ef47589c9..a220e2c401a522d62899ac76aa439024137342d1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -218,7 +218,7 @@ void render(){
        **************************/
        mx = ui::mouse.x + player->loc.x;
        my = ui::mouse.y;
-       my = 720 - my;
+       my = SCREEN_HEIGHT - my;
        mx -= (SCREEN_WIDTH/2);
        glColor3ub(255,255,255);
        glBegin(GL_TRIANGLES);
@@ -243,7 +243,7 @@ void logic(){
                                                entity[i]->near=true;
                                                if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)){
                                                        entity[i]->interact();
-                                                       std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
+                                                       //std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
                                                        //Mix_PlayChannel( -1, horn, 0);
                                                }
                                        }else entity[i]->near=false;
index 3882fb099429649db04ed3396ef5bf3fe6a5112c..83c40f6bfc74e39311155a82c9e01f280e28d9f7 100644 (file)
@@ -30,6 +30,7 @@ unsigned int initInventorySprites(void){
 }
 
 Inventory::Inventory(unsigned int s){
+       sel=0;
        size=s;
        item=(struct item_t *)calloc(size,sizeof(struct item_t));
 }
@@ -37,19 +38,32 @@ Inventory::Inventory(unsigned int s){
 Inventory::~Inventory(void){
        free(item);
 }
-       
+
+void Inventory::setSelection(unsigned int s){
+       sel=s;
+}
+
 int Inventory::addItem(ITEM_ID id,unsigned char count){
        unsigned int i;
        for(i=0;i<size;i++){
                if(item[i].id==id){
                        item[i].count+=count;
+#ifdef DEBUG
+                       DEBUG_printf("Gave player %u more %s(s).\n",count,itemName[i]);
+#endif // DEBUG
                        return 0;
                }else if(!item[i].count){
                        item[i].id=id;
                        item[i].count=count;
+#ifdef DEBUG
+                       DEBUG_printf("Gave player %u %s(s).\n",count,itemName[i]);
+#endif // DEBUG
                        return 0;
                }
        }
+#ifdef DEBUG
+       DEBUG_printf("Failed to add non-existant item with id %u.\n",id);
+#endif // DEBUG
        return -1;
 }
 
@@ -78,6 +92,8 @@ void Inventory::draw(void){
                xoff=ui::putText(player->loc.x-SCREEN_WIDTH/2,y,"%d x ",item[i].count);
                glEnable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id-1]);
+               if(sel==i)glColor3ub(255,0,255);
+               else      glColor3ub(255,255,255);
                glBegin(GL_QUADS);
                        glTexCoord2i(0,1);glVertex2i(xoff                 ,y);
                        glTexCoord2i(1,1);glVertex2i(xoff+HLINE*10,y);
index 72287be0b931553a57c367f43ebd225e4412b453..14980161b6a63f0fb9261023a392b96f6e44820e 100644 (file)
@@ -163,7 +163,7 @@ void World::singleDetect(Entity *e){
                        e->ground=true;
                        e->loc.y=line[i].y-.001*deltaTime;      
                        if(e->type==STRUCTURET){
-                               std::cout<<e->loc.x<<" "<<e->loc.y<<std::endl;
+                               //std::cout<<e->loc.x<<" "<<e->loc.y<<std::endl;
                                return;
                        }
                }else if(e->loc.y>line[i].y-.002*deltaTime){    // Snap the player to the top of that line if the player is inside it