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
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
; 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
; 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