]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world bg improvements
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 2 Dec 2015 13:48:39 +0000 (08:48 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 2 Dec 2015 13:48:39 +0000 (08:48 -0500)
Changelog
assets/bgWoodTile.png [new file with mode: 0644]
include/Texture.h
include/entities.h
include/world.h
src/Texture.cpp
src/entities.cpp
src/gameplay.cpp
src/world.cpp
xcf/bgWoodTile.xcf [new file with mode: 0644]

index f1e88418047c89b3106102b1669342d4213e8f19..a2727957fa90f90b6696019265bf5c4875f8c0a0 100644 (file)
--- a/Changelog
+++ b/Changelog
        - ran game through valgrind, fixed almost all memory leaks/errors
        - smoothed out game animations
        - broke the game
+
+12/2/2015:
+==========
+
+       - fixed many item related segfaults :)
+       - removed std::thread calls
+       - improved world background drawing; added that to IndoorWorld's
+       - improved inventory functionality
+       - fixed issues with cutscenes
diff --git a/assets/bgWoodTile.png b/assets/bgWoodTile.png
new file mode 100644 (file)
index 0000000..0c7c64b
Binary files /dev/null and b/assets/bgWoodTile.png differ
index 1a32aae9d714740938529abac0ffecf799a98271..5f5758b69ff6c7066e03948da2cb5c11ff9f6a20 100644 (file)
@@ -16,6 +16,7 @@ public:
        GLuint *image;
        
        Texturec(uint amt, ...);
+       Texturec(uint amt,const char **paths);
        ~Texturec();
        
        void bindNext();
