objanim: Added top door animation
authorLukas Krickl <lukas@krickl.dev>
Tue, 12 Aug 2025 19:16:23 +0000 (21:16 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 12 Aug 2025 19:16:23 +0000 (21:16 +0200)
src/objanim.s
src/roompatterns.s

index bce08f693b82e6b2eaf548e963c2b6c88189f225..4090b76a9dd64dcd46787a98c9866205f3b04670 100644 (file)
@@ -20,10 +20,27 @@ objanim_init:
 objanim_door_open:
        push de
        push bc
+
+       ; set up the correct state based on tile index
+       ld a, b ; a = tile index
+       cp a, DOOR_TILE_TOP
+       jr nz, @not_top REL
+               
+               ld de, st_objanim_door_open_up
+               ld hl, objanim
+               ld bc, st_size
+               call memcpy
+               jp @done
+@not_top:
+
+       ; default to down
        ld de, st_objanim_door_open_down
        ld hl, objanim
        ld bc, st_size
        call memcpy
+
+@done:
+
        pop bc
        pop de
 
@@ -52,7 +69,7 @@ objanim_door_open:
        ; clear frame counter
        xor a, a
        ld [de], a
-
+       
        ; set gameplay flag to pause object updates
        ld a, [gameplay_flags]
        or a, GPF_PAUSE_UPDATE
@@ -93,6 +110,44 @@ objanim_door_open_down_fn:
        pop bc ; restore next state
        ret
 
+objanim_door_open_up_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
@@ -184,3 +239,6 @@ door_open_done:
 
 st_objanim_door_open_down:
        st_def 0x00, objanim_door_open_down_fn, st_objanim_door_open_down 
+
+st_objanim_door_open_up:
+       st_def 0x00, objanim_door_open_up_fn, st_objanim_door_open_up 
index 4eb6e7a0d8b9a7c1657b141c1e47c1a09dd21dfb..a78b1b61f25788782ae9d7f9b8c0f1a5c42dea2a 100644 (file)
@@ -99,8 +99,8 @@ room_pattern_special1:
   .db RPLW, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRF, RPRW
   .db RPBL, RPBW, RPBW, RPBW, RPBW, RPDB, RPBW, RPBW, RPBW, RPBW, RPBW, RPBW, RPBW, RPBR
 
-#define DOOR_TILE_TOP 0x0E
-#define DOOR_TILE_BOTTOM 0x2E
+#define DOOR_TILE_TOP 0x2E
+#define DOOR_TILE_BOTTOM 0x0E
 #define DOOR_TILE_LEFT 0x2C
 #define DOOR_TILE_RIGHT 0x0C
   
@@ -113,7 +113,7 @@ room_pattern_tile_translation:
  .db 0x44, 0x42
  .db 0x00 ; floor
  ; doors
- .db DOOR_TILE_BOTTOM, DOOR_TILE_TOP, DOOR_TILE_RIGHT, DOOR_TILE_LEFT 
+ .db DOOR_TILE_TOP, DOOR_TILE_BOTTOM, DOOR_TILE_RIGHT, DOOR_TILE_LEFT 
  ; roof
  .db 0x48