]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixed jumping for real
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 26 Sep 2015 20:44:16 +0000 (16:44 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 26 Sep 2015 20:44:16 +0000 (16:44 -0400)
Changelog
include/entities.h
include/world.h
src/entities.cpp
src/ui.cpp
src/world.cpp

index 0e6d0a84944699059b0d9b462d3082dc1727ed7f..2d138e4ac61e626d851bf53ae557d044b1ed7aad 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -22,3 +22,7 @@
        - improved entity binding
        - added structures, villagers, and a basic villager AI
 
+9/26/2015:
+==========
+
+       - added a base for indoor areas
index 2687c24a78a40cd30790fd1a4c5d94bd7e296dce..6e0e2c3884e714e5e848bf8f3ed47c64a820c729 100644 (file)
@@ -14,6 +14,7 @@ public:
        vec2 vel;
        bool right,left, canMove;
        bool alive;
+       bool ground;
 
        unsigned int texture[];
        
index 444b2c480bbe93d3803ad14a06b30e0c420e0d95..e826ba2b9697d6b7badc84aad475a11061df68b9 100644 (file)
@@ -68,8 +68,8 @@ public:
        IndoorWorld(void);
        ~IndoorWorld(void);
        
-       void generate(unsigned int width);
-       void draw(vec2 *vec);
+       void generate(unsigned int width);      // Generates a flat world of width 'width'
+       void draw(vec2 *vec);                           // Draws the world (ignores layers)
 };
 
 #endif // WORLD_H
index 5da39dd336c4782ceaf8d024b2b49f66823ee42d..3c2120b0421c930380d9588fee8d75cf283f8481 100644 (file)
@@ -13,6 +13,7 @@ void Entity::spawn(float x, float y){
        left = false;
        ticksToUse = 0;
        canMove = false;
+       ground = false;
 }
 
 void Entity::draw(void){
@@ -38,6 +39,7 @@ Player::Player(){
        type = 0;
        subtype = 5;
        alive = true;
+       ground = false;
 }
 
 void Player::interact(){
@@ -55,8 +57,7 @@ NPC::NPC(){
 }
 
 void NPC::interact(){
-       loc.y += .01;
-       
+       //loc.y += .01;
 }
 
 Structures::Structures(){
index 5cfc492e7c84b0b7c4449bf98434cdc732e34177..f849cf8bd84c8a8d542223c42b5ed48ad93f48da 100644 (file)
@@ -142,7 +142,12 @@ namespace ui {
                                        player->vel.x=.15;
                                        currentWorld=currentWorld->goWorldRight(player);
                                }
-                               if(SDL_KEY==SDLK_SPACE)player->vel.y=.25;                                                       // Jump
+                               if(SDL_KEY==SDLK_SPACE){                                                                                        // Jump
+                                       if(player->ground){
+                                               player->vel.y=.25;
+                                               player->ground=false;
+                                       }
+                               }
                                if(SDL_KEY==SDLK_i)currentWorld=currentWorld->goWorldBack(player);      // Go back a layer if possible
                                if(SDL_KEY==SDLK_k)currentWorld=currentWorld->goWorldFront(player);     // Go forward a layer if possible
                                if(SDL_KEY==SDLK_F3)debug^=true;
index 44ea10d973df54a1ad9ddb78cb0e575bcbe4c1ee..cab9ecb2e825f7b1b7c70c4a2137c90a42292717 100644 (file)
@@ -121,6 +121,7 @@ void World::singleDetect(Entity *e){
                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
                        e->vel.y-=.01;