diff options
-rw-r--r-- | include/UIClass.h | 2 | ||||
-rw-r--r-- | include/World.h | 4 | ||||
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | include/entities.h | 2 | ||||
-rw-r--r-- | src/UIClass.cpp | 23 | ||||
-rw-r--r-- | src/entities.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 53 |
7 files changed, 62 insertions, 26 deletions
diff --git a/include/UIClass.h b/include/UIClass.h index 745dec3..867044e 100644 --- a/include/UIClass.h +++ b/include/UIClass.h @@ -13,6 +13,6 @@ namespace ui { void putString(const float x,const float y,const char *s);
void msgBox(const char *str,...);
void handleEvents();
-}
+};
#endif // UICLASS_H
diff --git a/include/World.h b/include/World.h index f6ddbfe..7d9224e 100644 --- a/include/World.h +++ b/include/World.h @@ -4,7 +4,7 @@ #include <common.h>
// Total amount of entities that can be bound to a layer
-#define MAX_ENTITIES 16
+#define MAX_ENTITIES 32
// Easy shortcuts used in UIClass
#define goWorldLeft(w) if(w->toLeft){w=w->toLeft;}
@@ -31,4 +31,4 @@ public: void addEntity(void *e); // Adds (binds) an entity to the world
};
-#endif // WORLD_H +#endif // WORLD_H
diff --git a/include/common.h b/include/common.h index 290e47a..bddb1b3 100644 --- a/include/common.h +++ b/include/common.h @@ -7,6 +7,7 @@ typedef struct{float x; float y;}vec2; #include <iostream> #include <cstdlib> +#include <math.h> #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> #include <SDL2/SDL_opengl.h> diff --git a/include/entities.h b/include/entities.h index 7d5e356..bc277cd 100644 --- a/include/entities.h +++ b/include/entities.h @@ -16,6 +16,8 @@ public: bool right,left, canMove; bool alive; + unsigned int texture[]; + void spawn(float, float); void draw(void); void wander(int, vec2*); diff --git a/src/UIClass.cpp b/src/UIClass.cpp index 86a7be6..94aa09c 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -13,6 +13,7 @@ static unsigned int fontSize; namespace ui { int mousex, mousey; + bool debug = false; void init(const char *ttf){ if(FT_Init_FreeType(&ftl)){ @@ -133,6 +134,14 @@ namespace ui { player.vel.y += .003; } } + 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; + } + } + break; if(e.key.keysym.sym == SDLK_i){ if(currentWorld->behind){ thing=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; @@ -144,14 +153,11 @@ namespace ui { } } } - 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; - } - } - break; + } + 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; @@ -163,5 +169,6 @@ namespace ui { break; } } + } } diff --git a/src/entities.cpp b/src/entities.cpp index 896e02d..7275af1 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -51,7 +51,8 @@ NPC::NPC(){ } void NPC::interact(){ - + loc.y += .01; + } Structures::Structures(){ diff --git a/src/main.cpp b/src/main.cpp index e48a66a..3b525d5 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, @@ -93,11 +94,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,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); @@ -188,11 +192,21 @@ void render(){ **** CLOSE THE LOOP **** **************************/ - //DRAW MOUSE HERE!!!!!W - glColor3ub(255,0,0); - 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; + //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); @@ -236,15 +250,26 @@ void logic(){ } 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); + } + } + /*for(int i = 0; i < 32; i++){ if(entnpc[i]->alive){ currentWorld->detect(&entnpc[i]->loc,&entnpc[i]->vel,entnpc[i]->width); std::cout<<(void *)entnpc[i]<<" "<<i<<" "<<entnpc<<" "<<eAmt(entnpc)<<std::endl; entnpc[i]->wander(30, &entnpc[i]->vel); + } - }*/ - ////////////////////// - std::cout<<"shit"; + } + */ tickCount++; } |