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.

192 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
  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. update_drop(d)
  130. if d.y < 128 then
  131. add(new_drops, d)
  132. end
  133. end
  134. drops = new_drops
  135. end
  136. function _draw()
  137. draw_world()
  138. spr(player.spr,player.x-1,player.y-1)
  139. print("("..player.x..","..player.y..")", 1, 1, white)
  140. print("drops: "..#drops, 1, 7, white)
  141. end
  142. function draw_world()
  143. cls(bg)
  144. foreach(drops, draw_drop)
  145. foreach(ramps, draw_ramp)
  146. foreach(levers, draw_lever)
  147. end
  148. function draw_drop(drop)
  149. pset(drop.x, drop.y, white)
  150. end
  151. function draw_ramp(r)
  152. line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown)
  153. end
  154. function draw_lever(l)
  155. dx = l.len * cos(l.angle)
  156. dy = l.len * sin(l.angle)
  157. line(l.x,l.y,l.x+dx,l.y+dy,brown)
  158. rectfill(l.x-1,l.y-1,l.x+1,l.y+1,black)
  159. end
  160. __gfx__
  161. 000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  162. 00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  163. 007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  164. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  165. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  166. 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000