From a9781681bb8f3277ac310fbec8dc0353972dbc37 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 1 Oct 2015 09:19:52 -0400 Subject: improved gravity --- Bugs | 2 +- Changelog | 2 ++ src/entities.cpp | 29 +++++++++++++++++++++-------- src/main.cpp | 1 + src/world.cpp | 10 +++------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Bugs b/Bugs index 1b4a683..2a19fbc 100644 --- a/Bugs +++ b/Bugs @@ -11,4 +11,4 @@ Minor bugs: Maybe bugs: =========== - - Player is generated a random name (9/30/15) + - diff --git a/Changelog b/Changelog index 0ecb80c..fb9e42b 100644 --- a/Changelog +++ b/Changelog @@ -62,3 +62,5 @@ ========== - player can now complete assigned requests + - player's name is displayed + - improved gravity so entities don't shake on the ground diff --git a/src/entities.cpp b/src/entities.cpp index e7ba599..9d7ce95 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,4 +1,5 @@ #include +#include extern std::vectorentity; extern std::vectornpc; @@ -29,6 +30,10 @@ void Entity::draw(void){ //draws the entities glColor3ub(100,0,100); } glRectf(loc.x,loc.y,loc.x+width,loc.y+height); + if(near){ + ui::setFontSize(14); + ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name); + } } void Entity::wander(int timeRun, vec2 *v){ //this makes the entites wander about @@ -45,24 +50,31 @@ void Entity::wander(int timeRun, vec2 *v){ //this makes the entites wander about void Entity::getName(){ rewind(names); - char buf; - char* bufs = (char*)malloc(16); - int max = 0; - int tempNum = rand()%105; + char buf,*bufs = (char *)malloc(16); + int tempNum,max = 0; + for(;!feof(names);max++){ + fgets(bufs,16,(FILE*)names); + } + tempNum = rand()%max; + rewind(names); for(int i=0;idraw(&player->loc); // Draw the world around the player glColor3ub(0,0,0); + player->near=true; player->draw(); // Draw the player if(ui::debug){ diff --git a/src/world.cpp b/src/world.cpp index 5ba2e7d..d2cd380 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -117,10 +117,6 @@ LOOP2: // Draw each world for(i=0;iinWorld==this){ entity[i]->draw(); - if(entity[i]->near){ - ui::setFontSize(14); - ui::putText(entity[i]->loc.x,entity[i]->loc.y-ui::fontSize-HLINE/2,"%s",entity[i]->name); - } } } } @@ -130,7 +126,7 @@ void World::singleDetect(Entity *e){ unsigned int i; if(e->alive){ i=(e->loc.x+e->width/2-x_start)/HLINE; // Calculate what line the player is currently on - if(e->loc.y>line[i].y){ // Snap the player to the top of that line if the player is inside it + if(e->loc.y>line[i].y-.002*deltaTime){ // Snap the player to the top of that line if the player is inside it for(i=0;iloc.x+e->width>platform[i].p1.x)&(e->loc.x+e->widthloc.xloc.x>platform[i].p1.x))){ @@ -145,10 +141,10 @@ void World::singleDetect(Entity *e){ } } e->vel.y-=.001*deltaTime; - }else{ + }else if(e->loc.yvel.y=0; e->ground=true; - e->loc.y=line[i].y+HLINE/2; + e->loc.y=line[i].y-.001*deltaTime; } if(e->loc.xvel.x=0; -- cgit v1.2.3