]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Updated village spawning with fixes to other things
authorAndy Belle-Isle <abelleisle@roadrunner.com>
Sun, 13 Sep 2015 01:17:12 +0000 (21:17 -0400)
committerAndy Belle-Isle <abelleisle@roadrunner.com>
Sun, 13 Sep 2015 01:17:12 +0000 (21:17 -0400)
include/entities.h
src/UIClass.cpp
src/entities.cpp
src/main.cpp

index 7cd657a11efa1fdcc031aff77cb62544966da272..752908bfc0391352d5c2dcbaea88e3aab41e4cbc 100644 (file)
@@ -8,7 +8,7 @@ public:
        float width;
        float height;
        float speed;
-       int type;
+       int type, subtype;
        vec2 loc;
        vec2 vel;
        bool right,left;
@@ -20,7 +20,6 @@ public:
 class Player : public Entity{
 public:
        Player();
-       ~Player();
 };
 
 class NPC : public Entity{
@@ -28,4 +27,13 @@ public:
        NPC();
 };
 
+extern Entity *entnpc[10];     //The NPC base
+extern NPC npc[10];
+
+class Structures : public Entity{
+public:
+       Structures();
+       void spawn(int, float, float);
+};
+
 #endif // ENTITIES_H
index 3f3a91a645267909d3c8946a00c4ba8c29261c66..18e273e8f544b312b6c5e6b675a00ae4193b45dc 100644 (file)
@@ -16,6 +16,7 @@ void UIClass::handleEvents(){
                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){
                                player.loc.y += HLINE*1.2;
                                player.vel.y += .004;
@@ -38,6 +39,8 @@ void UIClass::handleEvents(){
                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_ESCAPE) gameRunning = false;
                        break;
                }       
index 19ac536f185b0de5baf3d184ead19df0155a5e97..849bd7ce7e831877f607ae33f07a9e83695cf7c8 100644 (file)
@@ -8,6 +8,7 @@ void Entity::spawn(float x, float y){
        right = false;
        left = false;
 }
+
 void Entity::draw(void){
        glColor3ub(0,0,100);
        glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
@@ -18,10 +19,7 @@ Player::Player(){
        height = HLINE * 18;
        speed = 1;
        type = 0;
-}
-
-Player::~Player(){
-
+       subtype = 5;
 }
 
 NPC::NPC(){
@@ -29,4 +27,28 @@ NPC::NPC(){
        height = HLINE * 18;
        speed = 1;
        type = 0;
+       subtype = 0;
+}
+
+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;
+
+               for(int i = 0;i<10;i++){
+                       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
+               }
+       }
 }
index a9e5179b2fd39c1c0835a692bce0fcc9fb76736d..4e431052de8d443d0e18d08e9ed9635171f47722 100644 (file)
@@ -16,18 +16,22 @@ static unsigned int tickCount   = 0,
                                        currentTime = 0,
                                        deltaTime   = 0;
 
-Entity  *entPlay;         //The player base
-Entity  *entnpc;          //The NPC base
-Player  player;                   //The actual player object
-NPC     npc;              // A test NPC
-UIClass ui;                       // Handles the user interface
-World   *currentWorld; // Points to the current 'world' the player is in
-
-float interpolate(float goal, float current, float dt){
-       float difference=goal-current;
-       if(difference>dt)return current+dt;
-       if(difference<dt)return current-dt;
-       return goal;
+Entity *entPlay;       //The player base
+Entity *entnpc[10];    //The NPC base
+Player player;         //The actual player object
+NPC npc[10];
+Structures build;
+UIClass ui;                    //Yep
+World *currentWorld;//u-huh
+
+//static int randNext=1;
+
+void irand(unsigned int seed){
+       srand(seed);
+}
+
+int grand(void){
+       return rand();
 }
 
 void logic();
@@ -77,9 +81,9 @@ int main(int argc,char **argv){
 
        entPlay = &player;
        entPlay->spawn(0, 0);
-       entnpc = &npc;
-       npc.type = -1;                                           //this will make the NPC spawn the start of a village
-       entnpc->spawn(.5,0);// (grand()%20)-10 ,0); //this will spawn the start of a village
+
+       build.spawn(-1, (grand()%20)-10, 0);
+
 
        // Generate the world
        World *w=NULL,*w2=NULL;
@@ -88,7 +92,7 @@ int main(int argc,char **argv){
        
        currentWorld=w;
        currentWorld->addLayer(3);
-       currentWorld->addEntity((void *)entnpc);
+       //currentWorld->addEntity((void *)entnpc);
 
        float gw;
        
@@ -102,10 +106,9 @@ int main(int argc,char **argv){
                        prevTime = SDL_GetTicks();
                }
 
-               player.loc.x += player.vel.x*deltaTime;                                         //update the player's x based on 
-               player.loc.y += player.vel.y*deltaTime;
+               player.loc.x += (player.vel.x * player.speed) * deltaTime;                                              //update the player's x based on 
+               player.loc.y += player.vel.y * deltaTime;
                
-               npc.loc.y += npc.vel.y*deltaTime;
 
                gw=currentWorld->getWidth();
                if(player.loc.x+player.width>-1+gw){
@@ -168,14 +171,15 @@ void render(){
                glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height);
 
                ///TEMP NPC RENDER!!!!!!
-               /*glColor3ub(98, 78, 44);                                                       //render the NPC(s)
-               glRectf(npc.loc.x, npc.loc.y, npc.loc.x + .25, npc.loc.y + .25);
-               glColor3ub(83, 49, 24);
-               glBegin(GL_TRIANGLES);
-                       glVertex2f(npc.loc.x, npc.loc.y + .25);
-                       glVertex2f(npc.loc.x + .25, npc.loc.y + .25);
-                       glVertex2f(npc.loc.x + .125, npc.loc.y + .35);
-               glEnd();*/
+               for(int i = 0; i < 10; i++){
+                       npc[i].loc.y += npc[i].vel.y*deltaTime;
+
+                       glColor3ub(98, 78, 44);                                                 //render the NPC(s)
+                       glRectf(npc[i].loc.x, npc[i].loc.y, npc[i].loc.x + npc[i].width, npc[i].loc.y + npc[i].height);
+                       glEnd();
+           }
+           glColor3ub(255,0,0);
+               glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height);
                ///BWAHHHHHHHHHHHH
                
                /**************************
@@ -189,14 +193,19 @@ void render(){
 void logic(){
        ui.handleEvents();                                                              // Handle events
 
-       if(player.right == true) {player.vel.x = .002;}
-       if(player.left == true) {player.vel.x = -.002;}
+       if(player.right == true) {player.vel.x = .00075;}
+       if(player.left == true) {player.vel.x = -.00075;}
        if(player.right == false && player.left == false) {player.vel.x = 0;}
 
-       std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")";
+       std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")"<<std::endl;
+
 
        currentWorld->detect(&player.loc,&player.vel,player.width);
-       currentWorld->detect(&npc.loc,&player.vel,npc.height);
+
+       currentWorld->detect(&build.loc,&build.vel,build.width);
+       for(int i = 0; i < 10; i++){
+               currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width);
+       }
 
        tickCount++;
 }