diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-04-06 07:40:28 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-04-06 07:40:28 -0400 |
commit | 345a0fe74704dec3eecbb77e4bb252b3d4dd4308 (patch) | |
tree | 772a0a0925195193f9152ecff259c9f27f13f413 /main.cpp | |
parent | 3ca4cca09ed9a2b1028928dea98f19bd26ab3b2c (diff) | |
parent | 16920d744a2e638f564753f15f1269f51c131b6b (diff) |
First world and style
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 80 |
1 files changed, 45 insertions, 35 deletions
@@ -444,7 +444,7 @@ int main(int argc, char *argv[]){ Mix_CloseAudio(); destroyInventory(); - ui::destroyFonts(); + ui::destroyFonts(); Texture::freeTextures(); SDL_GL_DeleteContext(mainGLContext); @@ -485,7 +485,8 @@ void mainLoop(void){ deltaTime = currentTime - prevTime; prevTime = currentTime; - if(currentMenu)goto MENU; + if ( currentMenu ) + goto MENU; /* * Run the logic handler if MSEC_PER_TICK milliseconds have passed. @@ -525,14 +526,14 @@ void mainLoop(void){ if ( deltaTime ) fps = 1000 / deltaTime; - if(!(debugDiv % 10)) + if ( !(debugDiv % 10) ) debugY = player->loc.y; } MENU: render(); } -void render(){ +void render() { /* * This offset variable is what we use to move the camera and locked @@ -699,18 +700,27 @@ void render(){ getWorldWeatherStr( weather ).c_str() ); - if(ui::posFlag){ + if ( ui::posFlag ) { glBegin(GL_LINES); - glColor3ub(255,0,0); + /*glColor3ub(255,0,0); glVertex2i(0,0); - glVertex2i(0,SCREEN_HEIGHT); + glVertex2i(0,SCREEN_HEIGHT);*/ - glColor3ub(255,255,255); + /*glColor3ub(255,255,255); glVertex2i(player->loc.x + player->width/2,0); glVertex2i(player->loc.x + player->width/2,SCREEN_HEIGHT); + glVertex2i( offset.x - SCREEN_WIDTH / 2, player->loc.y + player->height / 2 ); + glVertex2i( offset.x + SCREEN_WIDTH / 2, player->loc.y + player->height / 2 );*/ + + /*glVertex2i( -SCREEN_WIDTH / 2 + offset.x, player->loc.y ); + glVertex2i( SCREEN_WIDTH / 2 + offset.x, player->loc.y );*/ + + glColor3ub(100,100,255); + for ( auto &e : currentWorld->entity ) { + glVertex2i( player->loc.x + player->width / 2, player->loc.y + player->height / 2 ); + glVertex2i( e->loc.x + e->width / 2, e->loc.y + e->height / 2 ); + } - glVertex2i(-SCREEN_WIDTH/2+offset.x,player->loc.y); - glVertex2i(SCREEN_WIDTH/2+offset.x, player->loc.y); glEnd(); } @@ -757,21 +767,33 @@ void render(){ static bool objectInteracting = false; void logic(){ - - /* - * NPCSelected is used to insure that only one NPC is made interactable with the mouse - * if, for example, multiple entities are occupying one space. - */ - static bool NPCSelected = false; - /* - * Run the world's detect function. This handles the physics of the player and any entities - * that exist in this world. - */ - - - if(player->loc.y<.02)gameRunning=false; + // exit the game if the player falls out of the world + if ( player->loc.y < 0 ) + gameRunning = false; + + if ( player->inv->usingi ) { + for ( auto &e : currentWorld->entity ) { + e->hit = false; + + if ( player->inv->usingi && !e->hit && + player->inv->detectCollision( { e->loc.x, e->loc.y }, { e->loc.x + e->width, e->loc.y + e->height} ) ) { + e->health -= 25; + e->hit = true; + e->forcedMove = true; + e->vel.x = 0.5f * (player->left ? -1 : 1); + e->vel.y = 0.2f; + break; + //for(int r = 0; r < (rand()%5);r++) + // currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%4)*.001-.002), {(rand()%75+10)/100.0f,0,0}, 10000); + //if ( e->health <= 0 ) { + //for(int r = 0; r < (rand()%30)+15;r++) + // currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%10)*.01-.05), {(rand()%75)+10/100.0f,0,0}, 10000); + } + } + player->inv->usingi = false; + } /* * Entity logic: This loop finds every entity that is alive and in the current world. It then @@ -791,18 +813,6 @@ void logic(){ if(n->canMove) n->wander((rand() % 120 + 30)); - if(!player->inv->usingi) n->hit = false; - - if(player->inv->usingi && !n->hit && player->inv->detectCollision({n->loc.x, n->loc.y},{n->loc.x+n->width,n->loc.y+n->height})){ - n->health -= 25; - n->hit = true; - for(int r = 0; r < (rand()%5);r++) - currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%4)*.001-.002), {(rand()%75+10)/100.0f,0,0}, 10000); - if(n->health <= 0){ - for(int r = 0; r < (rand()%30)+15;r++) - currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%10)*.01-.05), {(rand()%75)+10/100.0f,0,0}, 10000); - } - } /* * Don't bother handling the NPC if another has already been handled. */ |