From 5781bba3aa5764792b25a1d395cac388d001d713 Mon Sep 17 00:00:00 2001
From: Clyne Sullivan <tullivan99@gmail.com>
Date: Sat, 26 Sep 2015 16:44:16 -0400
Subject: fixed jumping for real

---
 src/entities.cpp | 5 +++--
 src/ui.cpp       | 7 ++++++-
 src/world.cpp    | 1 +
 3 files changed, 10 insertions(+), 3 deletions(-)

(limited to 'src')

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