index 4413d4116d75bbfa5fc310395273c0a80ff714b2..19dd492542ae42918f0de0c4b6c0de9f5cf2322f 100644 (file)
@@ -125,7 +125,7 @@ public:
 class Mob : public Entity{
 public:
        double init_y;
-       void (*hey)();
+       void (*hey)(Mob *callee);
        
        Mob(int);
        Mob(int,unsigned int);
index 6c0395d056c8eb06e5e2e5184673bef24d4bf7e6..57ea091d1454a7510b45cdf0f94dfa8b4b9f6db9 100644 (file)
@@ -12,7 +12,8 @@
 #define DAY_CYCLE 3000
 
 typedef enum {
-       BG_FOREST
+       BG_FOREST,
+       BG_WOODHOUSE
 } WORLD_BG_TYPE;
 
 typedef enum {
@@ -106,7 +107,7 @@ public:
        
        void addStructure(_TYPE t,float x,float y,World *outside,World *inside);
        void addMob(int t,float x,float y);
-       void addMob(int t,float x,float y,void (*hey)());
+       void addMob(int t,float x,float y,void (*hey)(Mob *));
        void addNPC(float x,float y);
        void addObject(ITEM_ID, bool, const char *, float, float);
        
index a3a8afe755a97b753b692f6d72eadafa5f19765a..a44f1a7cb2a662a60a5c67ae9847642774ea9999 100644 (file)
@@ -23,6 +23,9 @@ namespace Texture{
                        }
                }
 
+               if(!fileName)
+                       return 0;
+
                if(!(image = IMG_Load(fileName)))
                        return 0;
 #ifdef DEBUG
@@ -73,6 +76,14 @@ Texturec::Texturec(uint amt, ...){
        va_end(fNames);
 }
 
+Texturec::Texturec(uint amt,const char **paths){
+       texState = 0;
+       image = new GLuint[amt];
+       for(int i = 0; i < amt; i++){
+               image[i] = Texture::loadTexture(paths[i]);
+       }
+}
+
 Texturec::~Texturec(){
        delete[] image;
 }
index 32867841bcae6f45cbbb7d658a7ac8297c9efb2e..9c5e3cb3b859cc4e9c5408aa69bedc537b37678f 100644 (file)
@@ -280,10 +280,6 @@ void Player::interact(){ //the function that will cause the player to search for
  *     NPC::wander, this makes the npcs wander around the near area
  *
  *     timeRun                                 This variable is the amount of gameloop ticks the entity will wander for
- *
- *     *v                                              This is a pointer to whatever vec2 value is passed to it, usually the value
- *                                                     passed is the entities vec2 for coordinates. Since the value is a pointer
- *                                                     the memory address passed to it is directly modified.
 */
 
 void NPC::wander(int timeRun){
@@ -339,7 +335,7 @@ void NPC::interact(){ //have the npc's interact back to the player
        }
 }
 
-void Object::interact(void){   
+void Object::interact(void){
        if(questObject && alive){
                ui::dialogBox("You",":Yes:No",pickupDialog);            
                ui::waitForDialog();
@@ -435,7 +431,7 @@ void Mob::wander(int timeRun){
                   player->loc.x + player->width / 2 < loc.x + width ){
                        if(player->left)player->loc.x = loc.x + width;
                        else if(player->right) player->loc.x = loc.x - player->width;
-                       hey();
+                       hey(this);
                }
                break;
        default:
index 64b3908404cb56cfd641dc7dd26df637354a1792..711fc1dc7d6aacc5fc565e092f2a1ce90bf37734 100644 (file)
@@ -34,7 +34,7 @@ int giveTestQuest(NPC *speaker){
 
 static Arena *a;
 
-void CUTSCENEEE(void){
+void CUTSCENEEE(Mob *callee){
        player->vel.x = 0;
        
        ui::dialogBox(player->name,":K.","No way I\'m gettin\' up this hill.");
@@ -48,6 +48,15 @@ void CUTSCENEEE(void){
        player->loc.x += HLINE * 5;*/
 }
 
+void CUTSCENEEE2(Mob *callee){
+       player->vel.x = 0;
+       ui::dialogBox(player->name,":Yeah.",
+       "What the fuck is this dead end supposed \
+       to mean, and why this place smells like soap.");
+       ui::waitForDialog();
+       callee->alive = false;
+}
+
 float playerSpawnHillFunc(float x){
        return (float)(pow(2,(-x+200)/5) + 80);
 }
@@ -99,7 +108,9 @@ void initEverything(void){
        */
        
        iw=new IndoorWorld();
+       iw->setBackground(BG_WOODHOUSE);
        iw->generate(200);
+       iw->addMob(MS_TRIGGER,0,0,CUTSCENEEE2);
        
        /*
         *      Spawn some entities.
index c078726cc62eec064ee71f8781af3801766b9224..d81d8de696ca39cf1a570675763ce48f2e011027 100644 (file)
@@ -18,13 +18,19 @@ bool worldInside = false;           // True if player is inside a structure
 
 WEATHER weather = SUNNY;
 
-const char *bgPaths[6]={
-       "assets/bg.png",                                // Daytime background
+const char *bgPaths[2][6]={
+       {"assets/bg.png",                               // Daytime background
        "assets/bgn.png",                               // Nighttime background
        "assets/bgFarMountain.png",             // Furthest layer
        "assets/forestTileBack.png",    // Closer layer
        "assets/forestTileMid.png",             // Near layer
-       "assets/forestTileFront.png"    // Closest layer
+       "assets/forestTileFront.png"},  // Closest layer
+       {"assets/bgWoodTile.png",
+        NULL,
+        NULL,
+        NULL,
+        NULL,
+        NULL}
 };
 
 const float bgDraw[3][3]={
@@ -45,14 +51,11 @@ float worldGetYBase(World *w){
 
 void World::setBackground(WORLD_BG_TYPE bgt){
        switch(bgt){
-       default:
-               bgTex = new Texturec(6,bgPaths[0],
-                                                          bgPaths[1],
-                                                          bgPaths[2],
-                                                          bgPaths[3],
-                                                          bgPaths[4],
-                                                          bgPaths[5]
-                                                          );
+       case BG_FOREST:
+               bgTex = new Texturec(6,bgPaths[0]);
+               break;
+       case BG_WOODHOUSE:
+               bgTex = new Texturec(1,bgPaths[1]);
                break;
        }
 }
@@ -768,7 +771,7 @@ void World::addMob(int t,float x,float y){
        entity.push_back(mob.back());
 }
 
-void World::addMob(int t,float x,float y,void (*hey)()){
+void World::addMob(int t,float x,float y,void (*hey)(Mob *)){
        mob.push_back(new Mob(t));
        mob.back()->spawn(x,y);
        mob.back()->hey = hey;
@@ -910,13 +913,27 @@ void IndoorWorld::generate(unsigned int width){           // Generates a flat area of wid
 void IndoorWorld::draw(Player *p){
        int i,ie,v_offset;
        
+       glEnable(GL_TEXTURE_2D);
+       bgTex->bind(0);
+       glColor4ub(255,255,255,255);
+       glBegin(GL_QUADS);
+               for(i = x_start - SCREEN_WIDTH / 2;i < -x_start + SCREEN_WIDTH / 2; i += 1024){
+                       glTexCoord2i(1,1);glVertex2i(i     ,0);
+                       glTexCoord2i(0,1);glVertex2i(i+1024,0);
+                       glTexCoord2i(0,0);glVertex2i(i+1024,1024);
+                       glTexCoord2i(1,0);glVertex2i(i     ,1024);
+               }
+       glEnd();
+       glDisable(GL_TEXTURE_2D);
+       
        v_offset=(p->loc.x-x_start)/HLINE;                                      // Calculate the player's offset in the array 'line' using the player's location 'vec'
        i=v_offset-SCREEN_WIDTH/2;                                                      // um
        if(i<0)i=0;                                                                                     // If the player is past the start of that world 'i' should start at the beginning
                                                                                                                // of the world
        ie=v_offset+SCREEN_WIDTH/2;                                                     // Set how many lines should be drawn (the drawing for loop loops from 'i' to 'ie')
        if(ie>lineCount)ie=lineCount;                                           // If the player is past the end of that world 'ie' should contain the end of that world
-       glClearColor(.3,.1,0,0);
+       //glClearColor(.3,.1,0,0);
+       
        glBegin(GL_QUADS);
                for(i=i;i<ie-GEN_INC;i++){                                              // For lines in array 'line' from 'i' to 'ie'
                        safeSetColor(150,100,50);
diff --git a/xcf/bgWoodTile.xcf b/xcf/bgWoodTile.xcf
new file mode 100644 (file)
index 0000000..9aa0005
Binary files /dev/null and b/xcf/bgWoodTile.xcf differ