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