diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-21 15:22:21 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-21 15:22:21 -0500 |
commit | 59860415a2782694f630f7803ae4bcf445b3f5f1 (patch) | |
tree | 6c5dade6c2915cc68d69d536b465a5c6d7bd53fc /src | |
parent | e3e5a247c58c6e0b45d81ab61314bd8d1bd530ac (diff) | |
download | therapy-59860415a2782694f630f7803ae4bcf445b3f5f1.tar.gz therapy-59860415a2782694f630f7803ae4bcf445b3f5f1.tar.bz2 therapy-59860415a2782694f630f7803ae4bcf445b3f5f1.zip |
Player can short jump
Diffstat (limited to 'src')
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/mapview.cpp | 26 | ||||
-rw-r--r-- | src/mapview.h | 1 |
3 files changed, 23 insertions, 5 deletions
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 @@ | |||
3 | 3 | ||
4 | class Map { | 4 | class Map { |
5 | public: | 5 | public: |
6 | Map(); | ||
6 | Map(char* filename); | 7 | Map(char* filename); |
7 | ~Map(); | 8 | ~Map(); |
8 | const int* mapdata(); | 9 | 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 @@ | |||
1 | #include "mapview.h" | 1 | #include "mapview.h" |
2 | 2 | ||
3 | #define JUMP_VELOCITY(h, l) (-2 * (h) / (l)) | ||
4 | #define JUMP_GRAVITY(h, l) (2 * ((h) / (l)) / (l)) | ||
5 | |||
3 | // Initialize jump physics | 6 | // Initialize jump physics |
4 | double jump_height = TILE_HEIGHT*3; | 7 | double jump_height = TILE_HEIGHT*4; |
5 | double jump_length = 0.25 * FRAMES_PER_SECOND; | 8 | double jump_length = 0.25 * FRAMES_PER_SECOND; |
6 | double jump_velocity = -2 * jump_height / jump_length; | 9 | //double jump_velocity = -2 * jump_height / jump_length; |
7 | double jump_gravity = -1 * jump_velocity / jump_length; | 10 | //double jump_gravity = -1 * jump_velocity / jump_length; |
11 | double jump_velocity = JUMP_VELOCITY(TILE_HEIGHT*4, 0.30*FRAMES_PER_SECOND); | ||
12 | double jump_gravity = JUMP_GRAVITY(TILE_HEIGHT*4, 0.30*FRAMES_PER_SECOND); | ||
13 | double jump_gravity_short = JUMP_GRAVITY(TILE_HEIGHT*3, 0.20*FRAMES_PER_SECOND); | ||
8 | 14 | ||
9 | MapView::MapView(Map* first, int x, int y) | 15 | MapView::MapView(Map* first, int x, int y) |
10 | { | 16 | { |
@@ -14,8 +20,8 @@ MapView::MapView(Map* first, int x, int y) | |||
14 | player->y = y; | 20 | player->y = y; |
15 | player->x_vel = 0; | 21 | player->x_vel = 0; |
16 | player->y_vel = 0; | 22 | player->y_vel = 0; |
23 | player->y_accel = jump_gravity_short; | ||
17 | player->x_accel = 0; | 24 | player->x_accel = 0; |
18 | player->y_accel = jump_gravity; | ||
19 | player->w = 10; | 25 | player->w = 10; |
20 | player->h = 12; | 26 | player->h = 12; |
21 | player->onGround = false; | 27 | player->onGround = false; |
@@ -123,6 +129,7 @@ void MapView::input(int key, int action) | |||
123 | { | 129 | { |
124 | player->y_vel = jump_velocity; | 130 | player->y_vel = jump_velocity; |
125 | player->onGround = false; | 131 | player->onGround = false; |
132 | holding_up = true; | ||
126 | } | 133 | } |
127 | break; | 134 | break; |
128 | case GLFW_KEY_DOWN: | 135 | case GLFW_KEY_DOWN: |
@@ -144,6 +151,9 @@ void MapView::input(int key, int action) | |||
144 | case GLFW_KEY_DOWN: | 151 | case GLFW_KEY_DOWN: |
145 | holding_down = false; | 152 | holding_down = false; |
146 | break; | 153 | break; |
154 | case GLFW_KEY_UP: | ||
155 | holding_up = false; | ||
156 | break; | ||
147 | } | 157 | } |
148 | } | 158 | } |
149 | } | 159 | } |
@@ -165,7 +175,13 @@ void MapView::tick() | |||
165 | if (player->x_vel > 16) player->x_vel = 16; | 175 | if (player->x_vel > 16) player->x_vel = 16; |
166 | int playerx_next = player->x + player->x_vel; | 176 | int playerx_next = player->x + player->x_vel; |
167 | 177 | ||
168 | player->y_vel += player->y_accel; | 178 | if (holding_up) |
179 | { | ||
180 | player->y_vel += jump_gravity; | ||
181 | } else { | ||
182 | player->y_vel += jump_gravity_short; | ||
183 | } | ||
184 | |||
169 | if (player->y_vel > 16) player->y_vel = 16; // Terminal velocity | 185 | if (player->y_vel > 16) player->y_vel = 16; // Terminal velocity |
170 | if (player->y_vel < -16) player->y_vel = -16; | 186 | if (player->y_vel < -16) player->y_vel = -16; |
171 | int playery_next = player->y + player->y_vel; | 187 | 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 { | |||
54 | bool holding_left = false; | 54 | bool holding_left = false; |
55 | bool holding_right = false; | 55 | bool holding_right = false; |
56 | bool holding_down = false; | 56 | bool holding_down = false; |
57 | bool holding_up = false; | ||
57 | mob_t* player; | 58 | mob_t* player; |
58 | 59 | ||
59 | Map* curMap; | 60 | Map* curMap; |