From 5781bba3aa5764792b25a1d395cac388d001d713 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 26 Sep 2015 16:44:16 -0400 Subject: fixed jumping for real --- Changelog | 4 ++++ include/entities.h | 1 + include/world.h | 4 ++-- src/entities.cpp | 5 +++-- src/ui.cpp | 7 ++++++- src/world.cpp | 1 + 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 0e6d0a8..2d138e4 100644 --- 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 diff --git a/include/entities.h b/include/entities.h index 2687c24..6e0e2c3 100644 --- a/include/entities.h +++ b/include/entities.h @@ -14,6 +14,7 @@ public: vec2 vel; bool right,left, canMove; bool alive; + bool ground; unsigned int texture[]; diff --git a/include/world.h b/include/world.h index 444b2c4..e826ba2 100644 --- a/include/world.h +++ b/include/world.h @@ -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 diff --git a/src/entities.cpp b/src/entities.cpp index 5da39dd..3c2120b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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(){ diff --git a/src/ui.cpp b/src/ui.cpp index 5cfc492..f849cf8 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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; diff --git a/src/world.cpp b/src/world.cpp index 44ea10d..cab9ecb 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; -- cgit v1.2.3