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.

203 lines
3.7 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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 = 36
  37. player.y = 16
  38. player.spr = 1
  39. drops = {}
  40. ramps = {}
  41. levers = {}
  42. add_ramp(70,25,40,-5)
  43. add_ramp(50,20,15,10)
  44. add_ramp(60,50,15,-15)
  45. add_ramp(52,60,14,0)
  46. add_ramp(45,75,10,30)
  47. add_ramp(64,76,0,10)
  48. add_ramp(64,86,6,0)
  49. add_ramp(70,76,0,10)
  50. add_lever(30,30,20)
  51. end
  52. function add_ramp(x,y,dx,dy)
  53. r = {}
  54. r.x = x
  55. r.y = y
  56. r.dx = dx
  57. r.dy = dy
  58. add(ramps, r)
  59. end
  60. function add_lever(x,y,len)
  61. l = {}
  62. l.x = x
  63. l.y = y
  64. l.len = len
  65. l.angle = 0.06
  66. l.weight = 0
  67. add(levers, l)
  68. end
  69. function _update()
  70. update_player()
  71. update_drops()
  72. foreach(levers, update_lever)
  73. end
  74. function update_player()
  75. if btn(0) then
  76. player.x -= 1
  77. end
  78. if btn(1) then
  79. player.x += 1
  80. end
  81. if btn(2) then
  82. player.y -= 1
  83. end
  84. if btn(3) then
  85. player.y += 1
  86. end
  87. player.x = mid(0, player.x, 127)
  88. player.y = mid(0, player.y, 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. weight = 0
  98. for i=0,l.len do
  99. x = l.x + i
  100. y = l.y + i * sin(l.angle) - 1
  101. while pget(x, y) == white do
  102. weight += 1
  103. y -= 1
  104. end
  105. end
  106. l.weight = weight
  107. end
  108. function update_drop(d)
  109. if d.y == 127 or pget(d.x,d.y+1) == bg then
  110. d.y += 1
  111. return
  112. end
  113. left = pget(d.x-1,d.y) == bg and pget(d.x-1,d.y+1) == bg
  114. right = pget(d.x+1,d.y) == bg and pget(d.x+1,d.y+1) == bg
  115. if left and right then
  116. d.y += 1
  117. if rnd() < 0.5 then
  118. d.x -= 1
  119. else
  120. d.x += 1
  121. end
  122. elseif left then
  123. d.y += 1
  124. d.x -= 1
  125. elseif right then
  126. d.y += 1
  127. d.x += 1
  128. end
  129. end
  130. function update_drops()
  131. draw_world()
  132. new_drops = {}
  133. for i=1,#drops do
  134. d = drops[i]
  135. oldx = d.x
  136. oldy = d.y
  137. update_drop(d)
  138. if d.y < 128 then
  139. add(new_drops, d)
  140. end
  141. pset(oldx, oldy, bg)
  142. pset(d.x, d.y, white)
  143. end
  144. drops = new_drops
  145. end
  146. function _draw()
  147. draw_world()
  148. spr(player.spr,player.x-1,player.y-1)
  149. print("("..player.x..","..player.y..")", 1, 1, white)
  150. print("drops: "..#drops, 1, 7, white)
  151. end
  152. function draw_world()
  153. cls(bg)
  154. foreach(drops, draw_drop)
  155. foreach(ramps, draw_ramp)
  156. foreach(levers, draw_lever)
  157. end
  158. function draw_drop(drop)
  159. pset(drop.x, drop.y, white)
  160. end
  161. function draw_ramp(r)
  162. line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown)
  163. end
  164. function draw_lever(l)
  165. dx = l.len * cos(l.angle)
  166. dy = l.len * sin(l.angle)
  167. line(l.x,l.y,l.x+dx,l.y+dy,brown)
  168. circ(l.x,l.y,1,black)
  169. print(""..l.weight,1,13,red)
  170. end
  171. __gfx__
  172. 000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  173. 00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  174. 007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  175. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  176. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  177. 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000