diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-03 07:46:23 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-03 07:46:23 -0500 |
commit | bf91141782766f3648b62c6d96528fddb9ae7447 (patch) | |
tree | c6c9322ec7c4f111f05c7f639ab1d33bed9de40f | |
parent | dc24164926a7988e018d32fff1977d2b40c89057 (diff) | |
parent | 6b44ecd9da08087f4a44dd3daef211e763eb1c61 (diff) |
Added holding vs press key action
-rw-r--r-- | Changelog | 9 | ||||
-rw-r--r-- | assets/bgWoodTile.png | bin | 0 -> 65078 bytes | |||
-rw-r--r-- | include/Texture.h | 1 | ||||
-rw-r--r-- | include/entities.h | 2 | ||||
-rw-r--r-- | include/world.h | 5 | ||||
-rw-r--r-- | src/Texture.cpp | 11 | ||||
-rw-r--r-- | src/entities.cpp | 12 | ||||
-rw-r--r-- | src/gameplay.cpp | 13 | ||||
-rw-r--r-- | src/ui.cpp | 16 | ||||
-rw-r--r-- | src/world.cpp | 49 | ||||
-rw-r--r-- | xcf/bgWoodTile.xcf | bin | 0 -> 511093 bytes |
11 files changed, 87 insertions, 31 deletions
@@ -355,3 +355,12 @@ - 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 Binary files differnew file mode 100644 index 0000000..0c7c64b --- /dev/null +++ b/assets/bgWoodTile.png diff --git a/include/Texture.h b/include/Texture.h index 1a32aae..5f5758b 100644 --- a/include/Texture.h +++ b/include/Texture.h @@ -16,6 +16,7 @@ public: GLuint *image; Texturec(uint amt, ...); + Texturec(uint amt,const char **paths); ~Texturec(); void bindNext(); diff --git a/include/entities.h b/include/entities.h index 4413d41..19dd492 100644 --- a/include/entities.h +++ b/include/entities.h @@ -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); diff --git a/include/world.h b/include/world.h index 6c0395d..57ea091 100644 --- a/include/world.h +++ b/include/world.h @@ -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); diff --git a/src/Texture.cpp b/src/Texture.cpp index a3a8afe..a44f1a7 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -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; } diff --git a/src/entities.cpp b/src/entities.cpp index ee5a542..7f78637 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -120,10 +120,12 @@ Structures::Structures(){ //sets the structure type tex = new Texturec(1,"assets/house1.png"); inWorld = NULL; + name = NULL; } Structures::~Structures(){ delete tex; - delete[] name; + if(name) + delete[] name; } Mob::Mob(int sub){ @@ -175,7 +177,6 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){ } Object::~Object(){ delete[] pickupDialog; - delete tex; delete[] name; } @@ -278,10 +279,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){ @@ -337,7 +334,6 @@ void NPC::interact(){ //have the npc's interact back to the player } } - void Object::interact(void){ if(questObject && alive){ ui::dialogBox("You",":Yes:No",pickupDialog); @@ -434,7 +430,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: diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 6a2036c..c9c2b1e 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -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. @@ -48,6 +48,7 @@ static char *dialogBoxText = NULL; static char *dialogOptText[4]; static float dialogOptLoc[4][3]; static unsigned char dialogOptCount = 0; +static bool typeOutDone = true; extern void mainLoop(void); @@ -318,18 +319,23 @@ namespace ui { size=strlen(str); // Set the new target string size linc=0; // Reset the incrementers sinc=1; + typeOutDone = false; } /* * Draw the next letter if necessary. */ - if(++sinc==2){ + if(typeOutDone) + return str; + else if(++sinc==2){ sinc=0; strncpy(ret+linc,str+linc,1); // Get next character - if(linc<size)linc++; + if(linc<size) + linc++; + else typeOutDone = true; } return ret; // The buffered string. @@ -534,6 +540,12 @@ namespace ui { break; case SDL_MOUSEBUTTONDOWN: if((e.button.button&SDL_BUTTON_RIGHT)&&dialogBoxExists){ + + if(!typeOutDone){ + typeOutDone = true; + break; + } + for(i=0;i<dialogOptCount;i++){ if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] && diff --git a/src/world.cpp b/src/world.cpp index c078726..3557121 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; } } @@ -92,11 +95,9 @@ void World::deleteEntities(void){ } World::~World(void){ - - if(behind){ + if(behind) delete behind; - } - + delete bgTex; delete[] star; delete[] line; @@ -768,7 +769,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 +911,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 Binary files differnew file mode 100644 index 0000000..9aa0005 --- /dev/null +++ b/xcf/bgWoodTile.xcf |