#include <entities.h>
+#include <ui.h>
extern std::vector<Entity*>entity;
extern std::vector<NPC>npc;
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
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);
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
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);
- }
}
}
}
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))){
}
}
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;