diff options
author | Andy Belle-Isle <abelleisle@roadrunner.com> | 2015-09-14 11:51:05 -0400 |
---|---|---|
committer | Andy Belle-Isle <abelleisle@roadrunner.com> | 2015-09-14 11:51:05 -0400 |
commit | 7d974f6f4d54b3fbea99780ddf6e395b217065bc (patch) | |
tree | b9d8fe2166eedc57137737091c08cd7bbd749ddf /src | |
parent | d2d334f2cd3cc78f088f429eb5d0037268366e6d (diff) |
Added NPC Stuff
Added Wandering, and variable spawning amounts
Diffstat (limited to 'src')
-rw-r--r-- | src/World.cpp | 2 | ||||
-rw-r--r-- | src/entities.cpp | 23 | ||||
-rw-r--r-- | src/main.cpp | 38 |
3 files changed, 45 insertions, 18 deletions
diff --git a/src/World.cpp b/src/World.cpp index ce6a3c7..8083d47 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -116,7 +116,7 @@ void World::detect(vec2 *v,vec2 *vel,const float width){ return; // ;)
}
}else if(v->y>line[i].start+HLINE){ // Trashy gravity handling
- vel->y-=.00000001;
+ vel->y-=.0000001;
}
}
}
diff --git a/src/entities.cpp b/src/entities.cpp index 849bd7c..e9e69ce 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -7,6 +7,8 @@ void Entity::spawn(float x, float y){ vel.y = 0; right = false; left = false; + ticksToUse = 0; + canMove = false; } void Entity::draw(void){ @@ -14,20 +16,33 @@ void Entity::draw(void){ glRectf(loc.x,loc.y,loc.x+width,loc.y+height); } +void Entity::wander(int timeRun, vec2 *v){ + if(ticksToUse == 0){ + ticksToUse = timeRun; + v->x = .00010; + int hey = (grand() % 3 - 1); + v->x *= hey; + } + ticksToUse--; +} + Player::Player(){ width = HLINE * 8; height = HLINE * 18; speed = 1; type = 0; subtype = 5; + alive = true; } -NPC::NPC(){ +NPC::NPC(){ width = HLINE * 8; height = HLINE * 18; speed = 1; type = 0; subtype = 0; + alive = false; + canMove = true; } Structures::Structures(){ @@ -45,7 +60,11 @@ void Structures::spawn(int t, float x, float y){ width = 4 * HLINE; height = 4 * HLINE; - for(int i = 0;i<10;i++){ + int tempN = (grand() % 5 + 1); + npcAmt = tempN; + + for(int i = 0;i<eAmt(entnpc);i++){ + npc[i].alive = true; entnpc[i] = &npc[i]; npc[i].type = -1; //this will make the NPC spawn the start of a village entnpc[i]->spawn(loc.x + (float)(i - 5) / 8,0); //this will spawn the start of a village diff --git a/src/main.cpp b/src/main.cpp index e53664b..bed75c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,10 +16,11 @@ static unsigned int tickCount = 0, currentTime = 0, deltaTime = 0; +int npcAmt = 0; Entity *entPlay; //The player base -Entity *entnpc[10]; //The NPC base +Entity *entnpc[32]; //The NPC base Player player; //The actual player object -NPC npc[10]; +NPC npc[32]; Structures build; UIClass ui; //Yep World *currentWorld;//u-huh @@ -59,6 +60,7 @@ int main(int argc,char **argv){ return -1; } + glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT); glClearColor(.3,.5,.8,0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -75,6 +77,8 @@ int main(int argc,char **argv){ entPlay->spawn(0, 0); build.spawn(-1, (grand()%20)-10, 0); + //build.spawn(-1, 1.5, 0); + // Generate the world World *w=NULL,*w2=NULL; @@ -86,7 +90,7 @@ int main(int argc,char **argv){ currentWorld->addLayer(4); // shh unsigned char jklasdf; - for(jklasdf=0;jklasdf<10;jklasdf++){ + for(jklasdf=0;jklasdf<npcAmt;jklasdf++){ currentWorld->addEntity((void *)entnpc[jklasdf]); } @@ -105,6 +109,13 @@ int main(int argc,char **argv){ player.loc.x += (player.vel.x * player.speed) * deltaTime; //update the player's x based on player.loc.y += player.vel.y * deltaTime; + + for(int i = 0; i < eAmt(entnpc); i++){ + if(npc[i].alive == true){ + npc[i].loc.y += npc[i].vel.y * deltaTime; + npc[i].loc.x += npc[i].vel.x * deltaTime; + } + } gw=currentWorld->getWidth(); @@ -147,7 +158,7 @@ void render(){ glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode //set the the size of the screen if(player.loc.x-1<-1){ - glOrtho(-1,1,-1,1,-1,1); + glOrtho(-1,1, -1,1, -1,1); }else if(player.loc.x+1>-1+currentWorld->getWidth()){ glOrtho(-3+currentWorld->getWidth(),-1+currentWorld->getWidth(),-1,1,-1,1); }else{ @@ -167,14 +178,7 @@ void render(){ glColor3ub(120,30,30); //render the player glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); - ///TEMP NPC RENDER!!!!!! - for(int i = 0; i < 10; i++){ - npc[i].loc.y += npc[i].vel.y*deltaTime; - - glColor3ub(98, 78, 44); //render the NPC(s) - glRectf(npc[i].loc.x, npc[i].loc.y, npc[i].loc.x + npc[i].width, npc[i].loc.y + npc[i].height); - glEnd(); - } + glColor3ub(255,0,0); glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height); ///BWAHHHHHHHHHHHH @@ -196,14 +200,18 @@ void logic(){ if(player.left == true) {player.vel.x = -.00075;} if(player.right == false && player.left == false) {player.vel.x = 0;} - std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")"; + //std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")"; + //std::cout << tickCount << std::endl; currentWorld->detect(&player.loc,&player.vel,player.width); currentWorld->detect(&build.loc,&build.vel,build.width); - for(int i = 0; i < 10; i++){ - currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width); + for(int i = 0; i < eAmt(entnpc); i++){ + if(npc[i].alive == true){ + currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width); + entnpc[i]->wander((grand()%91 + 1), &npc[i].vel); + } } tickCount++; |