vending_machine.asm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. VendingMachineMenu:
  2. ld hl, VendingMachineText1
  3. call PrintText
  4. ld a, MONEY_BOX
  5. ld [wTextBoxID], a
  6. call DisplayTextBoxID
  7. xor a
  8. ld [wCurrentMenuItem], a
  9. ld [wLastMenuItem], a
  10. ld a, A_BUTTON | B_BUTTON
  11. ld [wMenuWatchedKeys], a
  12. ld a, 3
  13. ld [wMaxMenuItem], a
  14. ld a, 5
  15. ld [wTopMenuItemY], a
  16. ld a, 1
  17. ld [wTopMenuItemX], a
  18. ld hl, wd730
  19. set 6, [hl]
  20. coord hl, 0, 3
  21. ld b, 8
  22. ld c, 12
  23. call TextBoxBorder
  24. call UpdateSprites
  25. coord hl, 2, 5
  26. ld de, DrinkText
  27. call PlaceString
  28. coord hl, 9, 6
  29. ld de, DrinkPriceText
  30. call PlaceString
  31. ld hl, wd730
  32. res 6, [hl]
  33. call HandleMenuInput
  34. bit 1, a ; pressed B?
  35. jr nz, .notThirsty
  36. ld a, [wCurrentMenuItem]
  37. cp 3 ; chose Cancel?
  38. jr z, .notThirsty
  39. xor a
  40. ld [hMoney], a
  41. ld [hMoney + 2], a
  42. ld a, $2
  43. ld [hMoney + 1], a
  44. call HasEnoughMoney
  45. jr nc, .enoughMoney
  46. ld hl, VendingMachineText4
  47. jp PrintText
  48. .enoughMoney
  49. call LoadVendingMachineItem
  50. ld a, [hVendingMachineItem]
  51. ld b, a
  52. ld c, 1
  53. call GiveItem
  54. jr nc, .BagFull
  55. ld b, 60 ; number of times to play the "brrrrr" sound
  56. .playDeliverySound
  57. ld c, 2
  58. call DelayFrames
  59. push bc
  60. ld a, SFX_PUSH_BOULDER
  61. call PlaySound
  62. pop bc
  63. dec b
  64. jr nz, .playDeliverySound
  65. ld hl, VendingMachineText5
  66. call PrintText
  67. ld hl, hVendingMachinePrice + 2
  68. ld de, wPlayerMoney + 2
  69. ld c, $3
  70. predef SubBCDPredef
  71. ld a, MONEY_BOX
  72. ld [wTextBoxID], a
  73. jp DisplayTextBoxID
  74. .BagFull
  75. ld hl, VendingMachineText6
  76. jp PrintText
  77. .notThirsty
  78. ld hl, VendingMachineText7
  79. jp PrintText
  80. VendingMachineText1:
  81. TX_FAR _VendingMachineText1
  82. db "@"
  83. DrinkText:
  84. db "FRESH WATER"
  85. next "SODA POP"
  86. next "LEMONADE"
  87. next "CANCEL@"
  88. DrinkPriceText:
  89. db "¥200"
  90. next "¥300"
  91. next "¥350"
  92. next "@"
  93. VendingMachineText4:
  94. TX_FAR _VendingMachineText4
  95. db "@"
  96. VendingMachineText5:
  97. TX_FAR _VendingMachineText5
  98. db "@"
  99. VendingMachineText6:
  100. TX_FAR _VendingMachineText6
  101. db "@"
  102. VendingMachineText7:
  103. TX_FAR _VendingMachineText7
  104. db "@"
  105. LoadVendingMachineItem:
  106. ld hl, VendingPrices
  107. ld a, [wCurrentMenuItem]
  108. add a
  109. add a
  110. ld d, 0
  111. ld e, a
  112. add hl, de
  113. ld a, [hli]
  114. ld [hVendingMachineItem], a
  115. ld a, [hli]
  116. ld [hVendingMachinePrice], a
  117. ld a, [hli]
  118. ld [hVendingMachinePrice + 1], a
  119. ld a, [hl]
  120. ld [hVendingMachinePrice + 2], a
  121. ret
  122. VendingPrices:
  123. db FRESH_WATER
  124. money 200
  125. db SODA_POP
  126. money 300
  127. db LEMONADE
  128. money 350