diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-01 09:19:52 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-01 09:19:52 -0400 |
commit | a9781681bb8f3277ac310fbec8dc0353972dbc37 (patch) | |
tree | 548ed837877d9d07802fc980f0ef6d6f62ae920c /src | |
parent | 68ec0bf510fd16cf4e6d7aabd7998fe656c25444 (diff) |
improved gravity
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 29 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/world.cpp | 10 |
3 files changed, 25 insertions, 15 deletions
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 <entities.h> +#include <ui.h> extern std::vector<Entity*>entity; extern std::vector<NPC>npc; @@ -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;i<tempNum;i++){ fgets(bufs,16,(FILE*)names); } - buf = fgetc(names); - if(buf == 'm'){ + switch(fgetc(names)){ + case 'm': gender = MALE; std::puts("Male"); - }else if(buf == 'f'){ + break; + case 'f': gender = FEMALE; std::puts("Female"); + break; + default: + break; } if((fgets(bufs,16,(FILE*)names)) != NULL){ std::puts(bufs); - bufs[strlen(bufs)-1] = 0; + bufs[strlen(bufs)-1] = '\0'; strcpy(name,bufs); } free(bufs); @@ -76,6 +88,7 @@ Player::Player(){ //sets all of the player specific traits on object creation subtype = 5; alive = true; ground = false; + near = true; } void Player::interact(){ //the function that will cause the player to search for things to interact with diff --git a/src/main.cpp b/src/main.cpp index ea57998..53eaa16 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,6 +140,7 @@ void render(){ currentWorld->draw(&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;i<entity.size()+1;i++){ if(entity[i]->inWorld==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;i<platform.size();i++){ if(((e->loc.x+e->width>platform[i].p1.x)&(e->loc.x+e->width<platform[i].p2.x))|| ((e->loc.x<platform[i].p2.x)&(e->loc.x>platform[i].p1.x))){ @@ -145,10 +141,10 @@ void World::singleDetect(Entity *e){ } } e->vel.y-=.001*deltaTime; - }else{ + }else if(e->loc.y<line[i].y){ e->vel.y=0; e->ground=true; - e->loc.y=line[i].y+HLINE/2; + e->loc.y=line[i].y-.001*deltaTime; } if(e->loc.x<x_start){ // Keep the player inside world bounds (ui.cpp handles world jumping) e->vel.x=0; |