diff options
author | Andy Belle-Isle <abelleisle@roadrunner.com> | 2015-09-16 11:48:48 -0400 |
---|---|---|
committer | Andy Belle-Isle <abelleisle@roadrunner.com> | 2015-09-16 11:48:48 -0400 |
commit | 82d5e77a3fa4f3f9cc3145969d99ba8326af9892 (patch) | |
tree | 6c6385fced0b42b95e51e7935a4677058442fe5f /src | |
parent | c5d48afdbfb7451581a8f61fe24a606b15415224 (diff) |
Fixed mouse, and debug
Diffstat (limited to 'src')
-rw-r--r-- | src/UIClass.cpp | 3 | ||||
-rw-r--r-- | src/World.cpp | 1 | ||||
-rw-r--r-- | src/entities.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 37 |
4 files changed, 35 insertions, 9 deletions
diff --git a/src/UIClass.cpp b/src/UIClass.cpp index 0497575..0ee56ca 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -144,6 +144,9 @@ void UIClass::handleEvents(){ 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; diff --git a/src/World.cpp b/src/World.cpp index bde35de..4237d42 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -24,6 +24,7 @@ World::World(const float width,World *l,World *r){ 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;
diff --git a/src/entities.cpp b/src/entities.cpp index b418534..ee909d8 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -50,7 +50,8 @@ NPC::NPC(){ } void NPC::interact(){ - + loc.y += .01; + } Structures::Structures(){ diff --git a/src/main.cpp b/src/main.cpp index 1843f4a..cad8fc9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ SDL_Surface *renderSurface = NULL; SDL_GLContext mainGLContext = NULL; bool gameRunning = true; +static float mx,my; static unsigned int tickCount = 0, prevTime = 0, @@ -94,11 +95,11 @@ int main(int argc,char **argv){ // Generate the world World *w=NULL,*w2=NULL; w2=new World(4,w,NULL); - w=new World(10,NULL,w2); + w=new World(20,NULL,w2); spawn=currentWorld=w; - currentWorld->addLayer(3); - currentWorld->addLayer(4); + currentWorld->addLayer(15); + currentWorld->addLayer(10); // shh unsigned char jklasdf; for(jklasdf=0;jklasdf<npcAmt;jklasdf++){ @@ -139,7 +140,6 @@ int main(int argc,char **argv){ } void render(){ - static float mx,my; 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" @@ -166,7 +166,12 @@ void render(){ **** RENDER STUFF HERE **** **************************/ currentWorld->draw(); // layers dont scale x correctly... - glColor3ub(120,30,30); //render the player + + 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); @@ -180,7 +185,6 @@ void render(){ d=deltaTime; fps=(1000/d); } - ui.putText(-.98 + player.loc.x, .94, "FPS: %1.0f\nDT: %1.0f",fps); //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); @@ -188,10 +192,21 @@ void render(){ **** CLOSE THE LOOP **** **************************/ - //DRAW MOUSE HERE!!!!!W + //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)mx+=player.loc.x; + 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); @@ -238,6 +253,12 @@ void logic(){ 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++; |