diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-01-03 21:46:03 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-01-03 21:46:03 -0500 |
commit | 5c7c99ac5fe1158adbdf0469fb36ddd153511f5d (patch) | |
tree | 1c50bda4f3e4a530fde7f97169dbd52a004d903a /src | |
parent | 1ccd85fd022ab5d628c9e26a213e47cf2687fce7 (diff) | |
parent | 272a152b54a198a84f122ab8bedb1019708b7008 (diff) |
shit
Diffstat (limited to 'src')
-rw-r--r-- | src/common.cpp | 27 | ||||
-rw-r--r-- | src/entities.cpp | 90 | ||||
-rw-r--r-- | src/gameplay.cpp | 84 | ||||
-rw-r--r-- | src/inventory.cpp | 13 | ||||
-rw-r--r-- | src/ui.cpp | 23 | ||||
-rw-r--r-- | src/world.cpp | 85 |
6 files changed, 213 insertions, 109 deletions
diff --git a/src/common.cpp b/src/common.cpp index a8a964e..dbcef0b 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1,7 +1,32 @@ #include <common.h> +#include <cstring> #include <cstdio> +#include <chrono> -#define DEBUG +#ifndef __WIN32__ + +unsigned int millis(void){ + std::chrono::system_clock::time_point now=std::chrono::system_clock::now(); + return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); +} + +#endif // __WIN32__ + +Condition::Condition(const char *_id,void *val){ + id = new char[strlen(_id)+1]; + strcpy(id,_id); + value = val; +} +Condition::~Condition(){ + delete[] id; +} + +bool Condition::sameID(const char *s){ + return !strcmp(id,s); +} +void *Condition::getValue(void){ + return value; +} void DEBUG_prints(const char* file, int line, const char *s,...){ va_list args; diff --git a/src/entities.cpp b/src/entities.cpp index 24c0d01..3849040 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,7 +1,10 @@ #include <entities.h> #include <ui.h> -extern FILE* names; +#include <istream> +//#include <unistd.h> + +extern std::istream *names; extern unsigned int loops; extern World *currentWorld; @@ -10,39 +13,30 @@ extern Player *player; extern const char *itemName; -extern - void getRandomName(Entity *e){ - int tempNum,max=0; + unsigned int tempNum,max=0; char *bufs; - rewind(names); + names->seekg(0,names->beg); - bufs = new char[16]; //(char *)malloc(16); + bufs = new char[32]; - for(;!feof(names);max++){ - fgets(bufs,16,(FILE*)names); - } + for(;!names->eof();max++) + names->getline(bufs,32); tempNum = rand() % max; - rewind(names); + names->seekg(0,names->beg); - for(int i=0;i<tempNum;i++){ - fgets(bufs,16,(FILE*)names); - } + for(unsigned int i=0;i<tempNum;i++) + names->getline(bufs,32); - switch(fgetc(names)){ + switch(bufs[0]){ + default : case 'm': e->gender = MALE; break; case 'f': e->gender = FEMALE;break; - default : break; } - if((fgets(bufs,16,(FILE*)names)) != NULL){ - bufs[strlen(bufs)] = '\0'; - strcpy(e->name,bufs); - if(e->name[strlen(e->name)-1] == '\n') - e->name[strlen(e->name)-1] = '\0'; - } + strcpy(e->name,bufs+1); delete[] bufs; } @@ -71,19 +65,20 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o } } - name = new char[16]; + name = new char[32]; getRandomName(this); } Player::Player(){ //sets all of the player specific traits on object creation width = HLINE * 10; - height = HLINE * 16; + height = HLINE * 15; type = PLAYERT; //set type to player subtype = 0; health = maxHealth = 100; speed = 1; - tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png"); + //tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png"); + tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png"); inv = new Inventory(PLAYER_INV_SIZE); } Player::~Player(){ @@ -106,7 +101,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation tex = new Texturec(1,"assets/NPC.png"); inv = new Inventory(NPC_INV_SIZE); - randDialog = rand() % 10 - 1; + randDialog = rand() % 12 - 1; } NPC::~NPC(){ while(!aiFunc.empty()){ @@ -150,15 +145,22 @@ Mob::Mob(int sub){ width = HLINE * 8; height = HLINE * 8; tex = new Texturec(1, "assets/robin.png"); + break; case MS_TRIGGER: width = HLINE * 20; height = 2000; tex = new Texturec(0); + break; case MS_DOOR: - width = HLINE * 10; - height = HLINE * 16; + width = HLINE * 12; + height = HLINE * 19; tex = new Texturec(1,"assets/door.png"); break; + case MS_PAGE: + width = HLINE * 6; + height = HLINE * 4; + tex = new Texturec(1,"assets/items/ITEM_PAGE.png"); + break; } inv = new Inventory(NPC_INV_SIZE); @@ -217,7 +219,7 @@ void Entity::draw(void){ //draws the entities case PLAYERT: static int texState = 0; static bool up = true; - if(loops % (int)((float)4/(float)speed) == 0){ + if(speed && !(loops % (int)(4.0f/(float)speed))){ //currentWorld->addParticle(loc.x,loc.y-HLINE,HLINE,HLINE,0,0,{0.0f,.17f,0.0f},1000); if(up){ if(++texState==2)up=false; @@ -245,6 +247,7 @@ void Entity::draw(void){ //draws the entities break; case MS_BIRD: case MS_DOOR: + case MS_PAGE: default: tex->bind(0); break; @@ -342,7 +345,8 @@ const char *randomDialog[] = { "HELP MY CAPS LOCK IS STUCK", "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.", "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.", - "Frig." + "Frig.", + "The sine of theta equals the opposite over the hypotenuese." }; void NPC::interact(){ //have the npc's interact back to the player @@ -391,7 +395,7 @@ void Object::interact(void){ * point to have non-normal traits so it could be invisible or invincible... */ -unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ +unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World *oi){ loc.x = x; loc.y = y; type = t; @@ -402,6 +406,8 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ height = 40 * HLINE; bsubtype = sub; + inWorld = oi; + /* * tempN is the amount of entities that will be spawned in the village. Currently the village * will spawn bewteen 2 and 7 villagers for the starting hut. @@ -416,7 +422,7 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ * with type NPC. */ - currentWorld->addNPC(loc.x + i * HLINE ,100); + inWorld->addNPC(loc.x + i * HLINE ,100); } @@ -458,10 +464,28 @@ void Mob::wander(int timeRun){ case MS_TRIGGER: if(player->loc.x + player->width / 2 > loc.x && player->loc.x + player->width / 2 < loc.x + width ){ - hey(this); + //if(!vfork()){ + hey(this); + /*_exit(0); + }*/ + + } + break; + case MS_PAGE: + if(player->loc.x > loc.x - 100 && + player->loc.x < loc.x + 100 && + ui::mouse.x > loc.x && + ui::mouse.x < loc.x + width && + ui::mouse.y > loc.y - width / 2 && + ui::mouse.y < loc.y + width * 1.5 && + SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){ + if(speed != 666){ + speed = 666; + hey(this); + speed = 0; + } } break; - case MS_DOOR: default: break; } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 70630dd..5184136 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -28,6 +28,10 @@ void story(Mob *callee){ callee->alive = false; } +/* + * Gens + */ + float gen_worldSpawnHill1(float x){ return (float)(pow(2,(-x+200)/5) + GEN_MIN); } @@ -50,30 +54,46 @@ void worldSpawnHill1_hillBlock(Mob *callee){ static Arena *a; void worldSpawnHill2_infoSprint(Mob *callee){ - callee->alive = false; - a = new Arena(currentWorld,player); - a->setBackground(BG_FOREST); - a->setBGM("assets/music/embark.wav"); - ui::toggleWhiteFast(); - ui::waitForCover(); - currentWorld = a; - ui::toggleWhiteFast(); + + ui::dialogBox(player->name,":Sure:Nah",false,"This page would like to take you somewhere."); + ui::waitForDialog(); + switch(ui::dialogOptChosen){ + case 1: + ui::dialogBox(player->name,NULL,true,"Cool."); + callee->alive = false; + a = new Arena(currentWorld,player); + a->setBackground(BG_FOREST); + a->setBGM("assets/music/embark.wav"); + ui::toggleWhiteFast(); + ui::waitForCover(); + currentWorld = a; + ui::toggleWhiteFast(); + break; + case 2: + default: + ui::dialogBox(player->name,NULL,false,"Okay then."); + break; + } + //ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!"); } -void worldSpawnHill3_itemGet(Mob *callee){ - ui::dialogBox("B-) ",NULL,true,"Right click to pick up items!"); - callee->alive = false; -} - -void worldSpawnHill3_itemSee(Mob *callee){ - ui::dialogBox("B-) ",NULL,true,"Press \'e\' to open your inventory!"); - callee->alive = false; +int worldSpawnHill2_Quest2(NPC *callee){ + ui::dialogBox(callee->name,NULL,false,"Yo."); + ui::waitForDialog(); + return 0; } -void worldSpawnHill3_leave(Mob *callee){ - ui::dialogBox("B-) ",NULL,true,"Now jump in this hole, and let your journey begin :)"); - callee->alive = false; +int worldSpawnHill2_Quest1(NPC *callee){ + ui::dialogBox(callee->name,":Cool.",false,"Did you know that I\'m the coolest NPC in the world?"); + ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + ui::dialogBox(callee->name,NULL,false,"Yeah, it is."); + currentWorld->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest2,true); + ui::waitForDialog(); + return 0; + } + return 1; } /* @@ -93,6 +113,8 @@ static World *worldSpawnHill1; static World *worldSpawnHill2; static World *worldSpawnHill3; +static IndoorWorld *worldSpawnHill2_Building1; + /* * initEverything() start */ @@ -109,17 +131,18 @@ void initEverything(void){ worldSpawnHill2 = new World(); worldSpawnHill2->generate(700); worldSpawnHill2->setBackground(BG_FOREST); - worldSpawnHill2->setBGM("assets/music/embark.wav"); - worldSpawnHill2->addMob(MS_TRIGGER,-400,0,worldSpawnHill2_infoSprint); + worldSpawnHill2->setBGM("assets/music/ozone.wav"); + worldSpawnHill2->addMob(MS_PAGE,-400,0,worldSpawnHill2_infoSprint); worldSpawnHill3 = new World(); worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3); worldSpawnHill3->setBackground(BG_FOREST); worldSpawnHill3->setBGM("assets/music/embark.wav"); - worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet); - worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee); + //worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet); + //worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee); worldSpawnHill3->addObject(FLASHLIGHT,false,"",-200,300); - worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave); + //worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave); + worldSpawnHill3->addHole(800,1000); worldSpawnHill1->toRight = worldSpawnHill2; @@ -133,7 +156,6 @@ void initEverything(void){ //playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story); - //worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2); //playerSpawnHill->addStructure(STRUCTURET,FOUNTAIN,(rand()%120*HLINE)+100*HLINE,100,test,iw); //playerSpawnHill->addStructure(STRUCTURET,HOUSE2,(rand()%120*HLINE)+300*HLINE,100,test,iw); @@ -141,13 +163,19 @@ void initEverything(void){ //playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/ - currentWorld = worldSpawnHill1; + worldSpawnHill2_Building1 = new IndoorWorld(); + worldSpawnHill2_Building1->generate(300); + worldSpawnHill2_Building1->setBackground(BG_WOODHOUSE); + worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav"); + + worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1); + worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false); player = new Player(); player->spawn(200,100); - + + currentWorld = worldSpawnHill1; currentWorld->bgmPlay(NULL); - atexit(destroyEverything); } diff --git a/src/inventory.cpp b/src/inventory.cpp index 5ae97b4..c0f4163 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -107,7 +107,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ void Inventory::draw(void){ static unsigned int lop = 0; - static unsigned int numSlot = 7; + const unsigned int numSlot = 7; static std::vector<int>dfp(numSlot); static std::vector<Ray>iray(numSlot); static std::vector<vec2>curCoord(numSlot); @@ -153,7 +153,7 @@ void Inventory::draw(void){ curCoord[a].y += float((dfp[a]) * sin(angle*PI/180)); r.end = curCoord[a]; - glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range)*0.5f); + glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)(range?range:1))*0.5f); glBegin(GL_QUADS); glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)); glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)); @@ -164,7 +164,7 @@ void Inventory::draw(void){ if(inv[a].count > 0){ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]); - glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)range)*0.8f); + glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f); glBegin(GL_QUADS); if(item[inv[a].id].height > item[inv[a].id].width){ glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2)); @@ -203,7 +203,7 @@ void Inventory::draw(void){ mouseSel=true; }else{ if((ui::mouse.x - offset.x) >= mouseStart.x){ - thing = ((ui::mouse.x - offset.x) - mouseStart.x)/80; + thing = (ui::mouse.x - offset.x - mouseStart.x)/80; highlight=sel+thing; if(highlight>numSlot-1)highlight=numSlot-1; if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){ @@ -299,10 +299,10 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){ glBindTexture(GL_TEXTURE_2D,itemtex[id]); glColor4ub(255,255,255,255); glBegin(GL_QUADS); - glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y); + glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y); glTexCoord2i(1,1);glVertex2f(itemLoc.x+item[id].width,itemLoc.y); glTexCoord2i(1,0);glVertex2f(itemLoc.x+item[id].width,itemLoc.y+item[id].height); - glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+item[id].height); + glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+item[id].height); glEnd(); glDisable(GL_TEXTURE_2D); glTranslatef(player->loc.x*2,0,0); @@ -341,6 +341,7 @@ int Inventory::useItem(void){ } break; default: + //hangle++; break; } } @@ -300,7 +300,8 @@ namespace ui { } }while(s[++i]); - return putString(x-width/2,y,s); + putString(x-width/2,y,s); + return width; } /* @@ -464,6 +465,12 @@ namespace ui { }while(fadeIntensity < 255); fadeIntensity = 255; } + void waitForNothing(unsigned int ms){ + unsigned int target = millis() + ms; + do{ + mainLoop(); + }while(millis() < target); + } void importantText(const char *text,...){ va_list textArgs; @@ -481,7 +488,7 @@ namespace ui { } void draw(void){ unsigned char i; - float x,y; + float x,y,tmp; char *rtext; if(dialogBoxExists){ @@ -506,7 +513,7 @@ namespace ui { glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1); glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4); glVertex2f(x-1 ,y-1-SCREEN_HEIGHT/4); - glVertex2f(x-1 ,y+2); + glVertex2f(x ,y+1); glEnd(); glColor3ub(0,0,0); @@ -518,12 +525,12 @@ namespace ui { for(i=0;i<dialogOptCount;i++){ setFontColor(255,255,255); - dialogOptLoc[i][1]=y-SCREEN_HEIGHT/4+(fontSize+HLINE)*(i+1); - dialogOptLoc[i][2]= - putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]); - dialogOptLoc[i][0]=offset.x-dialogOptLoc[i][2]/2; + tmp = putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]); + dialogOptLoc[i][2] = offset.x + tmp; + dialogOptLoc[i][0] = offset.x - tmp; + dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1); if(mouse.x > dialogOptLoc[i][0] && - mouse.x < dialogOptLoc[i][0] + dialogOptLoc[i][2] && + mouse.x < dialogOptLoc[i][2] && mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize setFontColor(255,255,0); diff --git a/src/world.cpp b/src/world.cpp index 1b460a2..5663086 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -17,13 +17,14 @@ bool worldInside = false; // True if player is inside a structure WEATHER weather = SUNNY; -const char *bgPaths[2][6]={ +const char *bgPaths[2][7]={ {"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/dirt.png"}, // Dirt {"assets/bgWoodTile.png", NULL, NULL, @@ -51,7 +52,7 @@ float worldGetYBase(World *w){ void World::setBackground(WORLD_BG_TYPE bgt){ switch(bgt){ case BG_FOREST: - bgTex = new Texturec(6,bgPaths[0]); + bgTex = new Texturec(7,bgPaths[0]); break; case BG_WOODHOUSE: bgTex = new Texturec(1,bgPaths[1]); @@ -206,7 +207,7 @@ void World::generate(unsigned int width){ // Generates the world and sets all va * by setting an RGB value of color (red), color - 50 (green), color - 100 (blue). */ - line[i].color = rand() % 20 + 100; // 100 to 120 + line[i].color = rand() % 32 / 8; // 100 to 120 /* * Each line has two 'blades' of grass, here we generate random heights for them. @@ -344,13 +345,12 @@ void World::setBGM(const char *path){ } } -void World::bgmPlay(World *prev){ - if(!prev || strcmp(bgm,prev->bgm)){ +void World::bgmPlay(World *prev){ + if(prev && strcmp(bgm,prev->bgm)){ + Mix_FadeOutMusic(800); Mix_VolumeMusic(50); Mix_PlayMusic(bgmObj,-1); // Loop infinitely - }/*else{ - Mix_FadeOutMusic(800); - }*/ + } } int worldShade = 0; @@ -550,20 +550,23 @@ LOOP2: */ bool hey=false; + glEnable(GL_TEXTURE_2D); + bgTex->bindNext(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction glBegin(GL_QUADS); for(i=is;i<(unsigned)ie-GEN_INC;i++){ cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset if(!cline[i].y){ cline[i].y=base; hey=true; - safeSetColor(cline[i].color-100+shade,cline[i].color-150+shade,cline[i].color-200+shade); - }else{ - safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade); // Set the shaded dirt color - } - glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); - glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT); - glVertex2i(cx_start+i*HLINE+HLINE,0); - glVertex2i(cx_start+i*HLINE ,0); + glColor4ub(0,0,0,255); + }else + safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255); + glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); + glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT); + glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0); + glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE ,0); cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value if(hey){ hey=false; @@ -571,6 +574,7 @@ LOOP2: } } glEnd(); + glDisable(GL_TEXTURE_2D); /* * Draw grass on every line. @@ -604,7 +608,7 @@ LOOP2: cline[i].y+=(yoff-DRAW_Y_OFFSET); - safeSetColor(shade,150+shade,shade); + safeSetColor(shade,100+shade*1.5,shade); glVertex2i(cx_start+i*HLINE ,cline[i].y+cgh[0]); glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]); @@ -899,16 +903,17 @@ LOOOOP: goto LOOOOP; } } -void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *outside,World *inside){ +void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ build.push_back(new Structures()); - build.back()->spawn(t,sub,x,y); - build.back()->inWorld=outside; - build.back()->inside=(void *)inside; + build.back()->spawn(t,sub,x,y,this); + build.back()->inWorld=this; + build.back()->inside = (World *)inside; + ((IndoorWorld *)inside)->outside = this; entity.push_back(build.back()); } -void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside){ +void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside){ std::cout << npcMin << ", " << npcMax << std::endl; int xwasd; for(int i = 0; i < bCount; i++){ @@ -917,7 +922,7 @@ void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float for(auto &bu : build){ if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE; } - addStructure(t,HOUSE,xwasd,y,outside,inside); + addStructure(t,HOUSE,xwasd,y,outside); } } void World::addMob(int t,float x,float y){ @@ -975,6 +980,14 @@ void World::addLayer(unsigned int width){ behind->bgTex=bgTex; } +NPC *World::getAvailableNPC(void){ + for(auto &n : npc){ + if(n->aiFunc.empty()) + return n; + } + return (NPC *)NULL; +} + World *World::goWorldLeft(Player *p){ if(toLeft&&p->loc.x<x_start+HLINE*15){ p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10; @@ -1090,7 +1103,8 @@ void IndoorWorld::generate(unsigned int width){ // Generates a flat area of wid void IndoorWorld::draw(Player *p){ unsigned int i,ie; - int j,x,v_offset; + //int j,x,v_offset; + int x; /* * Draw the background. @@ -1099,15 +1113,17 @@ void IndoorWorld::draw(Player *p){ glEnable(GL_TEXTURE_2D); bgTex->bind(0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction glColor4ub(255,255,255,255); glBegin(GL_QUADS); - for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){ - glTexCoord2i(1,1);glVertex2i(j ,0); - glTexCoord2i(0,1);glVertex2i(j+512,0); - glTexCoord2i(0,0);glVertex2i(j+512,512); - glTexCoord2i(1,0);glVertex2i(j ,512); - } + //for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){ + glTexCoord2i(0,1); glVertex2i( x_start - SCREEN_WIDTH / 2,0); + glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,1);glVertex2i(-x_start + SCREEN_WIDTH / 2,0); + glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,0);glVertex2i(-x_start + SCREEN_WIDTH / 2,SCREEN_HEIGHT); + glTexCoord2i(0,0); glVertex2i( x_start - SCREEN_WIDTH / 2,SCREEN_HEIGHT); + //} glEnd(); glDisable(GL_TEXTURE_2D); @@ -1116,13 +1132,16 @@ void IndoorWorld::draw(Player *p){ * Calculate the starting and ending points to draw the ground from. */ - v_offset = (p->loc.x - x_start) / HLINE; + /*v_offset = (p->loc.x - x_start) / HLINE; j = v_offset - (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; if(j < 0)j = 0; i = j; ie = v_offset + (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; - if(ie > lineCount)ie = lineCount; + if(ie > lineCount)ie = lineCount;*/ + + i = 0; + ie = lineCount; /* * Draw the ground. |