summaryrefslogtreecommitdiff
path: root/home/movement.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/movement.asm')
-rw-r--r--home/movement.asm60
1 files changed, 34 insertions, 26 deletions
diff --git a/home/movement.asm b/home/movement.asm
index c15b6aa5..025fdeb6 100644
--- a/home/movement.asm
+++ b/home/movement.asm
@@ -1,12 +1,12 @@
InitMovementBuffer::
- ld [wMovementBufferPerson], a
+ ld [wMovementBufferObject], a
xor a
ld [wMovementBufferCount], a
- ld a, $0
+ ld a, $0 ; useless
ld [wceef], a
- ld a, wMovementBuffer % $100
+ ld a, LOW(wMovementBuffer)
ld [wcef0], a
- ld a, wMovementBuffer / $100
+ ld a, HIGH(wMovementBuffer)
ld [wcef1], a
ret
@@ -18,13 +18,13 @@ DecrementMovementBufferCount::
ld [wMovementBufferCount], a
ret
-AppendToMovementBuffer:: ; 19dc (0:19dc)
+AppendToMovementBuffer::
push hl
push de
ld hl, wMovementBufferCount
ld e, [hl]
inc [hl]
- ld d, $0
+ ld d, 0
ld hl, wMovementBuffer
add hl, de
ld [hl], a
@@ -32,72 +32,80 @@ AppendToMovementBuffer:: ; 19dc (0:19dc)
pop hl
ret
-AppendToMovementBufferNTimes:: ; 19ed (0:19ed)
+AppendToMovementBufferNTimes::
push af
ld a, c
and a
- jr nz, .asm_19f4
+ jr nz, .okay
pop af
ret
-.asm_19f4
+.okay
pop af
-.asm_19f5
+.loop
call AppendToMovementBuffer
dec c
- jr nz, .asm_19f5
+ jr nz, .loop
ret
ComputePathToWalkToPlayer::
push af
+; compare x coords, load left/right into h, and x distance into d
ld a, b
sub d
- ld h, $2
- jr nc, .asm_1a07
+ ld h, LEFT
+ jr nc, .got_x_distance
dec a
cpl
- ld h, $3
-.asm_1a07
+ ld h, RIGHT
+
+.got_x_distance
ld d, a
+; compare y coords, load up/down into l, and y distance into e
ld a, c
sub e
- ld l, $1
- jr nc, .asm_1a12
+ ld l, UP
+ jr nc, .got_y_distance
dec a
cpl
- ld l, $0
-.asm_1a12
+ ld l, DOWN
+
+.got_y_distance
ld e, a
+; if the x distance is less than the y distance, swap h and l, and swap d and e
cp d
- jr nc, .asm_1a1c
+ jr nc, .done
ld a, h
ld h, l
ld l, a
ld a, d
ld d, e
ld e, a
-.asm_1a1c
+
+.done
pop af
ld b, a
+; Add movement in the longer direction first...
ld a, h
- call WalkToPlayer_GetMovementByte
+ call .GetMovementData
ld c, d
call AppendToMovementBufferNTimes
+; ... then add the shorter direction.
ld a, l
- call WalkToPlayer_GetMovementByte
+ call .GetMovementData
ld c, e
call AppendToMovementBufferNTimes
ret
-WalkToPlayer_GetMovementByte:: ; 1a2f (0:1a2f)
+.GetMovementData:
push de
push hl
ld l, b
- ld h, $0
+ ld h, 0
add hl, hl
add hl, hl
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
ld de, .MovementData
add hl, de