]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
added dropping from platforms
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 28 Sep 2015 12:14:20 +0000 (08:14 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 28 Sep 2015 12:14:20 +0000 (08:14 -0400)
include/entities.h
src/entities.cpp
src/main.cpp
src/ui.cpp
src/world.cpp

index 6e0e2c3884e714e5e848bf8f3ed47c64a820c729..78d9a51039c68e45a4453934fe3993fcf9a4ed31 100644 (file)
@@ -14,7 +14,7 @@ public:
        vec2 vel;
        bool right,left, canMove;
        bool alive;
-       bool ground;
+       unsigned char ground;
 
        unsigned int texture[];
        
@@ -39,6 +39,7 @@ public:
 };
 class Structures : public Entity{
 public:
+       World *inside;
        Structures();
        unsigned int spawn(int, float, float);
 };
index da28851676e7085ea2a3c9dca4595d9355fbc5f6..140223d91eeeab4caa3361d0b2510cb35255c022 100644 (file)
@@ -50,9 +50,9 @@ NPC::NPC(){
        width = HLINE * 8;
        height = HLINE * 12;
        speed = 1;
-       type = 0;
+       type = 1;
        subtype = 0;
-       alive = false;
+       alive = true;
        canMove = true;
 }
 
@@ -78,13 +78,11 @@ unsigned int Structures::spawn(int t, float x, float y){
                //int tempN = (getRand() % 5 + 1);
                int tempN = 2;
                for(int i=0;i<tempN;i++){
-                       entity.push_back(new Entity());
+                       entity.push_back(new NPC());
                        npc.push_back(NPC());
                        std::cout<<"NPC:"<<npc.size()<<std::endl;
                        std::cout<<"Entity:"<<entity.size()<<std::endl;
                        entity[entity.size()] = &npc[npc.size()-1];
-                       entity[entity.size()]->alive=true;
-                       entity[entity.size()]->type = 1;
                        entity[entity.size()]->spawn(loc.x + (float)(i - 5) / 8,100);
                }
                return entity.size();
index 0ba715fa98d031224c2a259c818d5bb9f79dc6ba..9e029cf870db3a33e6953bfbe1499c7e69be7e2a 100644 (file)
@@ -173,7 +173,7 @@ void render(){
                        d=deltaTime;
                        debugDiv=0;
                }
-               ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d\nRes: %ux%u",fps,d,SCREEN_WIDTH,SCREEN_HEIGHT);
+               ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d G:%d\nRes: %ux%u",fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT);
        }
 
        ui::draw();                                                     // Draw any UI elements if they need to be
index 1e78dca49c1100a690098dfca1d2c9622aeb1dd0..75bc5ee15f62fe0694f01c913a82dae7d7dbbc28 100644 (file)
@@ -142,6 +142,10 @@ namespace ui {
                                        player->vel.x=.15;
                                        currentWorld=currentWorld->goWorldRight(player);
                                }
+                               if(SDL_KEY==SDLK_s && player->ground==2){
+                                       player->ground=false;
+                                       player->loc.y-=HLINE*1.5;
+                               }
                                if(SDL_KEY==SDLK_SPACE){                                                                                        // Jump
                                        if(player->ground){
                                                player->vel.y=.25;
index 14df3949a3a8c400d2c1ab9916909b07a289824d..a5a6f4ac44b344d41180792310f981326fcbe65d 100644 (file)
@@ -102,7 +102,7 @@ LOOP2:                                                                                                      // Draw each world
                }
        glEnd();
        for(i=0;i<entity.size()+1;i++){
-               if(entity[i]->inWorld==current){
+               if(entity[i]->inWorld==this){
                        entity[i]->draw();
                        ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i);
                }
@@ -127,11 +127,7 @@ void World::singleDetect(Entity *e){
        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
-                       e->vel.y=0;
-                       e->ground=true;
-                       e->loc.y=line[i].y+HLINE/2;
-               }else{                                                  // If the player is above the ground do some gravity stuff
+               if(e->loc.y>line[i].y){                         // 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))){
@@ -139,12 +135,17 @@ void World::singleDetect(Entity *e){
                                                if(e->vel.y<0){
                                                        e->vel.y=0;
                                                        e->loc.y=platform[i].p2.y;
-                                                       e->ground=true;
+                                                       e->ground=2;
+                                                       return;
                                                }
                                        }
                                }
                        }
                        e->vel.y-=.01;
+               }else{
+                       e->vel.y=0;
+                       e->ground=true;
+                       e->loc.y=line[i].y+HLINE/2;     
                }
                if(e->loc.x<x_start){                           // Keep the player inside world bounds (ui.cpp handles world jumping)
                        e->vel.x=0;