diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Quest.cpp | 62 | ||||
-rw-r--r-- | src/UIClass.cpp | 169 | ||||
-rw-r--r-- | src/World.cpp | 141 | ||||
-rw-r--r-- | src/entities.cpp | 83 | ||||
-rw-r--r-- | src/main.cpp | 177 |
5 files changed, 13 insertions, 619 deletions
diff --git a/src/Quest.cpp b/src/Quest.cpp deleted file mode 100644 index a42e42c..0000000 --- a/src/Quest.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include <Quest.h>
-
-const Quest QuestList[TOTAL_QUESTS]={
- Quest("Test","A test quest",0)
-};
-
-Quest::Quest(const char *t,const char *d,unsigned int x){
- size_t len;
- title=(char *)malloc((len=strlen(t)));
- strncpy(title,t,len);
- desc=(char *)malloc((len=strlen(d)));
- strncpy(desc,d,len);
- xp=x;
-}
-Quest::~Quest(){
- free(title);
- free(desc);
- xp=0;
-}
-
-QuestHandler::QuestHandler(){
- ccnt=0;
-}
-int QuestHandler::assign(const char *t){
- unsigned int i=0;
- if(ccnt==QUEST_LIMIT)
- return -1;
- for(;i<TOTAL_QUESTS;i++){
- if(!strcmp(QuestList[i].title,t)){
- current[ccnt++]=&QuestList[i];
- return ccnt;
- }
- }
- return -1;
-}
-int QuestHandler::drop(const char *t){
- unsigned char i=0;
- for(;i<ccnt;i++){
- if(!strcmp(current[i]->title,t)){
- for(i++;i<ccnt;i++){
- current[i-1]=current[i];
- }
- return (--ccnt);
- }
- }
- return -1;
-}
-int QuestHandler::finish(const char *t){
- unsigned char i=0;
- unsigned int j;
- for(;i<ccnt;i++){
- if(!strcmp(current[i]->title,t)){
- j=current[i]->xp;
- for(i++;i<ccnt;i++){
- current[i-1]=current[i];
- }
- ccnt--;
- return j;
- }
- }
- return -1;
-}
diff --git a/src/UIClass.cpp b/src/UIClass.cpp deleted file mode 100644 index eec7bec..0000000 --- a/src/UIClass.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include <UIClass.h> -#include <ft2build.h> -#include FT_FREETYPE_H - -extern Player player; -extern World *currentWorld; - -static FT_Library ftl; -static FT_Face ftf; -static GLuint ftex; -static unsigned int fontSize; - -namespace ui { - int mousex, mousey; - bool debug = false; - - void init(const char *ttf){ - if(FT_Init_FreeType(&ftl)){ - std::cout<<"Error! Couldn't initialize freetype."<<std::endl; - abort(); - } - if(FT_New_Face(ftl,ttf,0,&ftf)){ - std::cout<<"Error! Couldn't open "<<ttf<<"."<<std::endl; - abort(); - } - } - void setFontSize(unsigned int fs){ - fontSize=fs; - FT_Set_Pixel_Sizes(ftf,0,fontSize); - } - void putString(const float x,const float y,const char *s){ - unsigned int i=0,j; - float xo=x,yo=y,w,h; - char *buf; - do{ - if(s[i]=='\n'){ - xo=x; - yo-=fontSize*.0022; - }else{ - if(FT_Load_Char(ftf,s[i],FT_LOAD_RENDER)){ - std::cout<<"Error! Invalid character."<<std::endl; - return; - } - //glActiveTexture(GL_TEXTURE0); - glGenTextures(1,&ftex); - glBindTexture(GL_TEXTURE_2D,ftex); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - buf=(char *)malloc(ftf->glyph->bitmap.width*ftf->glyph->bitmap.rows*4); - for(j=0;j<ftf->glyph->bitmap.width*ftf->glyph->bitmap.rows;j++){ - buf[j*4]=255; - buf[j*4+1]=255; - buf[j*4+2]=255; - buf[j*4+3]=ftf->glyph->bitmap.buffer[j]?255:0; - } - glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf); - w=ftf->glyph->bitmap.width*(2.0/SCREEN_WIDTH); - h=ftf->glyph->bitmap.rows *(2.0/SCREEN_HEIGHT); - if(s[i]=='\''|| - s[i]=='\"'|| - s[i]=='-'|| - s[i]=='*'){ - yo+=fontSize*.001; - } - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D,ftex); - glBegin(GL_QUADS); - glColor3ub(255,255,255); - glTexCoord2f(0,1);glVertex2f(xo,yo); - glTexCoord2f(1,1);glVertex2f(xo+w,yo); - glTexCoord2f(1,0);glVertex2f(xo+w,yo+h); - glTexCoord2f(0,0);glVertex2f(xo,yo+h); - glEnd(); - glDisable(GL_TEXTURE_2D); - if(s[i]=='\''|| - s[i]=='\"'|| - s[i]=='-'|| - s[i]=='*'){ - yo-=fontSize*.001; - } - xo+=w+(fontSize*.0002); - free(buf); - } - }while(s[i++]); - } - void putText(const float x,const float y,const char *str,...){ - va_list args; - char *buf; - buf=(char *)calloc(128,sizeof(char)); - va_start(args,str); - vsnprintf(buf,128,str,args); - va_end(args); - putString(x,y,buf); - free(buf); - } - void msgBox(const char *str,...){ - va_list args; - va_start(args,str); - glColor3ub(0,0,0); - glRectf(-1,.6,1,1); - setFontSize(24); - putText(-1,1-24*.0022,str,args); - va_end(args); - } - - void handleEvents(){ - static bool space=false; - float thing; - SDL_Event e; - while(SDL_PollEvent(&e)){ - switch(e.type){ - case SDL_MOUSEMOTION: - mousex=e.motion.x; - mousey=e.motion.y; - break; - case SDL_WINDOWEVENT: - switch(e.window.event){ - case SDL_WINDOWEVENT_CLOSE: - gameRunning = false; - break; - } - case SDL_KEYDOWN: - if(e.key.keysym.sym == SDLK_d) player.right = true; - if(e.key.keysym.sym == SDLK_a) player.left = true; - if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 3; - if(e.key.keysym.sym == SDLK_SPACE){ - if(!space&&player.vel.y<=0){ - space=true; - player.loc.y += HLINE*1.2; - player.vel.y += .003; - } - } - if(e.key.keysym.sym == SDLK_i){ - if(currentWorld->behind){ - thing=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; - if(player.loc.x>thing-1&& - player.loc.x<thing-1+currentWorld->behind->getWidth()){ - player.loc.x-=thing; - memset(&player.vel,0,sizeof(vec2)); - currentWorld=currentWorld->behind; - } - } - } - if(e.key.keysym.sym == SDLK_k){ - if(currentWorld->infront){ - player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; - memset(&player.vel,0,sizeof(vec2)); - currentWorld=currentWorld->infront; - } - } - if(e.key.keysym.sym == SDLK_F3){ - debug = !debug; - } - break; - case SDL_KEYUP: - if(e.key.keysym.sym == SDLK_d) player.right = false; - if(e.key.keysym.sym == SDLK_a) player.left = false; - if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 1.0; - if(e.key.keysym.sym == SDLK_SPACE) - if(player.vel.y<=.001)space=false; - if(e.key.keysym.sym == SDLK_ESCAPE) gameRunning = false; - break; - } - } - } -}
\ No newline at end of file diff --git a/src/World.cpp b/src/World.cpp deleted file mode 100644 index 49bdf0d..0000000 --- a/src/World.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include <World.h>
-#include <cstdio>
-
-// Layer modulation in draw()
-static float drawOffsetX=0,
- drawOffsetY=0;
-
-// Generates a blank world
-World::World(void){
- line=NULL;
- lineCount=entCount=0;
- toLeft=toRight=behind=infront=NULL;
-}
-// Generates a legit world
-World::World(const float width,World *l,World *r){
- unsigned int i;
- double f;
- lineCount=width/HLINE+11; // Last 10 lines won't be drawn
- if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){ // Allocate buffer for lines
- std::cout<<"Failed to allocate memory!"<<std::endl;
- abort();
- }
- toLeft=l; // Set other variables
- toRight=r;
- behind=infront=NULL;
- entCount=0;
- entity=(void **)calloc(MAX_ENTITIES,sizeof(void *));
- if(toLeft){ // Make sure linked worlds link back
- if(toLeft->toRight){
- std::cout<<"There's already a world to the left!"<<std::endl;
- abort();
- }else toLeft->toRight=this;
- }
- if(toRight){
- if(toRight->toLeft){
- std::cout<<"There's already a world to the right!"<<std::endl;
- abort();
- }else toRight->toLeft=this;
- }
- line[0].start=(grand()%100)/100.0f-0.8f; // Set .start of first line
- if(line[0].start>-0.5f)line[0].start=-0.7f; // Don't let the ground take up too much of the window
- for(i=10;i<lineCount;i+=10){ // Set heights for every 10 lines
- line[i].start=((double)((grand()%50)+400))/1000.0f-1;
- }
- for(i=0;i<lineCount;i++){ // Set heights for other lines based on those
- if(!(i%10)||!i){
- f=line[i+10].start-line[i].start; // 1/10th of difference between the two heights
- f/=10.0f;
- }else{
- line[i].start=line[i-1].start+f;
- }
- line[i].color=(grand()%2)*10+130;
- }
-}
-// Set RGB color with potentially not 8-bit values
-void safeSetColor(int r,int g,int b){
- if(r>255)r=255;else if(r<0)r=0;
- if(g>255)g=255;else if(g<0)g=0;
- if(b>255)b=255;else if(b<0)b=0;
- glColor3ub(r,g,b);
-}
-void World::draw(void){
- unsigned int i;
- float x,y,hline=HLINE;
- World *root,*cur;
- int shade;
- root=cur=this;
-LOOP:
- if(cur->behind){ // If there's a layer behind us,
- drawOffsetX+=(cur->getWidth()-cur->behind->getWidth())/2; // set drawOffsetX so that it will be centered behind this one
- drawOffsetY+=.3; // Push it back a bit for depth-feel
- //hline/=2;
- cur=cur->behind; // Go back one
- goto LOOP; // loop
- }
-LOOP2: // Should be in furthest back layer once this is first reached
- shade=30*(drawOffsetY/.3); // Trash shaders
- glBegin(GL_QUADS);
- for(i=0;i<cur->lineCount-10;i++){ // Draw the layer
- x=(hline*i)-1+drawOffsetX; // Pre-calculate x for 'optimization'
- y=cur->line[i].start+drawOffsetY; // same, but y
- safeSetColor(0,200+shade,0); // Set shaded green for grass
- glVertex2f(x ,y); // Doodle
- glVertex2f(x+hline,y);
- y-=hline*2; // 'optimization'
- glVertex2f(x+hline,y);
- glVertex2f(x ,y);
- safeSetColor(line[i].color+shade,line[i].color-50+shade,line[i].color-100+shade); // Set shaded brown for dirt
- glVertex2f(x ,y);
- glVertex2f(x+hline,y);
- glVertex2f(x+hline,-1);
- glVertex2f(x ,-1);
- }
- glEnd();
- if(root!=cur){ // If we're still in one of the behinds
- cur=cur->infront; // Move one closer
- drawOffsetX-=(cur->getWidth()-cur->behind->getWidth())/2; // Take off last layer's centering
- drawOffsetY-=.3; // And back-pushing
- //hline*=2;
- goto LOOP2; // Loop the draw
- }else{
- drawOffsetX=drawOffsetY=0; // Reset for next draw() call
- for(i=0;i<entCount;i++){ // Draw any bound entities
- if(entity[i])
- ((Entity **)entity)[i]->draw();
- }
- }
-}
-extern World *spawn;
-void World::detect(vec2 *v,vec2 *vel,const float width){
- unsigned int i;
- for(i=0;i<lineCount-10;i++){ // For every line in world
- if(v->y<line[i].start){ // If we're inside the line
- if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){ // And we're inside it ;)
- vel->y=0;v->y=line[i].start+HLINE/8; // Correct
- return; // :/
- }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ // Same as above, but coming from right side instead of left
- vel->y=0;v->y=line[i].start+HLINE/8;
- return; // ;)
- }
- }
- if(v->y>line[i].start+HLINE){ // Trashy gravity handling
- vel->y-=this==spawn?.0000001:.0000003;
- }
- }
-}
-// Calculate the world's width in coordinates
-float World::getWidth(void){
- return (lineCount-11)*HLINE;
-}
-void World::addLayer(const float width){
- if(behind){ // If there's already a layer behind us
- behind->addLayer(width); // Add it back there
- }else{
- behind=new World(width,NULL,NULL); // Otherwise add it directly behind us
- behind->infront=this;
- }
-}
-void World::addEntity(void *addr){
- entity[entCount++]=addr;
-}
diff --git a/src/entities.cpp b/src/entities.cpp deleted file mode 100644 index 7275af1..0000000 --- a/src/entities.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include <entities.h> - -void Entity::spawn(float x, float y){ - loc.x = x; - loc.y = y; - vel.x = 0; - vel.y = 0; - right = false; - left = false; - ticksToUse = 0; - canMove = false; -} - -void Entity::draw(void){ - glColor3ub(0,0,100); - glRectf(loc.x,loc.y,loc.x+width,loc.y+height); -} - -void Entity::wander(int timeRun, vec2 *v){ - static int hey; - if(ticksToUse == 0){ - ticksToUse = timeRun; - v->x = .00010; - hey = (grand() % 3 - 1); - v->x *= hey; - } - ticksToUse--; -} - -Player::Player(){ - width = HLINE * 8; - height = HLINE * 18; - speed = 1; - type = 0; - subtype = 5; - alive = true; -} - -void Player::interact(){ - -} - -NPC::NPC(){ - width = HLINE * 8; - height = HLINE * 18; - speed = 1; - type = 0; - subtype = 0; - alive = false; - canMove = true; -} - -void NPC::interact(){ - loc.y += .01; - -} - -Structures::Structures(){ - type = -1; - speed = 0; -} - -void Structures::spawn(int t, float x, float y){ - loc.x = x; - loc.y = y; - type = t; - - /*VILLAGE*/ - if(type == -1){ - width = 4 * HLINE; - height = 4 * HLINE; - - int tempN = (grand() % 5 + 1); - npcAmt = tempN; - - for(int i = 0;i<eAmt(entnpc);i++){ - npc[i].alive = true; - entnpc[i] = &npc[i]; - npc[i].type = -1; //this will make the NPC spawn the start of a village - entnpc[i]->spawn(loc.x + (float)(i - 5) / 8,0); //this will spawn the start of a village - } - } -} diff --git a/src/main.cpp b/src/main.cpp index a60d52c..8c78eab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,30 +2,11 @@ #include <cstdio> #include <chrono> -#define TICKS_PER_SEC 20 -#define MSEC_PER_TICK (1000/TICKS_PER_SEC) - SDL_Window *window = NULL; SDL_Surface *renderSurface = NULL; SDL_GLContext mainGLContext = NULL; bool gameRunning = true; -static float mx,my; - -static unsigned int tickCount = 0, - prevTime = 0, - currentTime = 0, - deltaTime = 0; - -int npcAmt = 0; -Entity *entPlay; //The player base -Entity *entnpc[32]; //The NPC base -Player player; //The actual player object -NPC npc[32]; -Structures build; -World *currentWorld;//u-huh - -World *spawn; void logic(); void render(); @@ -49,9 +30,6 @@ int main(int argc, char *argv[]){ atexit(IMG_Quit); //Turn on double Buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - //ANTIALIASING!!! - //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16); //create the window window = SDL_CreateWindow("Independent Study v.0.2 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL #ifdef FULLSCREEN @@ -73,7 +51,6 @@ int main(int argc, char *argv[]){ glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT); glClearColor(.3,.5,.8,0); glEnable(GL_BLEND); - glEnable(GL_MULTISAMPLE); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); SDL_ShowCursor(SDL_DISABLE); @@ -81,52 +58,9 @@ int main(int argc, char *argv[]){ **** GAMELOOP **** **************************/ - ui::init("ttf/VCR_OSD_MONO_1.001.ttf"); - - irand(time(NULL)); - entPlay = &player; - entPlay->spawn(0, 0); - - build.spawn(-1, (grand()%20)-10, 0); - //build.spawn(-1, 1.5, 0); - - - // Generate the world - World *w=NULL,*w2=NULL; - w2=new World(4,w,NULL); - w=new World(20,NULL,w2); - - spawn=currentWorld=w; - currentWorld->addLayer(15); - currentWorld->addLayer(10); - // shh - unsigned char jklasdf; - for(jklasdf=0;jklasdf<npcAmt;jklasdf++){ - currentWorld->addEntity((void *)entnpc[jklasdf]); - } - - currentTime=millis(); - while(gameRunning){ - prevTime = currentTime; - currentTime = millis(); - deltaTime = currentTime - prevTime; - - player.loc.x += (player.vel.x * player.speed) * deltaTime; //update the player's x based on - player.loc.y += player.vel.y * deltaTime; - for(int i = 0; i < eAmt(entnpc); i++){ - if(npc[i].alive == true){ - npc[i].loc.y += npc[i].vel.y * deltaTime; - npc[i].loc.x += npc[i].vel.x * deltaTime; - } - } - render(); - - if(prevTime + MSEC_PER_TICK >= millis()){ //the logic loop to run at a dedicated time - logic(); - prevTime = millis(); - } + logic(); } /************************** @@ -140,22 +74,13 @@ int main(int argc, char *argv[]){ } void render(){ - static float d,fps; - static unsigned int div=0; //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" //GL_PROJECTION has 2 matrices //GL_MODELVIEW has 32 matrices glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on glPushMatrix(); //push the matrix to the top of the matrix stack glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode - //set the the size of the screen - if(player.loc.x-1<-1){ - glOrtho(-1,1, -1,1, -1,1); - }else if(player.loc.x+1>-1+currentWorld->getWidth()){ - glOrtho(-3+currentWorld->getWidth(),-1+currentWorld->getWidth(),-1,1,-1,1); - }else{ - glOrtho(-1 + player.loc.x, 1 + player.loc.x , -1, 1, -1,1); - } + glOrtho(0,SCREEN_WIDTH,0,SCREEN_HEIGHT,-1,1); glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects glPushMatrix(); //push the matrix to the top of the matrix stack glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode @@ -165,103 +90,27 @@ void render(){ /************************** **** RENDER STUFF HERE **** **************************/ - currentWorld->draw(); // layers dont scale x correctly... - - if((mx > player.loc.x && mx < player.loc.x + player.width) && (my > player.loc.y && my < player.loc.y + player.height)){ - glColor3ub(255,0,0); - }else{ - glColor3ub(120,30,30); //render the player - } - glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); - - glColor3ub(255,0,0); - glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height); - ///BWAHHHHHHHHHHHH - - ui::setFontSize(16); - if(++div==20){ - div=0; - d=deltaTime; - fps=(1000/d); - } - //ui.putText(-.98 + player.loc.x, .88, "DT: %1.0f",d); - ui::putText(player.loc.x,player.loc.y-(HLINE*10),"(%+1.3f,%+1.3f)",player.loc.x,player.loc.y); - /************************** **** CLOSE THE LOOP **** **************************/ - //DRAW MOUSE HERE!!!!! - mx=(ui::mousex/(float)SCREEN_WIDTH)*2.0f-1.0f; - my=((SCREEN_HEIGHT-ui::mousey)/(float)SCREEN_HEIGHT)*2.0f-1.0f; - if(player.loc.x-1>-1 && player.loc.x-1<-3+currentWorld->getWidth()){ - if(ui::debug) - ui::putText(-.98 + player.loc.x, .94, "FPS: %1.0f\nDT: %1.0f",fps, d); - mx+=player.loc.x; - }else if(player.loc.x-1>=-3+currentWorld->getWidth()){ - if(ui::debug) - ui::putText(-.98 + -2+currentWorld->getWidth(), .94, "FPS: %1.0f\nDT: %1.0f",fps, d); - mx =mx-1 + -1+currentWorld->getWidth(); - }else{ - if(ui::debug) - ui::putText(-.98, .94, "FPS: %1.0f\nDT: %1.0f",fps, d); - } - - glBegin(GL_TRIANGLES); - - glColor3ub(255,255,255); - glVertex2f(mx,my); - glVertex2f(mx + (HLINE*3.5),my - (HLINE*1)); - glVertex2f(mx + (HLINE*1),my - (HLINE*6)); - - glEnd(); - glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer SDL_GL_SwapWindow(window); //give the stack to SDL to render it } void logic(){ - float gw; - - ui::handleEvents(); // Handle events - - if(player.right)player.vel.x=.00075; - else if(player.left)player.vel.x=-.00075; - else player.vel.x = 0; - - currentWorld->detect(&player.loc,&player.vel,player.width); - gw=currentWorld->getWidth(); - if(player.loc.x+player.width>-1+gw){ - if(currentWorld->toRight){ - goWorldRight(currentWorld) - player.loc.x=-1+HLINE; - }else{ - player.loc.x=gw-1-player.width-HLINE; - } - } - if(player.loc.x<-1){ - if(currentWorld->toLeft){ - goWorldLeft(currentWorld); - player.loc.x=currentWorld->getWidth()-1-player.width-HLINE; - }else{ - player.loc.x=-1+HLINE; + SDL_Event e; + while(SDL_PollEvent(&e)){ + switch(e.type){ + case SDL_QUIT: + gameRunning=false; + break; + case SDL_KEYDOWN: + if(e.key.keysym.sym==SDLK_ESCAPE)gameRunning=false; + break; + default: + break; } } - - currentWorld->detect(&build.loc,&build.vel,build.width); - for(int i = 0; i < eAmt(entnpc); i++){ - if(npc[i].alive == true){ - currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width); - entnpc[i]->wander((grand()%181 + 1), &npc[i].vel); - if((mx > entnpc[i]->loc.x && mx < entnpc[i]->loc.x + entnpc[i]->width) && (my > entnpc[i]->loc.y && my < entnpc[i]->loc.y + entnpc[i]->height)&&(SDL_GetMouseState(NULL,NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))){ - if(pow((entnpc[i]->loc.x - player.loc.x),2) + pow((entnpc[i]->loc.y - player.loc.y),2) < pow(.2,2)){ - entnpc[i]->interact(); - ui::putText(entnpc[i]->loc.x, entnpc[i]->loc.y - HLINE * 3, "HEY", NULL); - } - } - } - - } - tickCount++; } |