From 897a0ff92b25d73114fcf338071bff2fd10d15d6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 12 Aug 2025 20:36:57 +0200 Subject: [PATCH] objanim: Added framework for makign door animations more generic --- src/objanim.s | 61 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/objanim.s b/src/objanim.s index 516c756..bce08f6 100644 --- a/src/objanim.s +++ b/src/objanim.s @@ -59,16 +59,56 @@ objanim_door_open: ld [gameplay_flags], a ret + + ; down animation +objanim_door_open_down_fn: + ld a, [objanim+obja_timer] ; read timer before calling handler + push af + call objanim_door_open_generic_fn + + pop af + push bc ; save next state + ; hl = oam ptr + inc hl ; skip obj1 y + + ; adjust x position based on timer + ; offset position by counter + sra a + ld b, a + ld a, [hl] + sub a, b + ; wirte adjusted obj1 x + ld [hl+], a ; hl = obj1 tile + + inc hl ; skip obj1 tile + inc hl ; skip obj1 flags + inc hl ; skip obj2 y + + ; hl = obj2 x + ld a, [hl] + add a, b + ; write adjusted obj2 x + ld [hl+], a + + pop bc ; restore next state + ret ; state function for door opening animation - ; down + ; is called by more specific functions that take this base setup + ; and set the right tiles and animations after ; inputs: ; de: objanim -objanim_door_open_down_fn: + ; returns: + ; hl: first object used + ; the objects are guaranteed to be consecutive + ; and 2 objects will have been reserved + ; bc: next state +objanim_door_open_generic_fn: #define TMP_Y, scratch #define TMP_X, scratch+1 call load_unit_obj + push hl ld de, objanim+st_size call load_scroll @@ -86,13 +126,6 @@ objanim_door_open_down_fn: ld a, [de] ; a = x position tile_to_scrn OBJ_OFF_X, c ld [TMP_X], a - ; offset position by counter - push af - ld a, [objanim+obja_timer] - sra a - ld b, a - pop af - sub a, b ld [hl+], a @@ -114,13 +147,6 @@ objanim_door_open_down_fn: ; set x pos ld a, [TMP_X] add a, 8 ; move over a tile - ; offset position by counter - push af - ld a, [objanim+obja_timer] - sra a - ld b, a - pop af - add a, b ld [hl+], a ; tile @@ -130,7 +156,8 @@ objanim_door_open_down_fn: ; flags xor a, a ld [hl], a - + + pop hl ; restore object ptr used == return value ; check if we are done ld a, [objanim+obja_timer] inc a -- 2.30.2