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
122
123
124
125
126
127
128
129
130
131
132
133
|
VendingMachineMenu::
ld hl, VendingMachineText1
call PrintText
ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
ld a, 3
ld [wMaxMenuItem], a
ld a, 5
ld [wTopMenuItemY], a
ld a, 1
ld [wTopMenuItemX], a
ld hl, wd730
set 6, [hl]
hlcoord 0, 3
ld b, 8
ld c, 12
call TextBoxBorder
call UpdateSprites
hlcoord 2, 5
ld de, DrinkText
call PlaceString
hlcoord 9, 6
ld de, DrinkPriceText
call PlaceString
ld hl, wd730
res 6, [hl]
call HandleMenuInput
bit BIT_B_BUTTON, a
jr nz, .notThirsty
ld a, [wCurrentMenuItem]
cp 3 ; chose Cancel?
jr z, .notThirsty
xor a
ldh [hMoney], a
ldh [hMoney + 2], a
ld a, $2
ldh [hMoney + 1], a
call HasEnoughMoney
jr nc, .enoughMoney
ld hl, VendingMachineText4
jp PrintText
.enoughMoney
call LoadVendingMachineItem
ldh a, [hVendingMachineItem]
ld b, a
ld c, 1
call GiveItem
jr nc, .BagFull
ld b, 60 ; number of times to play the "brrrrr" sound
.playDeliverySound
ld c, 2
call DelayFrames
push bc
ld a, SFX_PUSH_BOULDER
call PlaySound
pop bc
dec b
jr nz, .playDeliverySound
ld hl, VendingMachineText5
call PrintText
ld hl, hVendingMachinePrice + 2
ld de, wPlayerMoney + 2
ld c, $3
predef SubBCDPredef
ld a, MONEY_BOX
ld [wTextBoxID], a
jp DisplayTextBoxID
.BagFull
ld hl, VendingMachineText6
jp PrintText
.notThirsty
ld hl, VendingMachineText7
jp PrintText
VendingMachineText1:
text_far _VendingMachineText1
text_end
DrinkText:
db "FRESH WATER"
next "SODA POP"
next "LEMONADE"
next "CANCEL@"
DrinkPriceText:
db "¥200"
next "¥300"
next "¥350"
next "@"
VendingMachineText4:
text_far _VendingMachineText4
text_end
VendingMachineText5:
text_far _VendingMachineText5
text_end
VendingMachineText6:
text_far _VendingMachineText6
text_end
VendingMachineText7:
text_far _VendingMachineText7
text_end
LoadVendingMachineItem:
ld hl, VendingPrices
ld a, [wCurrentMenuItem]
add a
add a
ld d, 0
ld e, a
add hl, de
ld a, [hli]
ldh [hVendingMachineItem], a
ld a, [hli]
ldh [hVendingMachinePrice], a
ld a, [hli]
ldh [hVendingMachinePrice + 1], a
ld a, [hl]
ldh [hVendingMachinePrice + 2], a
ret
INCLUDE "data/items/vending_prices.asm"
|