From: Lukas Krickl Date: Mon, 27 Jan 2025 13:32:24 +0000 (+0100) Subject: player: moved collision check to subroutine X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=e8b57735b764f4332b0b7e28afa8124c667b54cb;p=gbrg%2F.git player: moved collision check to subroutine --- diff --git a/src/player.s b/src/player.s index 531213e..b0f7ae8 100644 --- a/src/player.s +++ b/src/player.s @@ -210,48 +210,14 @@ player_update: ; sotre x in e ld a, [hl] ld e, a - - ; if any collision happens now - ; we stop the animation - push hl ; need to save hl + ld a, [anim_target_y] add a, 8 ld d, a ; d = target y + 8 to center on tile ld a, [anim_target_x] add a, 8 ld e, a ; e = target x + 8 to center on tile - call collision_tile - ld h, a ; store original a in h for now - - and a, RF_DOOR - jr z, @no_door_hit REL - - ; set room load flag is door was hit - ld a, [engine_flags] - or a, EG_FLOAD_ROOM - ld [engine_flags], a - - -@no_door_hit: - - ld a, h ; restore original a for next check - and a, RF_ACTOR - jr z, @no_enemy_hit REL - - ; TODO add enemy hit logic - -@no_enemy_hit: - - ld a, h ; restore original a for next check - and a, RF_WALL | RF_ACTOR - pop hl - - jr z, @no_collision REL - ; clear anim memory - call anim_clear - jr @skip_input REL -@no_collision: - ; call z, player_tile_update_rf_flags + call player_collision_check @skip_input: ; hl should be player_y here @@ -350,6 +316,49 @@ player_update: ret + ; performs player collision checks + ; inputs: + ; hl: player ptr + ; de: y/x position used for check +player_collision_check: + ; if any collision happens now + ; we stop the animation + push hl ; need to save hl + call collision_tile + ld h, a ; store original a in h for now + + and a, RF_DOOR + jr z, @no_door_hit REL + + ; set room load flag is door was hit + ld a, [engine_flags] + or a, EG_FLOAD_ROOM + ld [engine_flags], a + + +@no_door_hit: + + ld a, h ; restore original a for next check + and a, RF_ACTOR + jr z, @no_enemy_hit REL + + ; TODO add enemy hit logic + +@no_enemy_hit: + + ld a, h ; restore original a for next check + and a, RF_WALL | RF_ACTOR + pop hl + + jr z, @no_collision REL + ; clear anim memory + call anim_clear + jr @skip REL +@no_collision: + ; call z, player_tile_update_rf_flags +@skip: + ret + ; uses a resource such as ; hp, mp, atk or def down to 0 ; inputs: