L5-build-cookie-stacker.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // on B button pressed
  2. controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
  3. if (canStack == true) {
  4. sugarCookie = sprites.create(assets.image`myImage0`, SpriteKind.Player)
  5. sugarCookie.setPosition(110, sugarCookieY)
  6. sugarCookieY += 0 - 2
  7. sugarCookieStack += 1
  8. }
  9. })
  10. // on A button pressed
  11. controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
  12. if (canStack == true) {
  13. chocCookie = sprites.create(assets.image`myImage`, SpriteKind.Player)
  14. chocCookie.setPosition(50, chocCookieY)
  15. chocCookieY += 0 - 2
  16. chocCookieStack += 1
  17. }
  18. })
  19. // on countdown end
  20. info.onCountdownEnd(function () {
  21. canStack = false
  22. askForNumber()
  23. pause(1000)
  24. music.play(music.melodyPlayable(music.powerUp), music.PlaybackMode.UntilDone)
  25. cookieStackTotal = chocCookieStack + sugarCookieStack
  26. if (playerGuess == cookieStackTotal) {
  27. game.showLongText("You geussed it!" + cookieStackTotal + " cookies were stacked!", DialogLayout.Bottom)
  28. } else if (playerGuess != cookieStackTotal) {
  29. game.showLongText("Wow! You geussed " + playerGuess + " but you acctulay stacked " + cookieStackTotal + " cookies instead!", DialogLayout.Bottom)
  30. game.showLongText("Wow! You geussed corectly " + cookieStackTotal + " cookies were stacked", DialogLayout.Bottom)
  31. }
  32. game.showLongText("Wow! You geussed " + playerGuess + " but you acctulay stacked" + cookieStackTotal + " cookies instead!", DialogLayout.Bottom)
  33. })
  34. function askForNumber () {
  35. playerGuess = game.askForNumber("how many cookies did you think you stacked?", 2)
  36. }
  37. let playerGuess = 0
  38. let cookieStackTotal = 0
  39. let chocCookieStack = 0
  40. let chocCookie: Sprite = null
  41. let sugarCookieStack = 0
  42. let sugarCookie: Sprite = null
  43. let sugarCookieY = 0
  44. let chocCookieY = 0
  45. let canStack = false
  46. // set up
  47. scene.setBackgroundColor(5)
  48. game.showLongText("Stack cookies then geuss how many you stacked!", DialogLayout.Bottom)
  49. // plate sprite code
  50. let plate1 = sprites.create(img`
  51. ...............bbbbbbbbbbbbbbbbbbb...............
  52. ...........bbbbdd111111111111111ddbbbb...........
  53. ........bbbd1111111111111111111111111dbbb........
  54. ......bbd11111111dddddddddddddd111111111dbb......
  55. ....bbd1111111ddd11111111111111dddd1111111dbb....
  56. ...bd111111ddd111111111111111111111ddd111111db...
  57. ..bd11111ddd111ddddddddddddddddddd111ddd11111db..
  58. .bd11111dd111dddd111111111111111dddd111dd11111db.
  59. .b11111d111ddd111111111111111111111ddd111d11111b.
  60. bd11111d1ddd1111111111111111111111111ddd1111111db
  61. b11111d1ddd111111111111111111111111111ddd1d11111b
  62. b11111ddddd111111111111111111111111111ddddd11111b
  63. b11111ddddd111111111111111111111111111dddbd11111b
  64. b111111dddd111111111111111111111111111dddb111111b
  65. bd111111dddd1111111111111111111111111dddbd11111db
  66. .b1111111dddd11111111111111111111111dddbd111111b.
  67. .bd1111111dbbdd1111111111111111111dddbbd111111db.
  68. ..bd11111111dbbdd111111111111111dddbbd1111111db..
  69. ...bd111111111dbbbbbbdddddddddddddd111111111db...
  70. ....bbd11111111111dbbbbbbbbbddd11111111111dbb....
  71. ......bbdd11111111111111111111111111111ddbb......
  72. ........bbbdd11111111111111111111111ddbbb........
  73. ...........bbbbbddd11111111111dddbbbbb...........
  74. ................bbbbbbbbbbbbbbbbb................
  75. `, SpriteKind.Player)
  76. plate1.setPosition(50, 100)
  77. let plate2 = sprites.create(img`
  78. ...............bbbbbbbbbbbbbbbbbbb...............
  79. ...........bbbbdd111111111111111ddbbbb...........
  80. ........bbbd1111111111111111111111111dbbb........
  81. ......bbd11111111dddddddddddddd111111111dbb......
  82. ....bbd1111111ddd11111111111111dddd1111111dbb....
  83. ...bd111111ddd111111111111111111111ddd111111db...
  84. ..bd11111ddd111ddddddddddddddddddd111ddd11111db..
  85. .bd11111dd111dddd111111111111111dddd111dd11111db.
  86. .b11111d111ddd111111111111111111111ddd111d11111b.
  87. bd11111d1ddd1111111111111111111111111ddd1111111db
  88. b11111d1ddd111111111111111111111111111ddd1d11111b
  89. b11111ddddd111111111111111111111111111ddddd11111b
  90. b11111ddddd111111111111111111111111111dddbd11111b
  91. b111111dddd111111111111111111111111111dddb111111b
  92. bd111111dddd1111111111111111111111111dddbd11111db
  93. .b1111111dddd11111111111111111111111dddbd111111b.
  94. .bd1111111dbbdd1111111111111111111dddbbd111111db.
  95. ..bd11111111dbbdd111111111111111dddbbd1111111db..
  96. ...bd111111111dbbbbbbdddddddddddddd111111111db...
  97. ....bbd11111111111dbbbbbbbbbddd11111111111dbb....
  98. ......bbdd11111111111111111111111111111ddbb......
  99. ........bbbdd11111111111111111111111ddbbb........
  100. ...........bbbbbddd11111111111dddbbbbb...........
  101. ................bbbbbbbbbbbbbbbbb................
  102. `, SpriteKind.Player)
  103. plate2.setPosition(110, 100)
  104. // varibel set up
  105. canStack = true
  106. info.startCountdown(10)
  107. chocCookieY = 100
  108. sugarCookieY = 100