xor a, a
ld [de], a
ret
+
+ ; writes actor default collider
+ ; bsed on an input position
+ ; writes the collider to dst
+ ; e.g. use with actor's real rectangle
+ ; if real collision should be written
+ ; use with tmp_rect for collision tests before moving
+ ; inputs:
+ ; a: collision mask
+ ; b/c: y/x position of actor
+ ; hl: destination rectangle
+actor_write_default_collider:
+ ld [hl+], a ; mask
+ ld a, b
+ ld [hl+], a ; y pos
+ ld a, c
+ ld [hl+], a ; x pos
+
+ ld a, 16 ; width/height
+ ld [hl+], a ; height
+ ld [hl+], a ; width
+ ret
+
+ ; tests movement against all collision rectangles
+ ; inputs:
+ ; a: collision mask
+ ; de: current actor (this actor is skipped)
+ ; tmp_rect: new collision rectangle
+ ; returns:
+ ; a == 0: no collision
+ ; a == 1: collision
+ ; hl: if collided with an actor points to the actor hit, otherwise NULL
+actor_test_movement:
+ ret
call player_try_move
@not_right:
+ ; write collider for this frame
+ ld a, [player+act_pos_y]
+ ld b, a
+ ld a, [player+act_pos_x]
+ ld c, a
+ ld a, RF_PLAYER
+ ld hl, player+act_rect
+ call actor_write_default_collider
+
+
ret
#define PLAYER_SPRITE_IDLE1 0x8D
; inputs:
; b/c: new y/x position
player_try_move:
+ ; write temporary collider
+ push bc
+ ld a, RF_PLAYER
+ ld hl, tmp_rect
+ call actor_write_default_collider
+
+ ; test collision agains walls and enemies
+ ld a, RF_WALL | RF_ENEMY
+ ld de, player
+ call actor_test_movement
+ pop bc
+
ld a, b
ld [player+act_pos_y], a
and a, d
; exit if mask is no match
jp z, @no_collision_mask_match
+
+ push hl
+ call rect_tr
+ pop hl
ret
actors: .adv act_size * ACTS_MAX
map_objs: .adv mo_size * MAP_OBJ_MAX
rectangles: .adv r_size * RECT_MAX
+
+ ; temporary rectangle used for collision checks
+ ; during movement
+tmp_rect: .adv r_size
; current row that is being drawn
map_curr_row: .adv 1