diff options
author | Andy Belle-Isle <abelleisle@roadrunner.com> | 2015-09-12 21:17:12 -0400 |
---|---|---|
committer | Andy Belle-Isle <abelleisle@roadrunner.com> | 2015-09-12 21:17:12 -0400 |
commit | 328a35846f24aa61524e27d7a08f99617f1b0e55 (patch) | |
tree | 966398509d063b10b3949ec0384e3aa2a5cdb062 /src | |
parent | f3028d986781fb9a5199b6a0394b5a79871af156 (diff) |
Updated village spawning with fixes to other things
Diffstat (limited to 'src')
-rw-r--r-- | src/UIClass.cpp | 3 | ||||
-rw-r--r-- | src/entities.cpp | 30 | ||||
-rw-r--r-- | src/main.cpp | 71 |
3 files changed, 69 insertions, 35 deletions
diff --git a/src/UIClass.cpp b/src/UIClass.cpp index 3f3a91a..18e273e 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -16,6 +16,7 @@ void UIClass::handleEvents(){ case SDL_KEYDOWN: if(e.key.keysym.sym == SDLK_d) player.right = true; if(e.key.keysym.sym == SDLK_a) player.left = true; + if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 3; if(e.key.keysym.sym == SDLK_SPACE){ player.loc.y += HLINE*1.2; player.vel.y += .004; @@ -38,6 +39,8 @@ void UIClass::handleEvents(){ case SDL_KEYUP: if(e.key.keysym.sym == SDLK_d) player.right = false; if(e.key.keysym.sym == SDLK_a) player.left = false; + if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 1.0; + if(e.key.keysym.sym == SDLK_ESCAPE) gameRunning = false; break; } diff --git a/src/entities.cpp b/src/entities.cpp index 19ac536..849bd7c 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -8,6 +8,7 @@ void Entity::spawn(float x, float y){ right = false; left = false; } + void Entity::draw(void){ glColor3ub(0,0,100); glRectf(loc.x,loc.y,loc.x+width,loc.y+height); @@ -18,10 +19,7 @@ Player::Player(){ height = HLINE * 18; speed = 1; type = 0; -} - -Player::~Player(){ - + subtype = 5; } NPC::NPC(){ @@ -29,4 +27,28 @@ NPC::NPC(){ height = HLINE * 18; speed = 1; type = 0; + subtype = 0; +} + +Structures::Structures(){ + type = -1; + speed = 0; +} + +void Structures::spawn(int t, float x, float y){ + loc.x = x; + loc.y = y; + type = t; + + /*VILLAGE*/ + if(type == -1){ + width = 4 * HLINE; + height = 4 * HLINE; + + for(int i = 0;i<10;i++){ + 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 a9e5179..4e43105 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,18 +16,22 @@ static unsigned int tickCount = 0, currentTime = 0, deltaTime = 0; -Entity *entPlay; //The player base -Entity *entnpc; //The NPC base -Player player; //The actual player object -NPC npc; // A test NPC -UIClass ui; // Handles the user interface -World *currentWorld; // Points to the current 'world' the player is in - -float interpolate(float goal, float current, float dt){ - float difference=goal-current; - if(difference>dt)return current+dt; - if(difference<dt)return current-dt; - return goal; +Entity *entPlay; //The player base +Entity *entnpc[10]; //The NPC base +Player player; //The actual player object +NPC npc[10]; +Structures build; +UIClass ui; //Yep +World *currentWorld;//u-huh + +//static int randNext=1; + +void irand(unsigned int seed){ + srand(seed); +} + +int grand(void){ + return rand(); } void logic(); @@ -77,9 +81,9 @@ int main(int argc,char **argv){ entPlay = &player; entPlay->spawn(0, 0); - entnpc = &npc; - npc.type = -1; //this will make the NPC spawn the start of a village - entnpc->spawn(.5,0);// (grand()%20)-10 ,0); //this will spawn the start of a village + + build.spawn(-1, (grand()%20)-10, 0); + // Generate the world World *w=NULL,*w2=NULL; @@ -88,7 +92,7 @@ int main(int argc,char **argv){ currentWorld=w; currentWorld->addLayer(3); - currentWorld->addEntity((void *)entnpc); + //currentWorld->addEntity((void *)entnpc); float gw; @@ -102,10 +106,9 @@ int main(int argc,char **argv){ prevTime = SDL_GetTicks(); } - player.loc.x += player.vel.x*deltaTime; //update the player's x based on - player.loc.y += player.vel.y*deltaTime; + player.loc.x += (player.vel.x * player.speed) * deltaTime; //update the player's x based on + player.loc.y += player.vel.y * deltaTime; - npc.loc.y += npc.vel.y*deltaTime; gw=currentWorld->getWidth(); if(player.loc.x+player.width>-1+gw){ @@ -168,14 +171,15 @@ void render(){ glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); ///TEMP NPC RENDER!!!!!! - /*glColor3ub(98, 78, 44); //render the NPC(s) - glRectf(npc.loc.x, npc.loc.y, npc.loc.x + .25, npc.loc.y + .25); - glColor3ub(83, 49, 24); - glBegin(GL_TRIANGLES); - glVertex2f(npc.loc.x, npc.loc.y + .25); - glVertex2f(npc.loc.x + .25, npc.loc.y + .25); - glVertex2f(npc.loc.x + .125, npc.loc.y + .35); - glEnd();*/ + 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 /************************** @@ -189,14 +193,19 @@ void render(){ void logic(){ ui.handleEvents(); // Handle events - if(player.right == true) {player.vel.x = .002;} - if(player.left == true) {player.vel.x = -.002;} + if(player.right == true) {player.vel.x = .00075;} + 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::endl; + currentWorld->detect(&player.loc,&player.vel,player.width); - currentWorld->detect(&npc.loc,&player.vel,npc.height); + + 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); + } tickCount++; } |