diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-08 22:35:16 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-08 22:35:16 +0100 |
commit | 8871729a65615df0eab213bbbf942abe75771704 (patch) | |
tree | 34a4ab0f412c34383799e14816d1dfe288705085 /src/player.c | |
parent | 5ae0b6490f5fd138f4cbf5c084680bb03b2fff05 (diff) | |
download | gold-mine-run-8871729a65615df0eab213bbbf942abe75771704.tar.gz gold-mine-run-8871729a65615df0eab213bbbf942abe75771704.zip |
Avoid drawing the whole screen on each frame
This allows supporting 386DX "just about" (there will be flickering).
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/player.c b/src/player.c index 8c1765a..399dacf 100644 --- a/src/player.c +++ b/src/player.c @@ -24,20 +24,18 @@ #define IS_NOT_GOING_UP(x) (gravity == GRAVITY_OFF || (x)>=GRAVITY_DOWN) -static uint16_t x, y; +static uint16_t x, y, ox, oy, erase; static uint8_t dir, frame, delay, gravity, jump, momentum; static uint16_t respawn_x, respawn_y; static uint8_t respawn_dir; -static uint8_t invuln, dying; +static uint8_t invuln, dying, dead; const uint8_t gravity_seq[GRAVITY_SEQ_LEN] = { 6, 4, 4, 2, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 4 }; -static uint8_t bg[256]; - static const Rect frames[2][6] = { { @@ -77,9 +75,11 @@ void player_init(uint16_t start_x, uint8_t start_y, uint8_t start_dir) momentum = 0; invuln = 0; dying = 0; + dead = 0; + erase = 0; - respawn_x = x = start_x; - respawn_y = y = start_y; + respawn_x = ox = x = start_x; + respawn_y = oy = y = start_y; gravity = GRAVITY_OFF; } @@ -97,17 +97,20 @@ static void player_dying() /* exit screen */ if (y == MAP_H * MAP_TILE_H - 16) { + /* oh, well */ + player_erase(); + /* if there are lifes left, respawn */ if (dec_lives()) { player_init(respawn_x, respawn_y, respawn_dir); invuln = INVULN_TIME; } + else + dead = 1; /* stop falling */ gravity = GRAVITY_OFF; - /* don't draw the player; XXX: magic number */ - invuln = 4; return; } y++; @@ -131,6 +134,9 @@ void player_update() { uint8_t moved = 0; + ox = x; + oy = y; + if (dying) { player_dying(); @@ -160,7 +166,7 @@ void player_update() momentum = 0; frame = FRAME_JUMPING; gravity = GRAVITY_UP; - sound_queue_efx(EFX_JUMP); + sound_play_efx(EFX_JUMP); } } else @@ -273,26 +279,30 @@ void player_update() if (map_update_gold(x + (dir == DIR_LEFT ? 7 : 8), y + 15)) { add_score(10); - sound_queue_efx(EFX_GOLD); + sound_play_efx(EFX_GOLD); } } void player_erase() { - Rect dst = { x, y + MAP_OFFS_Y, 16, 16 }; - blit(bg, &dst); + if (!erase) + return; + + Rect dst = { ox, oy + MAP_OFFS_Y, 16, 16 }; + blit_copy(&dst); + + erase = 0; } void player_draw() { - Rect dst = { x, y + MAP_OFFS_Y, 16, 16 }; - - read_buffer(bg, &dst); - - if (invuln && (invuln & 4)) + if (dead || (invuln && (invuln & 4))) return; + Rect dst = { x, y + MAP_OFFS_Y, 16, 16 }; blitrc(binary_sprites_start, &frames[dir][frame], &dst); + + erase = 1; } uint8_t player_collision(Entity *e) @@ -320,14 +330,14 @@ void player_hit() if (use_pickaxe()) { invuln = INVULN_TIME; - sound_queue_efx(EFX_HIT); + sound_play_efx(EFX_HIT); } else { dying = 1; frame = FRAME_DYING; gravity = GRAVITY_UP; - sound_queue_efx(EFX_DEATH); + sound_play_efx(EFX_DEATH); } } |