aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-09-28 08:14:20 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-09-28 08:14:20 -0400
commit60f685b7b544b94ae1e6212b939cdae5ac12e725 (patch)
tree1fd3d11972cd2887a7927611a0da763821645767 /src
parent4391f9289b7368765b39c9654d6b0bdf2db8f36b (diff)
added dropping from platforms
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp8
-rw-r--r--src/main.cpp2
-rw-r--r--src/ui.cpp4
-rw-r--r--src/world.cpp15
4 files changed, 16 insertions, 13 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index da28851..140223d 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -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();
diff --git a/src/main.cpp b/src/main.cpp
index 0ba715f..9e029cf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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
diff --git a/src/ui.cpp b/src/ui.cpp
index 1e78dca..75bc5ee 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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;
diff --git a/src/world.cpp b/src/world.cpp
index 14df394..a5a6f4a 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -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;