ld b, a
ld a, [de]
add a, OBJ_OFF_Y
- inc de ; de = y_hi
add a, b ; a = y postion
- ld b, a
- ld a, [de] ; a = y_hi
- adjust_y_row
-
inc de ; de = x pos
ld [hl+], a
; if flags == 0 the rectangle is free
.de r_flags, 1
.de r_pos_y, 1
-.de r_pos_y_hi, 1
.de r_pos_x, 1
.de r_h, 1
.de r_w, 1
.de act_flags, 1
.de act_pos_y, 1 ; y/x position
-.de act_pos_y_hi, 1 ; high byte of 16 bit y position
.de act_pos_x, 1
; custom parameter
; placeholder for y, row and x
; since those are set at runtime
- .db 0, 0, 0
+ .db 0, 0
.db $3
; placeholder for collision rectangle
; since those are runtime values
- .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0
#endmacro
; defines a map object
dw $4
#endmacro
- ; adjusts an input position
- ; to draw correctly based on the current map row
- ; inputs:
- ; a: hi y position
- ; b: unadjusted lo y position
- ; returns:
- ; a: real y position (or 0 if out of bounds)
- ; uses: a, b, c
-#macro adjust_y_row
-.beginscope
- ld c, a
- ld a, [map_curr_row]
- div16 a ; 16 rows per screen page -> row count to hi y position
- cp a, c
- jr c, @zero REL
-
- ld a, b
- jr @done REL
-@zero:
- xor a, a
-@done:
-.endscope
-#endmacro
; defines a rectangle
; inputs:
ld a, 0
ld [player+act_pos_x], a
- ld a, 0
- ld [player+act_pos_y_hi], a
-
ld a, 0x30 ; initial next scroll
ld [player_next_scroll_y], a
ret
; b/c: y/x movement
; returns:
; b/c: new y/x position
- ; d: new y hi position
player_stage_move_p:
ld a, [player+act_pos_y]
add a, b
ld b, a
- ld a, [player+act_pos_y_hi]
- adc a, 0
- ld [player+act_pos_y_hi], a
- ld d, a
-
ld a, [player+act_pos_x]
add a, c
ld c, a
; b/c: y/x movement
; returns:
; b/c: new y/x position
- ; d: new y hi position
player_stage_move_n:
ld a, [player+act_pos_y]
sub a, b
ld b, a
- ld a, [player+act_pos_y_hi]
- sbc a, 0
- ld [player+act_pos_y_hi], a
- ld d, a
-
ld a, [player+act_pos_x]
sub a, c
ld c, a
; moves scroll and performs map loads if needed
; inputs:
; b/c: new y/x position
- ; d: new y hi position
player_try_move:
ld a, b
ld [player+act_pos_y], a
ld a, c
ld [player+act_pos_x], a
- ld a, d
- ld [player+act_pos_y_hi], a
ret
; draws the special player actor
+ ; limitations:
+ ; positions can never wrap around a page
+ ; in this engine
+ ; all positions are 8-bit only
+ ; great care must be taken to avoid
+ ; collisions from overlapping a page swap!
+
; attempts to add a rectangle
; to the rectangle buffer
ld a, b
ld [hl+], a
- ; wirte y hi
- xor a, a
- ld [hl+], a
-
; wirte x
ld a, c
ld [hl+], a
cp a, 0x70
call nc, actor_despawn
pop af
-
- ld a, [hl]
- adc a, 0
- ld [hl], a
pop hl
add a, 1
ld [player+act_pos_y], a
- ld a, [player+act_pos_y_hi]
- adc a, 0
- ld [player+act_pos_y_hi], a
-
; TODO: adjust rectangles
ret