You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. pico-8 cartridge // http://www.pico-8.com
  2. version 32
  3. __lua__
  4. -- game code
  5. function init_world()
  6. drops = {}
  7. frozen_drops = {}
  8. player = {}
  9. player.x = 64
  10. player.y = 16
  11. player.spr = 1
  12. end
  13. function _init()
  14. -- button-press initial delay
  15. poke(0x5f5c, 1)
  16. -- button-press repeat
  17. poke(0x5f5d, 2)
  18. init_world()
  19. end
  20. function _update()
  21. update_drops()
  22. update_player()
  23. end
  24. function update_player()
  25. if btn(0) then
  26. player.x -= 1
  27. end
  28. if btn(1) then
  29. player.x += 1
  30. end
  31. if btn(2) then
  32. player.y -= 1
  33. end
  34. if btn(3) then
  35. player.y += 1
  36. end
  37. if (player.y < 0) player.y = 0
  38. if (player.y > 127) player.y = 127
  39. if (player.x < 0) player.x = 0
  40. if (player.x > 127) player.x = 127
  41. if (btnp(🅾️)) then
  42. drop = {}
  43. drop.x = player.x
  44. drop.y = player.y
  45. drop.momentum = 0
  46. drop.fall_time = 0
  47. found_drop = false
  48. for i=1,#drops do
  49. if (drops[i].x == player.x and drops[i].y == player.y) then
  50. found_drop = true
  51. break
  52. end
  53. end
  54. if (not found_drop) then
  55. add(drops, drop)
  56. end
  57. end
  58. end
  59. function update_drops()
  60. cls()
  61. draw_drops()
  62. for i=1,#drops do
  63. drop = drops[i]
  64. try_left = rnd() < 0.5
  65. if drop.momentum == 0 then
  66. if try_left then
  67. drop.momentum = -1
  68. else
  69. drop.momentum = 1
  70. end
  71. end
  72. if pget(drop.x, drop.y+1) == black then
  73. drop.y += 1
  74. drop.momentum = 0
  75. drop.fall_time = 0
  76. elseif try_left and drop.x > 0 and
  77. pget(drop.x-1, drop.y+1) == black then
  78. drop.x -= 1
  79. drop.y += 1
  80. drop.fall_time = 0
  81. elseif drop.x < 127 and
  82. pget(drop.x+1, drop.y+1) == black then
  83. drop.x += 1
  84. drop.y += 1
  85. drop.fall_time = 0
  86. elseif drop.momentum == -1 then
  87. drop.fall_time += 1
  88. if drop.x > 0 and pget(drop.x-1, drop.y) == black then
  89. drop.x -= 1
  90. else
  91. drop.momentum = 0
  92. end
  93. elseif drop.momentum == 1 then
  94. drop.fall_time += 1
  95. if drop.x < 127 and pget(drop.x+1, drop.y) == black then
  96. drop.x += 1
  97. else
  98. drop.momentum = 0
  99. end
  100. end
  101. if drop.y > 127 then drop.y = 127 end
  102. end
  103. new_drops = {}
  104. for i=1,#drops do
  105. drop = drops[i]
  106. if drop.fall_time > 64 then
  107. add(frozen_drops, drop)
  108. else
  109. add(new_drops, drop)
  110. end
  111. end
  112. drops = new_drops
  113. end
  114. function _draw()
  115. cls()
  116. draw_drops()
  117. draw_player()
  118. --print("cpu: "..stat(1), 0, 0, light_gray)
  119. --print("drops: "..#drops, 0, 6, light_gray)
  120. --print("frozen: "..#frozen_drops, 0, 12, light_gray)
  121. end
  122. function draw_player()
  123. spr(player.spr,player.x-1,player.y-1)
  124. end
  125. function draw_drops()
  126. foreach(frozen_drops,draw_drop)
  127. foreach(drops,draw_drop)
  128. circfill(94, 94, 3, green)
  129. circfill(98, 105, 2, orange)
  130. line(98, 115, 98, 122, pink)
  131. line(105, 122)
  132. line(105, 115)
  133. line(70, 64, 90, 60, dark_purple)
  134. line(70, 65, 90, 61, dark_purple)
  135. line(60, 30, 80, 50, indigo)
  136. line(60, 31, 80, 51, indigo)
  137. line(64, 90, 74, 90)
  138. line(70, 86)
  139. line(68, 86, 64, 90)
  140. ovalfill(54, 95, 74, 100, pink)
  141. line(70, 116, 93, 112, green)
  142. line(70, 115, 93, 111, green)
  143. line(70, 116, 60, 112, green)
  144. line(70, 115, 60, 111, green)
  145. print("hello everybody", 63, 58, yellow)
  146. end
  147. function draw_drop(drop)
  148. pset(drop.x, drop.y, blue)
  149. end
  150. -->8
  151. -- library
  152. black = 0
  153. dark_blue = 1
  154. dark_purple = 2
  155. dark_green = 3
  156. brown = 4
  157. dark_gray = 5
  158. light_gray = 6
  159. white = 7
  160. red = 8
  161. orange = 9
  162. yellow = 10
  163. green = 11
  164. blue = 12
  165. indigo = 13
  166. pink = 14
  167. peach = 15
  168. function print_ctr(s,y,c)
  169. print(s,64 - #s * 2,y,c)
  170. end
  171. __gfx__
  172. 000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  173. 00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  174. 007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  175. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  176. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  177. 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000