From 59860415a2782694f630f7803ae4bcf445b3f5f1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 21 Feb 2015 15:22:21 -0500 Subject: Player can short jump --- src/map.h | 1 + src/mapview.cpp | 26 +++++++++++++++++++++----- src/mapview.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/map.h b/src/map.h index 2acce59..d7b4ecf 100644 --- a/src/map.h +++ b/src/map.h @@ -3,6 +3,7 @@ class Map { public: + Map(); Map(char* filename); ~Map(); const int* mapdata(); diff --git a/src/mapview.cpp b/src/mapview.cpp index 78dd770..76d7f02 100644 --- a/src/mapview.cpp +++ b/src/mapview.cpp @@ -1,10 +1,16 @@ #include "mapview.h" +#define JUMP_VELOCITY(h, l) (-2 * (h) / (l)) +#define JUMP_GRAVITY(h, l) (2 * ((h) / (l)) / (l)) + // Initialize jump physics -double jump_height = TILE_HEIGHT*3; +double jump_height = TILE_HEIGHT*4; double jump_length = 0.25 * FRAMES_PER_SECOND; -double jump_velocity = -2 * jump_height / jump_length; -double jump_gravity = -1 * jump_velocity / jump_length; +//double jump_velocity = -2 * jump_height / jump_length; +//double jump_gravity = -1 * jump_velocity / jump_length; +double jump_velocity = JUMP_VELOCITY(TILE_HEIGHT*4, 0.30*FRAMES_PER_SECOND); +double jump_gravity = JUMP_GRAVITY(TILE_HEIGHT*4, 0.30*FRAMES_PER_SECOND); +double jump_gravity_short = JUMP_GRAVITY(TILE_HEIGHT*3, 0.20*FRAMES_PER_SECOND); MapView::MapView(Map* first, int x, int y) { @@ -14,8 +20,8 @@ MapView::MapView(Map* first, int x, int y) player->y = y; player->x_vel = 0; player->y_vel = 0; + player->y_accel = jump_gravity_short; player->x_accel = 0; - player->y_accel = jump_gravity; player->w = 10; player->h = 12; player->onGround = false; @@ -123,6 +129,7 @@ void MapView::input(int key, int action) { player->y_vel = jump_velocity; player->onGround = false; + holding_up = true; } break; case GLFW_KEY_DOWN: @@ -144,6 +151,9 @@ void MapView::input(int key, int action) case GLFW_KEY_DOWN: holding_down = false; break; + case GLFW_KEY_UP: + holding_up = false; + break; } } } @@ -165,7 +175,13 @@ void MapView::tick() if (player->x_vel > 16) player->x_vel = 16; int playerx_next = player->x + player->x_vel; - player->y_vel += player->y_accel; + if (holding_up) + { + player->y_vel += jump_gravity; + } else { + player->y_vel += jump_gravity_short; + } + if (player->y_vel > 16) player->y_vel = 16; // Terminal velocity if (player->y_vel < -16) player->y_vel = -16; int playery_next = player->y + player->y_vel; diff --git a/src/mapview.h b/src/mapview.h index 06309e3..505ab25 100644 --- a/src/mapview.h +++ b/src/mapview.h @@ -54,6 +54,7 @@ class MapView : public State { bool holding_left = false; bool holding_right = false; bool holding_down = false; + bool holding_up = false; mob_t* player; Map* curMap; -- cgit 1.4.1