objanim: wip left and right door animation
authorLukas Krickl <lukas@krickl.dev>
Tue, 12 Aug 2025 20:43:34 +0000 (22:43 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 12 Aug 2025 20:43:34 +0000 (22:43 +0200)
This will require special handling to actually make the animations work

src/objanim.s
tiles/bank8800.inc

index 4090b76a9dd64dcd46787a98c9866205f3b04670..42d828d19024302383266faffbbc119584625a00 100644 (file)
@@ -33,6 +33,25 @@ objanim_door_open:
                jp @done
 @not_top:
 
+       cp a, DOOR_TILE_LEFT
+       jr nz, @not_left REL
+               
+               ld de, st_objanim_door_open_left
+               ld hl, objanim
+               ld bc, st_size
+               call memcpy
+               jp @done
+@not_left:
+
+       cp a, DOOR_TILE_RIGHT
+       jr nz, @not_right REL
+               ld de, st_objanim_door_open_right
+               ld hl, objanim
+               ld bc, st_size
+               call memcpy
+               jp @done
+@not_right:    
+
        ; default to down
        ld de, st_objanim_door_open_down
        ld hl, objanim
@@ -148,6 +167,86 @@ objanim_door_open_up_fn:
 
        ret
 
+objanim_door_open_left_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
+
+       ; adjust x position based on timer
+       ; offset position by counter 
+       sra a
+       ld b, a
+       ld a, [hl]
+       sub a, b
+       ; wirte adjusted obj1 y 
+       ld [hl+], a ; hl = obj1 tile
+       inc hl ; skip obj1 x 
+
+       ; adjust tile by 4 (next tile) and ++
+       ld a, DOOR_SPRITE_TILE + 4 
+       ld [hl+], a
+
+       xor a, a
+       ld [hl+], a ; write obj1 flag and ++
+       
+       ; hl = obj2 y 
+       ld a, [hl]
+       add a, b
+       ; write adjusted obj2 y 
+       ld [hl+], a
+       inc hl ; skip obj2 x 
+       
+       ; adjust tile by 4 (next tile) and ++
+       ld a, DOOR_SPRITE_TILE + 6 
+       ld [hl+], a
+
+       xor a, a
+       ld [hl], a
+       
+       pop bc ; restore next state
+       ldnull bc
+       ret
+
+objanim_door_open_right_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
+       ld a, OAM_FYFLIP
+       ld [hl+], a ; write obj1 flag and ++
+       inc hl ; skip obj2 y 
+       
+       ; hl = obj2 x 
+       ld a, [hl]
+       add a, b
+       ; write adjusted obj2 x
+       ld [hl+], a
+
+       inc hl ; skip obj2 tile
+       ld a, OAM_FYFLIP ; write obj2 flag 
+       ld [hl], a
+       
+       pop bc ; restore next state
+       ret
        ; state function for door opening animation
        ; is called by more specific functions that take this base setup
        ; and set the right tiles and animations after
@@ -242,3 +341,9 @@ st_objanim_door_open_down:
 
 st_objanim_door_open_up:
        st_def 0x00, objanim_door_open_up_fn, st_objanim_door_open_up 
+
+st_objanim_door_open_left:
+       st_def 0x00, objanim_door_open_left_fn, st_objanim_door_open_left 
+
+st_objanim_door_open_right:
+       st_def 0x00, objanim_door_open_right_fn, st_objanim_door_open_right 
index 2f0785988ae63a741b086ff43de355eb448134ce..cf2b3b181a43e93fd6c72136e41baa19f98867e8 100644 (file)
 .chr 31111113
 .chr 33333333
 ; tile 2
-.chr 01000100
-.chr 01333100
-.chr 03333300
-.chr 03221310
-.chr 10222010
-.chr 13333310
-.chr 10333000
-.chr 00333000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333333
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 33333333
+.chr 33333333
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 31111111
+.chr 33333333
 ; tile 3
-.chr 00000000
-.chr 00033000
-.chr 00033000
-.chr 00033000
-.chr 00000000
-.chr 00033000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333222
+.chr 11111322
+.chr 11111132
+.chr 11111113
+.chr 11111113
+.chr 11111113
+.chr 11111113
+.chr 33333333
+.chr 33333333
+.chr 11111113
+.chr 11111113
+.chr 11111113
+.chr 11111113
+.chr 11111132
+.chr 11111322
+.chr 33333222
 ; tile 4
 .chr 00000000
 .chr 00000000