2015-11-10 04:01:45 +00:00
|
|
|
InitMovementBuffer:: ; 1b1e
|
|
|
|
ld [wMovementBufferPerson], 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
|
2015-02-10 23:14:41 +00:00
|
|
|
ld [wd004], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, $7
|
2015-11-10 04:01:45 +00:00
|
|
|
ld [wd005], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, $d0
|
2015-11-10 04:01:45 +00:00
|
|
|
ld [wd006], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
; 1b35
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
DecrementMovementBufferCount:: ; 1b35
|
|
|
|
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
|
|
|
|
; 1b3f
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
AppendToMovementBuffer:: ; 1b3f
|
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
|
|
|
|
ld hl, MovementBuffer
|
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
; 1b50
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
AppendToMovementBufferNTimes:: ; 1b50
|
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
|
|
|
|
; 1b5f
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
ComputePathToWalkToPlayer:: ; 1b5f
|
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
|
|
|
|
; 1b92
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
.GetMovementData: ; 1b92
|
2013-11-26 11:44:05 +00:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
ld l, b
|
|
|
|
ld h, 0
|
2015-07-21 02:18:18 +00:00
|
|
|
rept 2
|
2013-11-26 11:44:05 +00:00
|
|
|
add hl, hl
|
2015-07-21 02:18:18 +00:00
|
|
|
endr
|
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
|
|
|
|
; 1ba5
|
|
|
|
|
2015-11-10 04:01:45 +00:00
|
|
|
.MovementData
|
|
|
|
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
|
2013-11-26 11:44:05 +00:00
|
|
|
; 1bb1
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Function1bb1:: ; 1bb1
|
2013-11-26 11:44:05 +00:00
|
|
|
push hl
|
|
|
|
push bc
|
2015-02-10 23:14:41 +00:00
|
|
|
ld hl, wcfa1
|
2013-11-26 11:44:05 +00:00
|
|
|
ld b, $8
|
|
|
|
.asm_1bb8
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
dec b
|
|
|
|
jr nz, .asm_1bb8
|
|
|
|
ld a, $1
|
2015-07-21 02:18:18 +00:00
|
|
|
rept 2
|
2013-11-26 11:44:05 +00:00
|
|
|
ld [hli], a
|
2015-07-21 02:18:18 +00:00
|
|
|
endr
|
2013-11-26 11:44:05 +00:00
|
|
|
xor a
|
2015-07-21 02:18:18 +00:00
|
|
|
rept 3
|
2013-11-26 11:44:05 +00:00
|
|
|
ld [hli], a
|
2015-07-21 02:18:18 +00:00
|
|
|
endr
|
2013-11-26 11:44:05 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
; 1bc9
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Function1bc9:: ; 1bc9
|
2013-11-26 11:44:05 +00:00
|
|
|
callab Function241a8
|
|
|
|
call Function1bdd
|
|
|
|
ret
|
|
|
|
; 1bd3
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Function1bd3:: ; 1bd3
|
2013-11-26 11:44:05 +00:00
|
|
|
callab Function241ab
|
|
|
|
call Function1bdd
|
|
|
|
ret
|
|
|
|
; 1bdd
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Function1bdd:: ; 1bdd
|
2013-11-26 11:44:05 +00:00
|
|
|
push bc
|
|
|
|
push af
|
2015-10-16 17:35:43 +00:00
|
|
|
ld a, [hJoyLast]
|
|
|
|
and D_PAD
|
2013-11-26 11:44:05 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, [hJoyPressed]
|
2015-10-16 17:35:43 +00:00
|
|
|
and BUTTONS
|
2013-11-26 11:44:05 +00:00
|
|
|
or b
|
|
|
|
ld b, a
|
|
|
|
pop af
|
|
|
|
ld a, b
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
; 1bee
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Function1bee:: ; 1bee
|
2015-02-10 23:14:41 +00:00
|
|
|
ld hl, wcfac
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld [hl], $ec
|
|
|
|
ret
|
|
|
|
; 1bf7
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Function1bf7:: ; 1bf7
|
2015-02-10 23:14:41 +00:00
|
|
|
ld hl, wcfac
|
2013-11-26 11:44:05 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld [hl], $7f
|
|
|
|
ret
|
|
|
|
; 1c00
|
|
|
|
|