diff options
author | Astatin <[email protected]> | 2024-09-19 18:56:32 +0900 |
---|---|---|
committer | Astatin <astatin@redacted> | 2024-09-19 18:56:32 +0900 |
commit | ec1f79b44203735f581c7f85b6c23216aaf587a6 (patch) | |
tree | 0ae669440b2dce7f2e23cfadebb3dc0ab42efcba /entity/bunny.gbasm | |
parent | fa37dcacf1ff0de66f5c4eed7b89be6006d6d77b (diff) |
Read action buttons and set it in the entity direction highest nibble
Diffstat (limited to 'entity/bunny.gbasm')
-rw-r--r-- | entity/bunny.gbasm | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm new file mode 100644 index 0000000..81e19a6 --- /dev/null +++ b/entity/bunny.gbasm @@ -0,0 +1,126 @@ +Move_Bunny: + PUSH HL + LD C, $00 ; (bit 0 = has_scrolled, bit 1 = has ended movement) + LD A, $mem_bunny_direction + BIT 3, A + JR NZ, =Move_Bunny.check_direction + + LD B, $00 + Move_Bunny.check_start_action: + LD A, $mem_button_action + BIT 0, A + JR Z, =Move_Bunny.check_start_action.end + LD B, $10 + Move_Bunny.check_start_action.end: + LD A, $mem_bunny_direction + AND $0f + OR B + LD $mem_bunny_direction, A + + LD A, $mem_bunny_direction + AND $f0 + LD B, A + LD A, $mem_button_direction + CP $00 + JP Z, =Move_Bunny.end + SET 3, A + OR B + LD $mem_bunny_direction, A + + Move_Bunny.check_collision: + LD A, $mem_moving_animation_step + CP $00 + JR NZ, =Move_Bunny.check_collision.end + + ; THIS ASSUMES THAT THE BUNNY IS ALWAYS THE FIRST ENTITY IN THE LIST + LD HL, $mem_entities_list + LD A, $mem_bunny_direction + + PUSH BC + CALL =Get_Position_After_Move + LD A, C + CALL =Is_Collisionable + CALL =Carve_Entity_Collision_Map + POP BC + CP $00 + JR Z, =Move_Bunny.check_collision.end + + Move_Bunny.check_collision.collision: + LD A, $mem_bunny_direction + RES 3, A + LD $mem_bunny_direction, A + JP =Move_Bunny.end + + Move_Bunny.check_collision.end: + + Move_Bunny.check_direction: + LD A, $mem_bunny_direction + + DEC A + LD B, $01 ; Direction of the movement (+1) + BIT 0, A + JR NZ, =Move_Bunny.check_direction_end + LD B, $FF ; Direction of the movement (-1) + + Move_Bunny.check_direction_end: + + BIT 1, A + JR NZ, =Move_Bunny.vertical_viewport_move + + Move_Bunny.horizontal_viewport_move: + SET 0, C + LD A, $reg_viewport_x + ADD B + LD $reg_viewport_x, A + JP =Move_Bunny.check_end_of_movement + + Move_Bunny.vertical_viewport_move: + SET 0, C + LD A, $reg_viewport_y + ADD B + LD $reg_viewport_y, A + + Move_Bunny.check_end_of_movement: + LD A, $mem_moving_animation_step + INC A + AND $0f + LD $mem_moving_animation_step, A + JR NZ, =Move_Bunny.end + SET 1, C + LD A, $mem_bunny_direction + RES 3, A + LD $mem_bunny_direction, A + AND $07 + DEC A + + BIT 1, A + JR NZ, =Move_Bunny.vertical_tile_move + + Move_Bunny.horizontal_tile_move: + BIT 0, C + JR Z, =Move_Bunny.horizontal_tile_move.move_viewport_end + LD A, $mem_viewport_x + ADD B + LD $mem_viewport_x, A + Move_Bunny.horizontal_tile_move.move_viewport_end: + LD A, $mem_bunny_x + ADD B + LD $mem_bunny_x, A + JP =Move_Bunny.end + + Move_Bunny.vertical_tile_move: + BIT 0, C + JR Z, =Move_Bunny.vertical_tile_move.move_viewport_end + LD A, $mem_viewport_y + ADD B + LD $mem_viewport_y, A + Move_Bunny.vertical_tile_move.move_viewport_end: + LD A, $mem_bunny_y + ADD B + LD $mem_bunny_y, A + + Move_Bunny.end: + LD A, C + LD $mem_map_loading_flags, A + POP HL + RET |