From fcf3e396c57b285b621624f63f9acd6515c58ef9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 17 Nov 2015 08:38:51 -0500 Subject: cutscenes, arenas --- src/entities.cpp | 47 ++++++++++++++++++++---------- src/gameplay.cpp | 27 ++++++++++++++--- src/ui.cpp | 13 +++++++-- src/world.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 141 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/entities.cpp b/src/entities.cpp index a8e9bfb..67a564a 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -25,8 +25,11 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o if(!maxHealth)health = maxHealth = 1; - if(type==MOBT) - Mobp(this)->init_y=loc.y; + if(type==MOBT){ + if(Mobp(this)->subtype == MS_BIRD){ + Mobp(this)->init_y=loc.y; + } + } name = (char*)malloc(16); getName(); @@ -71,7 +74,7 @@ Structures::Structures(){ //sets the structure type } Mob::Mob(int sub){ - type = MOBT; + type = MOBT; maxHealth = health = 50; @@ -85,6 +88,10 @@ Mob::Mob(int sub){ width = HLINE * 8; height = HLINE * 8; tex = new Texturec(1, "assets/robin.png"); + case MS_TRIGGER: + width = HLINE * 8; + height = 2000; + tex = new Texturec(0); break; } @@ -152,28 +159,27 @@ void Entity::draw(void){ //draws the entities tex->bind(2); break; } - } - else{ + }else{ tex->bind(1); } }else if(type == MOBT){ switch(subtype){ - case 1: //RABBIT + case MS_RABBIT: if(ground == 0){ tex->bind(1); }else if(ground == 1){ tex->bind(0); } break; - case 2: //RABBIT - if(ground == 0){ - tex->bind(0); - }else if(ground == 1){ - tex->bind(0); - } + case MS_BIRD: + tex->bind(0); + break; + case MS_TRIGGER: + goto NOPE; break; default: - break; + tex->bind(0); + break; } }else if(type == OBJECTT){ tex->bind(0); @@ -187,6 +193,7 @@ void Entity::draw(void){ //draws the entities glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height); glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height); glEnd(); +NOPE: glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glPopMatrix(); @@ -352,7 +359,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure void Mob::wander(int timeRun){ static int direction; //variable to decide what direction the entity moves - static unsigned int hey=0,hi=0; + static unsigned int heya=0,hi=0; switch(subtype){ case MS_RABBIT: if(!ticksToUse){ @@ -373,10 +380,18 @@ void Mob::wander(int timeRun){ case MS_BIRD: if(loc.y<=init_y-.2)vel.y=.02*deltaTime; // TODO handle direction vel.x=.02*deltaTime; - if(++hey==200){hey=0;hi^=1;} + if(++heya==200){heya=0;hi^=1;} if(hi)vel.x*=-1; break; + case MS_TRIGGER: + if(player->loc.x + player->width / 2 > loc.x && + 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(); + } + break; default: break; } -} \ No newline at end of file +} diff --git a/src/gameplay.cpp b/src/gameplay.cpp index fcc501c..e5d7251 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -41,9 +41,26 @@ int giveTestQuest(NPC *speaker){ return 0; } +static Arena *a; + +void CUTSCENEEE(void){ + char opt[]=":K."; + player->vel.x = 0; + ui::dialogBox(player->name,opt,"No way I\'m gettin\' up this hill."); + + waitForDialog(); + + a = new Arena(currentWorld,player); + + currentWorld = a; + + /*player->right = true; + player->left = false; + player->loc.x += HLINE * 5;*/ +} + float playerSpawnHillFunc(float x){ - x=-x; - return (float)(pow(2,(x+200)/5) + 80); + return (float)(pow(2,(-x+200)/5) + 80); } void initEverything(void){ unsigned int i; @@ -104,13 +121,15 @@ void initEverything(void){ currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw); /* - * Spawn a mob. + * Spawn some mobs. */ + + playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE); test->addMob(MS_RABBIT,200,100); test->addMob(MS_BIRD,-500,500); - currentWorld->addObject(2, 500,200); + test->addObject(2, 500,200); /* * Link all the entities that were just created to the initial world, and setup a test AI function. diff --git a/src/ui.cpp b/src/ui.cpp index bbec2de..e4cb93a 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -55,6 +55,9 @@ static unsigned char dialogOptCount = 0; bool fadeEnable = false; + +bool inBattle = false; + namespace ui { /* @@ -304,7 +307,7 @@ namespace ui { * Reset values if a new string is being passed. */ - if(!size || ((linc>15)&(strncmp(ret,str,15)))){ + if(strncmp(ret,str,linc-1)){ memset(ret,0,512); // Zero the buffer size=strlen(str); // Set the new target string size linc=0; // Reset the incrementers @@ -434,7 +437,7 @@ namespace ui { if(dialogBoxExists){ glColor3ub(0,0,0); - x=player->loc.x-SCREEN_WIDTH/2+HLINE*8; + x=offset.x-SCREEN_WIDTH/2+HLINE*8; y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8; glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4); @@ -543,7 +546,11 @@ DONE: player->ground=false; player->loc.y-=HLINE*1.5; } - if(SDL_KEY==SDLK_w)currentWorld=currentWorld->goInsideStructure(player); + if(SDL_KEY==SDLK_w){ + if(inBattle){ + currentWorld=((Arena *)currentWorld)->exitArena(player); + }else currentWorld=currentWorld->goInsideStructure(player); + } if(SDL_KEY==SDLK_SPACE){ // Jump if(player->ground){ player->vel.y=.4; diff --git a/src/world.cpp b/src/world.cpp index 2757471..335bda6 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -286,9 +286,7 @@ LOOP2: /* * Draw the layer up until the grass portion, which is done later. */ - /* - * TODO: CLYNE CHANGE THE NAME OF THIS - */ + bool hey=false; glBegin(GL_QUADS); for(i=is;ialive&&e->health<=0){ - - e->alive=false; - std::cout<<"Killing entity..."<alive||e->health<=0){ + + for(i=0;itype){ + case STRUCTURET: + for(j=0;jname<<"."<alive){ + if(e->type == MOBT && Mobp(e)->subtype == MS_TRIGGER)return; + /* * Calculate the line that this entity is currently standing on. */ @@ -577,6 +610,14 @@ 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)()){ + mob.push_back(new Mob(t)); + mob.back()->spawn(x,y); + mob.back()->hey = hey; + + entity.push_back(mob.back()); +} + void World::addNPC(float x,float y){ npc.push_back(new NPC()); npc.back()->spawn(x,y); @@ -727,9 +768,33 @@ void IndoorWorld::draw(Player *p){ p->draw(); } -void Arena::drawDoor(void){ +extern bool inBattle; + +Arena::Arena(World *leave,Player *p){ + generate(300); + door.y = line[299].y; + door.x = 100; + exit = leave; + + npc.push_back(new NPC()); + entity.push_back(npc.back()); + entity.back()->spawn(door.x,door.y); + entity.back()->width = HLINE * 12; + entity.back()->height = HLINE * 16; + + inBattle = true; + pxy = p->loc; } -World *Arena::exitArena(void){ - return this; +World *Arena::exitArena(Player *p){ + npc[0]->loc.x = door.x; + npc[0]->loc.y = door.y; + if(p->loc.x + p->width / 2 > door.x && + p->loc.x + p->width / 2 < door.x + HLINE * 12 ){ + inBattle = false; + p->loc = pxy; + return exit; + }else{ + return this; + } } -- cgit v1.2.3 From 5598e4d1f52224f2d075dc318868e284b2f20a78 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 18 Nov 2015 08:49:51 -0500 Subject: tiled backgrounds, ortho fix --- Changelog | 7 +++++++ assets/bgFarTreeTile.png | Bin 0 -> 9433 bytes assets/bgFrontTreeTile.png | Bin 0 -> 27660 bytes assets/bgMidTreeTile.png | Bin 0 -> 30605 bytes assets/bgTrashWaves.png | Bin 0 -> 1454217 bytes main.cpp | 48 +++++++++++++++++++++++---------------------- src/world.cpp | 6 +++--- xcf/bgTrashWaves.xcf | Bin 0 -> 3932867 bytes 8 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 assets/bgFarTreeTile.png create mode 100644 assets/bgFrontTreeTile.png create mode 100644 assets/bgMidTreeTile.png create mode 100644 assets/bgTrashWaves.png create mode 100644 xcf/bgTrashWaves.xcf (limited to 'src') diff --git a/Changelog b/Changelog index 1a75022..0fe9386 100644 --- a/Changelog +++ b/Changelog @@ -304,3 +304,10 @@ - added entity deletion when an entity dies - fixed errors with typewriter-text - finished cutscene triggers + +11/18/2015: +=========== + + - converted layered background items to tiles + - fixed ortho in small spaces + - began formalizing item system diff --git a/assets/bgFarTreeTile.png b/assets/bgFarTreeTile.png new file mode 100644 index 0000000..07546a5 Binary files /dev/null and b/assets/bgFarTreeTile.png differ diff --git a/assets/bgFrontTreeTile.png b/assets/bgFrontTreeTile.png new file mode 100644 index 0000000..7fc7450 Binary files /dev/null and b/assets/bgFrontTreeTile.png differ diff --git a/assets/bgMidTreeTile.png b/assets/bgMidTreeTile.png new file mode 100644 index 0000000..126723e Binary files /dev/null and b/assets/bgMidTreeTile.png differ diff --git a/assets/bgTrashWaves.png b/assets/bgTrashWaves.png new file mode 100644 index 0000000..6a177cd Binary files /dev/null and b/assets/bgTrashWaves.png differ diff --git a/main.cpp b/main.cpp index 62cd87a..1f8c58e 100644 --- a/main.cpp +++ b/main.cpp @@ -434,12 +434,12 @@ int main(int argc, char *argv[]){ * Load a temporary background image. */ - bgDay =Texture::loadTexture("assets/bg.png" ); - bgNight =Texture::loadTexture("assets/bgn.png" ); - bgMtn =Texture::loadTexture("assets/bgFarMountain.png"); - bgTreesFront =Texture::loadTexture("assets/bgFrontTree.png" ); - bgTreesMid =Texture::loadTexture("assets/bgMidTree.png" ); - bgTreesFar =Texture::loadTexture("assets/bgFarTree.png" ); + bgDay =Texture::loadTexture("assets/bg.png" ); + bgNight =Texture::loadTexture("assets/bgn.png" ); + bgMtn =Texture::loadTexture("assets/bgFarMountain.png" ); + bgTreesFront =Texture::loadTexture("assets/bgFrontTreeTile.png" ); + bgTreesMid =Texture::loadTexture("assets/bgMidTreeTile.png" ); + bgTreesFar =Texture::loadTexture("assets/bgFarTreeTile.png" ); /* * Load sprites used in the inventory menu. See src/inventory.cpp @@ -572,7 +572,9 @@ void render(){ * see past the world render */ - if(!worldInside){ + if(currentWorld->getTheWidth() < SCREEN_WIDTH){ + offset.x = 0; + }else if(!worldInside){ if(player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth() * -0.5f) offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2) + player->width / 2; if(player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() * 0.5f) @@ -674,7 +676,7 @@ void render(){ * Draws stars if it is an appropriate time of day for them. */ - int base = 40 - (int)worldGetYBase(currentWorld); + int base = 80; int shade = worldShade*2; if(((weather==DARK )&(tickCount%DAY_CYCLE)getTheWidth()/1920; i++){ - glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.6,base); - glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.6,base); - glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.6,base+1080); - glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.6,base+1080); + for(int i = -currentWorld->getTheWidth() / 2; i <= currentWorld->getTheWidth() / 2; i += 300){ + glTexCoord2i(0,1);glVertex2i(i+offset.x*.6,base); + glTexCoord2i(1,1);glVertex2i((i+300)+offset.x*.6,base); + glTexCoord2i(1,0);glVertex2i((i+300)+offset.x*.6,base+200); + glTexCoord2i(0,0);glVertex2i(i+offset.x*.6,base+200); } glEnd(); glBindTexture(GL_TEXTURE_2D, bgTreesMid); glBegin(GL_QUADS); safeSetColorA(150-shade,150-shade,150-shade,250); - for(int i = 0; i <= currentWorld->getTheWidth()/1920; i++){ - glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.4,base); - glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.4,base); - glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.4,base+1080); - glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.4,base+1080); + for(int i = -currentWorld->getTheWidth() / 2; i <= currentWorld->getTheWidth() / 2; i += 400){ + glTexCoord2i(0,1);glVertex2i(i+offset.x*.4,base); + glTexCoord2i(1,1);glVertex2i((i+300)+offset.x*.4,base); + glTexCoord2i(1,0);glVertex2i((i+300)+offset.x*.4,base+200); + glTexCoord2i(0,0);glVertex2i(i+offset.x*.4,base+200); } glEnd(); glBindTexture(GL_TEXTURE_2D, bgTreesFront); glBegin(GL_QUADS); safeSetColorA(255-shade,255-shade,255-shade,255); - for(int i = 0; i <= currentWorld->getTheWidth()/1920; i++){ - glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.25,base); - glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.25,base); - glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.25,base+1080); - glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.25,base+1080); + for(int i = -currentWorld->getTheWidth() / 2; i <= currentWorld->getTheWidth() / 2; i += 280){ + glTexCoord2i(0,1);glVertex2i(i+offset.x*.25,base); + glTexCoord2i(1,1);glVertex2i((i+300)+offset.x*.25,base); + glTexCoord2i(1,0);glVertex2i((i+300)+offset.x*.25,base+200); + glTexCoord2i(0,0);glVertex2i(i+offset.x*.25,base+200); } glEnd(); glDisable(GL_TEXTURE_2D); diff --git a/src/world.cpp b/src/world.cpp index 335bda6..904bed7 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -17,13 +17,13 @@ bool worldInside = false; float worldGetYBase(World *w){ - float base = 0; + /*float base = 0; World *ptr = w; while(ptr->infront){ base+=DRAW_Y_OFFSET; ptr=ptr->infront; - } - return base; + }*/ + return /*base*/ GEN_MIN; } struct wSavePack { diff --git a/xcf/bgTrashWaves.xcf b/xcf/bgTrashWaves.xcf new file mode 100644 index 0000000..0214d8d Binary files /dev/null and b/xcf/bgTrashWaves.xcf differ -- cgit v1.2.3