2018-06-24 14:09:41 +00:00
|
|
|
InitMovementBuffer::
|
2017-12-24 18:46:34 +00:00
|
|
|
ld [wMovementBufferObject], a
|
2013-11-26 11:44:05 +00:00
|
|
|
xor a
|
2015-11-10 04:01:45 +00:00
|
|
|
ld [wMovementBufferCount], a
|
|
|
|
ld a, $0 ; useless
|
2017-12-10 00:41:03 +00:00
|
|
|
ld [wUnusedMovementBufferBank], a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, LOW(wMovementBuffer)
|
2017-12-10 00:41:03 +00:00
|
|
|
ld [wUnusedMovementBufferPointer], a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, HIGH(wMovementBuffer)
|
2017-12-10 00:41:03 +00:00
|
|
|
ld [wUnusedMovementBufferPointer + 1], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
DecrementMovementBufferCount::
|
2015-11-10 04:01:45 +00:00
|
|
|
ld a, [wMovementBufferCount]
|
2013-11-26 11:44:05 +00:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec a
|
2015-11-10 04:01:45 +00:00
|
|
|
ld [wMovementBufferCount], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
AppendToMovementBuffer::
|
2013-11-26 11:44:05 +00:00
|
|
|
push hl
|
|
|
|
push de
|
2015-11-10 04:01:45 +00:00
|
|
|
ld hl, wMovementBufferCount
|
2013-11-26 11:44:05 +00:00
|
|
|
ld e, [hl]
|
|
|
|
inc [hl]
|
|
|
|
ld d, 0
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wMovementBuffer
|
2013-11-26 11:44:05 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
AppendToMovementBufferNTimes::
|
2013-11-26 11:44:05 +00:00
|
|
|
push af
|
|
|
|
ld a, c
|
|
|
|
and a
|
2015-11-10 04:01:45 +00:00
|
|
|
jr nz, .okay
|
2013-11-26 11:44:05 +00:00
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
.okay
|
2013-11-26 11:44:05 +00:00
|
|
|
pop af
|
2015-11-10 04:01:45 +00:00
|
|
|
.loop
|
|
|
|
call AppendToMovementBuffer
|
2013-11-26 11:44:05 +00:00
|
|
|
dec c
|
2015-11-10 04:01:45 +00:00
|
|
|
jr nz, .loop
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ComputePathToWalkToPlayer::
|
2013-11-26 11:44:05 +00:00
|
|
|
push af
|
2015-11-10 04:01:45 +00:00
|
|
|
; compare x coords, load left/right into h, and x distance into d
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, b
|
|
|
|
sub d
|
2015-11-10 04:01:45 +00:00
|
|
|
ld h, LEFT
|
|
|
|
jr nc, .got_x_distance
|
2013-11-26 11:44:05 +00:00
|
|
|
dec a
|
|
|
|
cpl
|
2015-11-10 04:01:45 +00:00
|
|
|
ld h, RIGHT
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
.got_x_distance
|
2013-11-26 11:44:05 +00:00
|
|
|
ld d, a
|
2015-11-10 04:01:45 +00:00
|
|
|
; compare y coords, load up/down into l, and y distance into e
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, c
|
|
|
|
sub e
|
2015-11-10 04:01:45 +00:00
|
|
|
ld l, UP
|
|
|
|
jr nc, .got_y_distance
|
2013-11-26 11:44:05 +00:00
|
|
|
dec a
|
|
|
|
cpl
|
2015-11-10 04:01:45 +00:00
|
|
|
ld l, DOWN
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
.got_y_distance
|
2013-11-26 11:44:05 +00:00
|
|
|
ld e, a
|
2015-11-10 04:01:45 +00:00
|
|
|
; if the x distance is less than the y distance, swap h and l, and swap d and e
|
2013-11-26 11:44:05 +00:00
|
|
|
cp d
|
2015-11-10 04:01:45 +00:00
|
|
|
jr nc, .done
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, h
|
|
|
|
ld h, l
|
|
|
|
ld l, a
|
|
|
|
ld a, d
|
|
|
|
ld d, e
|
|
|
|
ld e, a
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
.done
|
2013-11-26 11:44:05 +00:00
|
|
|
pop af
|
|
|
|
ld b, a
|
2015-11-10 04:01:45 +00:00
|
|
|
; Add movement in the longer direction first...
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, h
|
2015-11-10 04:01:45 +00:00
|
|
|
call .GetMovementData
|
2013-11-26 11:44:05 +00:00
|
|
|
ld c, d
|
2015-11-10 04:01:45 +00:00
|
|
|
call AppendToMovementBufferNTimes
|
|
|
|
; ... then add the shorter direction.
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, l
|
2015-11-10 04:01:45 +00:00
|
|
|
call .GetMovementData
|
2013-11-26 11:44:05 +00:00
|
|
|
ld c, e
|
2015-11-10 04:01:45 +00:00
|
|
|
call AppendToMovementBufferNTimes
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.GetMovementData:
|
2013-11-26 11:44:05 +00:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
ld l, b
|
|
|
|
ld h, 0
|
|
|
|
add hl, hl
|
2016-05-04 15:46:23 +00:00
|
|
|
add hl, hl
|
2013-11-26 11:44:05 +00:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
add hl, de
|
2015-11-10 04:01:45 +00:00
|
|
|
ld de, .MovementData
|
2013-11-26 11:44:05 +00:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.MovementData:
|
2016-05-14 17:46:14 +00:00
|
|
|
slow_step DOWN
|
|
|
|
slow_step UP
|
|
|
|
slow_step LEFT
|
|
|
|
slow_step RIGHT
|
|
|
|
step DOWN
|
|
|
|
step UP
|
|
|
|
step LEFT
|
|
|
|
step RIGHT
|
|
|
|
big_step DOWN
|
|
|
|
big_step UP
|
|
|
|
big_step LEFT
|
|
|
|
big_step RIGHT
|