; bc = attribute table
ret
+
+ ; attempts to move an actor
+ ; to a new y/x position.
+ ; aborts the move if the position
+ ; is inside a wall tile or the tile is already occupied
+ ; unsets t_act on current tile. sets t_act on new tile
+ ; inputs:
+ ; de: actor ptr
+ ; bc: new position
+ ; returns:
+ ; a: 0 -> moved
+ ; a: 1 -> not moved
+ ; col_tile: ptr to new tile
+act_move_to:
+ ld hl, act_pos_y
+ add hl, de
+
+ push hl
+ push bc
+
+ call map_get_tile
+ ; write col tile
+ ld a, h
+ ld [col_tile], a
+ ld a, l
+ ld [col_tile+1], a
+
+ ; hl = tile
+ push hl
+
+ ; check flags
+ ld de, t_flags0
+ add hl, de
+ ld a, [hl]
+ ; if wall flag do not move
+ and a, TF0_WALL
+ jp nz, @hit
+ pop hl
+
+ ; check actor ptr
+ ld de, t_act
+ add hl, de
+
+ ; if not NULL do not move
+ ld a, [hl+]
+ or a, [hl]
+ jp nz, @hit
+
+
+ pop bc
+ pop de ; de = actor ptr
+
+
+ ; write new position
+ ld a, b
+ ld [de], a
+ inc de
+ ld a, c
+ ld [de], a
+
+ ld a, 0
+ ret
+@hit:
+ ; clean up stack
+ pop de
+ pop de
+ pop de
+ ld a, 1
+ ret
call vblank_wait
call enableinterrupts
+ call map_uncover
+
call map_full_draw
call update_render
+
ret
; loads all map related data that
call update_render
ret
+ ; uncovers tiles starting at player position
+ ; and moving in all non-uncovered tiles until walls are hit
+map_uncover:
+ ret
+
; nop map rotuine
map_r_nop:
ret
+
; sets up the player actor
player_init:
- xor a, a
+ ld a, 2
ld [player+act_pos_y], a
ld [player+act_pos_x], a
jr z, @not_left REL
ld a, [player+act_pos_x]
dec a
- ld [player+act_pos_x], a
- call map_full_draw
+ ld c, a
+
+ ld a, [player+act_pos_y]
+ ld b, a
+
+
+ ld de, player
+ call act_move_to
+
+ cp a, 0
+ jp z, player_moved
+ jp player_collided
@not_left:
ld b, DIRRIGHT
jr z, @not_right REL
ld a, [player+act_pos_x]
inc a
- ld [player+act_pos_x], a
- call map_full_draw
+ ld c, a
+
+ ld a, [player+act_pos_y]
+ ld b, a
+
+ ld de, player
+ call act_move_to
+
+ cp a, 0
+ jp z, player_moved
+ jp player_collided
@not_right:
ld b, DIRUP
jr z, @not_up REL
ld a, [player+act_pos_y]
dec a
- ld [player+act_pos_y], a
- call map_full_draw
+ ld b, a
+
+ ld a, [player+act_pos_x]
+ ld c, a
+
+ ld de, player
+ call act_move_to
+
+ cp a, 0
+ jp z, player_moved
+ jp player_collided
@not_up:
ld b, DIRDOWN
jr z, @not_down REL
ld a, [player+act_pos_y]
inc a
- ld [player+act_pos_y], a
- call map_full_draw
+ ld b, a
+
+ ld a, [player+act_pos_x]
+ ld c, a
+
+ ld de, player
+ call act_move_to
+
+ cp a, 0
+ jp z, player_moved
+ jp player_collided
@not_down:
ret
+ ; code to run when player has collided
+player_collided:
+ ld a, [col_tile]
+ ld d, a
+ ld a, [col_tile+1]
+ ld e, a
+ ; de = collision tile
+
+ ld a, [de]
+ cp a, TT_DOOR ; if its a door run special code
+ jp z, @open_door
+
+ ret
+@open_door:
+ ld a, TT_FLOOR
+ ld [de], a
+
+ ld hl, t_flags0
+ add hl, de
+ ; clear all flags
+ xor a, a
+ ld [hl], a
+
+ call map_uncover
+ call map_full_draw
+ ret
+
+ ; code to run when player has moved
+player_moved:
+ call map_full_draw
+ ret