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.

196 lines
3.6 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
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. -- library
  5. black = 0
  6. dark_blue = 1
  7. dark_purple = 2
  8. dark_green = 3
  9. brown = 4
  10. dark_gray = 5
  11. light_gray = 6
  12. white = 7
  13. red = 8
  14. orange = 9
  15. yellow = 10
  16. green = 11
  17. blue = 12
  18. indigo = 13
  19. pink = 14
  20. peach = 15
  21. function print_ctr(s,y,c)
  22. print(s,64 - #s * 2,y,c)
  23. end
  24. -->8
  25. -- game code
  26. bg = blue
  27. function _init()
  28. -- button-press initial delay
  29. poke(0x5f5c, 2)
  30. -- button-press repeat
  31. poke(0x5f5d, 2)
  32. init_world()
  33. end
  34. function init_world()
  35. player = {}
  36. player.x = 64
  37. player.y = 16
  38. player.spr = 1
  39. drops = {}
  40. ramps = {}
  41. levers = {}
  42. add_ramp(50,20,15,10)
  43. add_ramp(60,50,15,-15)
  44. add_ramp(52,60,14,0)
  45. add_ramp(45,75,10,30)
  46. add_ramp(64,76,0,10)
  47. add_ramp(64,86,6,0)
  48. add_ramp(70,76,0,10)
  49. add_lever(30,30,20)
  50. end
  51. function add_ramp(x,y,dx,dy)
  52. r = {}
  53. r.x = x
  54. r.y = y
  55. r.dx = dx
  56. r.dy = dy
  57. add(ramps, r)
  58. end
  59. function add_lever(x,y,len)
  60. l = {}
  61. l.x = x
  62. l.y = y
  63. l.len = len
  64. l.angle = 0
  65. add(levers, l)
  66. end
  67. function _update()
  68. update_player()
  69. update_drops()
  70. update_levers()
  71. end
  72. function update_player()
  73. if btn(0) then
  74. player.x -= 1
  75. end
  76. if btn(1) then
  77. player.x += 1
  78. end
  79. if btn(2) then
  80. player.y -= 1
  81. end
  82. if btn(3) then
  83. player.y += 1
  84. end
  85. if (player.y < 0) player.y = 0
  86. if (player.y > 127) player.y = 127
  87. if (player.x < 0) player.x = 0
  88. if (player.x > 127) player.x = 127
  89. if btnp(🅾️) then
  90. drop = {}
  91. drop.x = player.x
  92. drop.y = player.y
  93. add(drops, drop)
  94. end
  95. end
  96. function update_lever(l)
  97. l.angle += 0.001
  98. end
  99. function update_levers()
  100. foreach(levers, update_lever)
  101. end
  102. function update_drop(d)
  103. if d.y == 127 or pget(d.x,d.y+1) == bg then
  104. d.y += 1
  105. return
  106. end
  107. left = pget(d.x-1,d.y) == bg and pget(d.x-1,d.y+1) == bg
  108. right = pget(d.x+1,d.y) == bg and pget(d.x+1,d.y+1) == bg
  109. if left and right then
  110. d.y += 1
  111. if rnd() < 0.5 then
  112. d.x -= 1
  113. else
  114. d.x += 1
  115. end
  116. elseif left then
  117. d.y += 1
  118. d.x -= 1
  119. elseif right then
  120. d.y += 1
  121. d.x += 1
  122. end
  123. end
  124. function update_drops()
  125. draw_world()
  126. new_drops = {}
  127. for i=1,#drops do
  128. d = drops[i]
  129. oldx = d.x
  130. oldy = d.y
  131. update_drop(d)
  132. if d.y < 128 then
  133. add(new_drops, d)
  134. end
  135. pset(oldx, oldy, bg)
  136. pset(d.x, d.y, white)
  137. end
  138. drops = new_drops
  139. end
  140. function _draw()
  141. draw_world()
  142. spr(player.spr,player.x-1,player.y-1)
  143. print("("..player.x..","..player.y..")", 1, 1, white)
  144. print("drops: "..#drops, 1, 7, white)
  145. end
  146. function draw_world()
  147. cls(bg)
  148. foreach(drops, draw_drop)
  149. foreach(ramps, draw_ramp)
  150. foreach(levers, draw_lever)
  151. end
  152. function draw_drop(drop)
  153. pset(drop.x, drop.y, white)
  154. end
  155. function draw_ramp(r)
  156. line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown)
  157. end
  158. function draw_lever(l)
  159. dx = l.len * cos(l.angle)
  160. dy = l.len * sin(l.angle)
  161. line(l.x,l.y,l.x+dx,l.y+dy,brown)
  162. rectfill(l.x-1,l.y-1,l.x+1,l.y+1,black)
  163. end
  164. __gfx__
  165. 000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  166. 00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  167. 007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  168. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  169. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  170. 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000