Implement falling

This commit is contained in:
Juhani Krekelä 2022-01-14 17:25:57 +00:00
parent 4cab2a66b9
commit b69249d230
1 changed files with 6 additions and 6 deletions

View File

@ -28,9 +28,9 @@ static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
static char tilemap[] = " "
" "
" "
" "
" g "
"gg g "
" g g"
" g"
" g "
" g "
" g g "
@ -73,7 +73,7 @@ static void on_keyboard(void *context, uint32_t window, uint32_t codepoint) {
case KBKEY_E: jump_duration += 0.1; break;
case KBKEY_D: jump_duration -= 0.1; break;
}
printf("hold %i height %i duration %i\n", (int)(jump_maxhold * 10), (int)(jump_maxheight * 10), (int)(jump_duration * 10));
//printf("hold %i height %i duration %i\n", (int)(jump_maxhold * 10), (int)(jump_maxheight * 10), (int)(jump_duration * 10));
}
static void on_quit(void *context, uint32_t window) {
@ -124,7 +124,6 @@ static void update(struct timespec now, struct timespec dt_timespec) {
jump_start_y = player_y;
}
if (!on_ground && !jumping) {
// TODO: implement proper falling
jumping = true;
in_jump = jump_duration;
jump_start_y = player_y + jump_maxheight;
@ -186,7 +185,7 @@ static void update(struct timespec now, struct timespec dt_timespec) {
size_t left_cx = px - 1;
size_t right_cx = px + TILE_SIDE;
size_t leftright_top_cy = py;
size_t leftright_bottom_cy = py + TILE_SIDE - 2;
size_t leftright_bottom_cy = py + TILE_SIDE - 3; //XXX: proper handling of snapping
if ((sample_tilemap(left_cx, leftright_top_cy) != ' ' ||
sample_tilemap(left_cx, leftright_bottom_cy) != ' ') &&
player_dx < 0) {
@ -224,7 +223,8 @@ static void update(struct timespec now, struct timespec dt_timespec) {
player_dy < 0) {
size_t snapped_py = (py + TILE_SIDE - 1) / TILE_SIDE * TILE_SIDE;
player_y = snapped_py;
player_dy = 0;
in_jump = jump_duration;
jump_start_y = player_y + jump_maxheight;
}
}