-#define ACT_NEARBY_Y 60
-#define ACT_NEARBY_X 80
+#define ACT_FAR_Y 60
+#define ACT_FAR_X 80
+
+#define ACT_FURTHEST_Y 60
+#define ACT_FURTHEST_X 80
; vectors for each direction
; SOUTH, NORTH, WEST, EAST
ld h, [hl]
ld l, a
jp hl
+
+
+ ; generic actor table call
+ ; inputs:
+ ; $1: far, near, furthest
+#macro _act_draw_n
+ ld a, [de] ; type
+ add a, a ; * 2 for offset
+ ld hl, act_draw_$1_table
+ ld b, 0
+ ld c, a
+ add hl, bc
+
+ ; load routine ptr
+ ld a, [hl+]
+ ld h, [hl]
+ ld l, a
+ jp hl
+#endmacro
+
+act_draw_near_table:
+ ; NULL
+ dw act_r_nop
+ ; PLAYER
+ dw act_r_nop
+ ; bat
+ dw act_r_nop
+
+ ; draws a near actor
+ ; inputs:
+ ; de: actor
+act_draw_near:
+ _act_draw_n near
; draws a bat actor
; inputs:
; de: act ptr
-act_draw_nearby_bat:
+act_draw_far_bat:
+ ld a, 4
+ call oamalloc
+
+ ld a, ACT_FAR_Y
+ ld [hl+], a
+ ld a, ACT_FAR_X
+ ld [hl+], a
+ ld a, 0x85
+ ld [hl+], a
+ xor a, a
+ ld [hl+], a
+
+ ld a, ACT_FAR_Y+8
+ ld [hl+], a
+ ld a, ACT_FAR_X
+ ld [hl+], a
+ ld a, 0xA4
+ ld [hl+], a
+ xor a, a
+ ld [hl+], a
+
+ ld a, ACT_FAR_Y
+ ld [hl+], a
+ ld a, ACT_FAR_X+8
+ ld [hl+], a
+ ld a, 0x87
+ ld [hl+], a
+ xor a, a
+ ld [hl+], a
+
+ ld a, ACT_FAR_Y+8
+ ld [hl+], a
+ ld a, ACT_FAR_X+8
+ ld [hl+], a
+ ld a, 0xA6
+ ld [hl+], a
+ xor a, a
+ ld [hl+], a
+ ret
+
+act_draw_far_table:
+ ; NULL
+ dw act_r_nop
+ ; player
+ dw act_r_nop
+ ; bat
+ dw act_draw_far_bat
+
+ ; draws an actor if they are far
+ ; usuall act_nearby or prop_nearby
+ ; to the camera
+ ; inputs:
+ ; de: actor ptr
+act_draw_far:
+ _act_draw_n far
+
+ ; draw a bat actor
+ ; inputs:
+ ; de: actor ptr
+act_draw_furthest_bat:
ld a, 2
call oamalloc
- ld a, ACT_NEARBY_Y
+ ld a, ACT_FURTHEST_Y
ld [hl+], a
- ld a, ACT_NEARBY_X
+ ld a, ACT_FURTHEST_X
ld [hl+], a
ld a, 0x83
ld [hl+], a
xor a, a
ld [hl+], a
- ld a, ACT_NEARBY_Y+8
+ ld a, ACT_FURTHEST_Y+8
ld [hl+], a
- ld a, ACT_NEARBY_X
+ ld a, ACT_FURTHEST_X
ld [hl+], a
ld a, 0xA2
ld [hl+], a
ld [hl], a
ret
-act_draw_nearby_table:
- ; NULL
+act_draw_furthest_table:
+ ; NULLL
dw act_r_nop
; player
dw act_r_nop
; bat
- dw act_draw_nearby_bat
+ dw act_draw_furthest_bat
- ; draws an actor if they are near
- ; usuall act_nearby or prop_nearby
- ; to the camera
+ ; draws an actor if they are furthest
; inputs:
; de: actor ptr
-act_draw_nearby:
- ld a, [de] ; type
- add a, a ; * 2 for offset
- ld hl, act_draw_nearby_table
- ld b, 0
- ld c, a
- add hl, bc
-
- ; load routine ptr
- ld a, [hl+]
- ld h, [hl]
- ld l, a
- jp hl
+act_draw_furthest:
+ _act_draw_n furthest
+
+ ret
; clears tact at the current actors position
; inputs:
; tmp_map_near_right_door: 0/1 door present or not
; tmp_map_far_left_door: 0/1 door present or not
; tmp_map_far_right_door 0/1 door present or not
+ ; tmp_map_furthest_left_door: 0/1 door present or not
+ ; tmp_map_furthest_right_door: 0/1 door present or not
; tile_near: near tile coordinates
; tile_far: far tile coordinates
+ ; tile_furthest: furthest tile coordinates
map_full_draw_count_forward_attributes:
xor a, a
ld [tmp_map_forward], a
ld [tmp_map_near_right_door], a
ld [tmp_map_far_left_door], a
ld [tmp_map_far_right_door], a
+ ld [tmp_map_furthest_left_door], a
+ ld [tmp_map_furthest_right_door], a
; clear tile_near and tile_far
ld [tile_near+1], a
ld [tile_far], a
ld [tile_far+1], a
+ ld [tile_furthest], a
+ ld [tile_furthest+1], a
ld a, [player+act_pos_y]
ld b, a
@north:
+ ; write near tile
map_full_draw_door_state TF_NE, TF_WE, TF_EE
map_full_draw_write_door_state 1, 1, ret
dec b ; move one tile back
_map_write_nearby_tile 2
+ push bc
call map_get_tile
+ pop bc
+ ; write far tile
map_full_draw_door_state TF_NE, TF_WE, TF_EE
map_full_draw_write_door_state 3, 2, ret
+
+ dec b ; move one tile back
+ _map_write_nearby_tile 4
+
+ ; write furthest tile
+ map_full_draw_door_state TF_NE, TF_WE, TF_EE
+ map_full_draw_write_door_state 5, 3, ret
ret
@south:
map_full_draw_door_state TF_SE, TF_WE, TF_EE
inc b ; move one tile forward
_map_write_nearby_tile 2
+ push bc
call map_get_tile
+ pop bc
map_full_draw_door_state TF_SE, TF_WE, TF_EE
map_full_draw_write_door_state 3, 2, ret
+
+ inc b ; move one tile forward
+ _map_write_nearby_tile 4
+ call map_get_tile
+
+ map_full_draw_door_state TF_SE, TF_WE, TF_EE
+ map_full_draw_write_door_state 5, 3, ret
ret
@east:
map_full_draw_door_state TF_EE, TF_NE, TF_SE
inc c ; move one tile east
_map_write_nearby_tile 2
+ push bc
call map_get_tile
+ pop bc
map_full_draw_door_state TF_EE, TF_NE, TF_SE
- map_full_draw_write_door_state 3, 2, ret
+ map_full_draw_write_door_state 3, 3, ret
+
+ inc c ; move one tile east
+ _map_write_nearby_tile 4
+ call map_get_tile
+
+ map_full_draw_door_state TF_EE, TF_NE, TF_SE
+ map_full_draw_write_door_state 5, 3, ret
ret
@west:
map_full_draw_door_state TF_WE, TF_SE, TF_NE
dec c ; move one tile west
_map_write_nearby_tile 2
+ push bc
call map_get_tile
+ pop bc
map_full_draw_door_state TF_WE, TF_SE, TF_NE
map_full_draw_write_door_state 3, 2, ret
+
+ dec c ; move one tile west
+ _map_write_nearby_tile 4
+ call map_get_tile
+
+ map_full_draw_door_state TF_WE, TF_SE, TF_NE
+ map_full_draw_write_door_state 5, 3, ret
ret
; draws near doors
; clear far back door if _forward is > 1
ld a, [tmp_map_forward]
cp a, 2
- jr nz, @no_far_forward_door REL
+ jr c, @no_far_forward_door REL
ld hl, render_buffer + RENDER_BUF_W * 5 + 8
ld de, far_center_door
ld bc, RENDER_BUF_W-4
update_game_over:
ret
-
-update_game:
- ; clear oam
- ; TODO: only clear used OAM
- call shadow_oam_clear
- ; player should update even in debug mode
- call player_update
- call compass_draw
-
- ; tick rng every frame
- call rand
-
- call ui_update
-
- ; TODO: update map routine
-
+ ; draws an actor
+ ; inputs:
+ ; $1: near, far, furthest
+#macro _update_game_draw_act
; draw actors and props
; on nearby tiles
; if the ptr is not NULL
- ld a, [tile_far]
+ ld a, [tile_$1]
ld b, a
- ld a, [tile_far+1]
+ ld a, [tile_$1+1]
ld c, a
call map_get_tile
; hl = tile far
ld e, [hl]
ld d, a
or a, e ; check if it is null
- call nz, act_draw_nearby
+ call nz, act_draw_$1
pop hl
; load t_prop
ld e, [hl]
ld d, a
or a, e ; check if it is null
- call nz, act_draw_nearby
+ call nz, act_draw_$1
+#endmacro
+
+update_game:
+ ; clear oam
+ ; TODO: only clear used OAM
+ call shadow_oam_clear
+
+ ; player should update even in debug mode
+ call player_update
+ call compass_draw
+
+ ; tick rng every frame
+ call rand
+
+ call ui_update
+
+ ; TODO: update map routine
+ _update_game_draw_act near
+ _update_game_draw_act far
+ _update_game_draw_act furthest
ret
+
; draws a single tile
; inputs: