From 1c14120e1fb036b467ce91e82fb6d7913385ab35 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 18 Nov 2024 13:55:32 +0100 Subject: [PATCH] Added new movement for player. - TODO: collision is still not implemented again --- src/actor.s | 50 +++++++++++++++++++++++++++ src/player.s | 97 ++++++++++++++++------------------------------------ src/wram.s | 13 +++++++ 3 files changed, 93 insertions(+), 67 deletions(-) diff --git a/src/actor.s b/src/actor.s index 828101d..b617ffc 100644 --- a/src/actor.s +++ b/src/actor.s @@ -78,3 +78,53 @@ actors_update: jr nz, @loop REL ret + + ; simple move animation + ; moves 1 pixel per frame + ; inputs: + ; hl: ptr to y/x positon + ; anim_move_x/y: y/x offset + ; anim_step_x/y: y/x step per frame + ; returns: + ; a == 0 if both y and x are 0 + ; hl is left unchanged +anim_move: + ; y pos + ld a, [anim_move_y] + ld b, a ; exit code == b + + cp a, 0 + jr z, @no_y REL ; if move is 0 do nothing + + dec a + ld [anim_move_y], a ; a-- + + ld a, [hl] + ld b, a + ld a, [anim_step_y] + add a, b ; a = y + step + ld [hl], a +@no_y: + + inc hl + + ; x pos + ld a, [anim_move_x] + cp a, 0 + jr z, @no_x REL ; if move is 0 do nothing + + dec a + ld [anim_move_x], a ; a-- + + ld a, [hl] + ld b, a + ld a, [anim_step_x] + add a, b ; a = x + step + ld [hl], a + +@no_x: + dec hl + ; exit code + ld a, b + + ret diff --git a/src/player.s b/src/player.s index 4abe639..8dedd63 100644 --- a/src/player.s +++ b/src/player.s @@ -76,6 +76,13 @@ player_update: ld a, [who] cp a, WHO_PLAYER jp nz, @skip_input + + ; play move animation + ; and skip inputs if it is still + ; ongoing + call anim_move + cp a, 0 + jp nz, @skip_input ; set collision mask ld a, RF_WALL @@ -85,85 +92,47 @@ player_update: ; input handling input_held BTNDOWN jr z, @notdown REL - - ; hl = player_y - ld a, [hl] - inc a - ld [hl], a - - - player_collision_check collision_player_bot - jr z, @no_collision_up REL - ld a, [hl] - dec a - ld [hl], a -@no_collision_down: - + + ; set animation params + ld a, ANIM_MOVE_TILE_SIZE + ld [anim_move_y], a + ld a, ANIM_STEP_DOWN + ld [anim_step_y], a @notdown: input_held BTNUP jr z, @notup REL - ; hl = player_y - ld a, [hl] - dec a - ld [hl], a - - player_collision_check collision_player_top - jr z, @no_collision_up REL - ld a, [hl] - inc a - ld [hl], a -@no_collision_up: - - + ; set animation params + ld a, ANIM_MOVE_TILE_SIZE + ld [anim_move_y], a + ld a, ANIM_STEP_UP + ld [anim_step_y], a @notup: - ; store y in d - ; and inc hl - ld a, [hl+] - ld d, a input_held BTNLEFT jr z, @notleft REL - ; hl = player_x - ld a, [hl] - dec a - ld [hl], a - - - dec hl ; hl = player_y - player_collision_check collision_player_left - inc hl ; hl = player_x - jr z, @no_collision_left REL - ld a, [hl] - inc a - ld [hl], a -@no_collision_left: - + ; set animation params + ld a, ANIM_MOVE_TILE_SIZE + ld [anim_move_x], a + ld a, ANIM_STEP_LEFT + ld [anim_step_x], a @notleft: input_held BTNRIGHT jr z, @notright REL - ; hl = player_x - ld a, [hl] - inc a - ld [hl], a - + ; set animation params + ld a, ANIM_MOVE_TILE_SIZE + ld [anim_move_x], a + ld a, ANIM_STEP_RIGHT + ld [anim_step_x], a +@notright: - dec hl ; hl = player_y - player_collision_check collision_player_right - inc hl ; hl = player_x - jr z, @no_collision_right REL - ld a, [hl] - dec a - ld [hl], a -@no_collision_right: +@action_buttons: -@notright: - input_just BTNA jr z, @nota REL @@ -202,18 +171,12 @@ player_update: ; sotre x in e ld a, [hl] ld e, a - - ; hl is ok to use again - ; bc is free - ; de is still used - dec hl ; hl = player_y = player start @skip_input: ; hl should be player_y here ; d: player_y ; e: player_x - ; b: obj flags mask ld a, [hl+] ; hl = player_x ld d, a ; d = player_y ld a, [hl] diff --git a/src/wram.s b/src/wram.s index c2dbc48..558b9c6 100644 --- a/src/wram.s +++ b/src/wram.s @@ -152,6 +152,19 @@ game_mode: .adv 1 ; but may *never* act when they are not currently enabled who: .adv 1 +#define ANIM_MOVE_TILE_SIZE 16 +#define ANIM_STEP_DOWN 1 +#define ANIM_STEP_LEFT 0xFF +#define ANIM_STEP_UP 0xFF +#define ANIM_STEP_RIGHT 1 + +; animation params storage +anim_move_y: .adv 1 +anim_move_x: .adv 1 + +anim_step_y: .adv 1 +anim_step_x: .adv 1 + ; collision tile tmp values ct_poy: .adv 1 ct_pox: .adv 1 -- 2.30.2