summaryrefslogtreecommitdiff
path: root/home/movement.asm
blob: c15b6aa5034e5b94945e4d218559e465d2ec3b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
InitMovementBuffer::
	ld [wMovementBufferPerson], a
	xor a
	ld [wMovementBufferCount], a
	ld a, $0
	ld [wceef], a
	ld a, wMovementBuffer % $100
	ld [wcef0], a
	ld a, wMovementBuffer / $100
	ld [wcef1], a
	ret

DecrementMovementBufferCount::
	ld a, [wMovementBufferCount]
	and a
	ret z
	dec a
	ld [wMovementBufferCount], a
	ret

AppendToMovementBuffer:: ; 19dc (0:19dc)
	push hl
	push de
	ld hl, wMovementBufferCount
	ld e, [hl]
	inc [hl]
	ld d, $0
	ld hl, wMovementBuffer
	add hl, de
	ld [hl], a
	pop de
	pop hl
	ret

AppendToMovementBufferNTimes:: ; 19ed (0:19ed)
	push af
	ld a, c
	and a
	jr nz, .asm_19f4
	pop af
	ret

.asm_19f4
	pop af
.asm_19f5
	call AppendToMovementBuffer
	dec c
	jr nz, .asm_19f5
	ret

ComputePathToWalkToPlayer::
	push af
	ld a, b
	sub d
	ld h, $2
	jr nc, .asm_1a07
	dec a
	cpl
	ld h, $3
.asm_1a07
	ld d, a
	ld a, c
	sub e
	ld l, $1
	jr nc, .asm_1a12
	dec a
	cpl
	ld l, $0
.asm_1a12
	ld e, a
	cp d
	jr nc, .asm_1a1c
	ld a, h
	ld h, l
	ld l, a
	ld a, d
	ld d, e
	ld e, a
.asm_1a1c
	pop af
	ld b, a
	ld a, h
	call WalkToPlayer_GetMovementByte
	ld c, d
	call AppendToMovementBufferNTimes
	ld a, l
	call WalkToPlayer_GetMovementByte
	ld c, e
	call AppendToMovementBufferNTimes
	ret

WalkToPlayer_GetMovementByte:: ; 1a2f (0:1a2f)
	push de
	push hl
	ld l, b
	ld h, $0
	add hl, hl
	add hl, hl
	ld e, a
	ld d, $0
	add hl, de
	ld de, .MovementData
	add hl, de
	ld a, [hl]
	pop hl
	pop de
	ret

.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