]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
improved gravity
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Oct 2015 13:19:52 +0000 (09:19 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Oct 2015 13:19:52 +0000 (09:19 -0400)
Bugs
Changelog
src/entities.cpp
src/main.cpp
src/world.cpp

diff --git a/Bugs b/Bugs
index 1b4a683644b4da7f7f3f1a462173bb28dee7a9d9..2a19fbc221f3beb488473100e94fbf4d81ef6d73 100644 (file)
--- a/Bugs
+++ b/Bugs
@@ -11,4 +11,4 @@ Minor bugs:
 Maybe bugs:
 ===========
 
-       - Player is generated a random name (9/30/15)
+       - 
index 0ecb80c865d026d15ae6324f62975256c768ebc8..fb9e42b749fdaa9830315cbaada084b2603cb34a 100644 (file)
--- 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
index e7ba599eb0bed0091103726b56d3b74f527b3256..9d7ce95ddb863587c0144614b0400eb461b431c0 100644 (file)
@@ -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
index ea579981e2f272c63ce61b5fc5e2f257c37bcbf0..53eaa16586f475a5ec2ce2a0d7b7ac41754e8990 100644 (file)
@@ -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){
index 5ba2e7d37c1516aa7ee93a62e485d11984987ccd..d2cd3801cdc2ef91a96da67e3d5b3c928e0734e6 100644 (file)
@@ -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;