#define SCRN0_END 0x9BF3
+
+ ; clears the map routine to nop
+map_clear_routine:
+ ld a, map_r_nop LO
+ ld [map_routine], a
+ ld a, map_r_nop HI
+ ld [map_routine+1], a
+ ret
; loads a map
; including the required tileset
; de: map ptr
map_load:
; clear map routine
- ld a, map_r_nop LO
- ld [map_routine], a
- ld a, map_r_nop HI
- ld [map_routine+1], a
+ call map_clear_routine
call disableinterrupts
call next_vblank_wait
; checks if all enemies are defeated
; and re-enables scroll
map_r_enable_scroll_all_enemies_defeated:
+ ld a, [map_anim_timer]
+ cp a, 0
+ jp z, @no_animation
; TODO
+ call map_arrow_indicator
+ ret
+
+@no_animation:
+ ; set animation
+ ld a, 120
+ ld [map_anim_timer], a
+
+ xor a, a
+ ld [map_anim_state], a
+
+ ld a, 80 ; x position
+ ld [map_anim_p0], a
+ ret
+
+#define MAP_TILE_ARROW 0x84
+
+ ; plays an arrow indicator animation
+ ; flashng it every 32 frames
+ ; uses timer for duration
+ ; map anim state for state counter
+ ; anim p0 for x position
+map_arrow_indicator:
+ ld a, [map_anim_timer]
+ dec a
+ ld [map_anim_timer], a
+ jp z, @end_anim
+
+ ; check state
+ ld a, [map_anim_state]
+ inc a
+ cp a, 32
+ jr nz, @no_x_swap REL
+ ld a, [map_anim_p0]
+ xor a, 80
+ ld [map_anim_p0], a
+ xor a, a ; clear state
+@no_x_swap:
+ ld [map_anim_state], a
+
+ ld a, 1
+ call oamalloc
+
+ ld a, 16
+ ; y
+ ld [hl+], a
+
+ ; x
+ ld a, [map_anim_p0]
+ ld [hl+], a
+
+ ; tile
+ ld a, MAP_TILE_ARROW
+ ld [hl+], a
+
+ ; flags
+ xor a, a
+ ld [hl+], a
+
+ ret
+@end_anim:
+ call map_clear_routine
ret
l1_map:
modef2 MOT_ACTOR_SPAWNER, 0, 18, ACT_T_GUARD, 0x40
modef MOT_SET_PAT, 0, 0x1E, pat_empty
+ modef2 MOT_ACTOR_SPAWNER, 0, 0x1F, ACT_T_GUARD, 0x40
modef MOT_DISABLE_SCROLL, 0, 0x20, 0
modef MOT_SET_MAP_ROUTINE, 0, 0x20, map_r_enable_scroll_all_enemies_defeated
modef MOT_NOP, 0, 0xFF, 0
; can be set by map object
map_routine: .adv 2
+ ; map animation timer
+ ; use for e.g. arrow indicating scroll is enabled again
+map_anim_timer: .adv 1
+ ; state data for map anim
+map_anim_state: .adv 1
+ ; custom data for map anim
+map_anim_p0: .adv 1
; current debug function
dbg_fn: .adv 1