mrWhiskasss

111

Jan 30th, 2026
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local computer = require("computer")
  5. local gpu = component.gpu
  6.  
  7. gpu.setResolution(150,50)
  8. term.clear()
  9.  
  10. local W,H = gpu.getResolution()
  11. local FLOOR = H-4
  12.  
  13. -------------------------------------------------
  14.  
  15. local ladders = {
  16. {x=40, y1=15, y2=FLOOR},
  17. {x=75, y1=20, y2=FLOOR},
  18. {x=110,y1=15, y2=FLOOR}
  19. }
  20.  
  21. local dkArt = {
  22. " ███████████ ",
  23. " ███ DK ███",
  24. " ███ ███████ ███",
  25. "███ ██ ██ ██ ███",
  26. "███ ██ ██ ███",
  27. " ███ ██████ ███",
  28. " ███████████"
  29. }
  30.  
  31. -------------------------------------------------
  32.  
  33. local function center(y,t)
  34. gpu.set(math.floor(W/2-#t/2),y,t)
  35. end
  36.  
  37. -------------------------------------------------
  38. -- MENU
  39. -------------------------------------------------
  40.  
  41. local function menu()
  42. term.clear()
  43. center(15,"DONKEY KONG - OpenComputers")
  44. center(18,"A/D move W/S ladders")
  45. center(19,"W or SPACE jump")
  46. center(20,"Q quit")
  47. center(23,"Press ENTER")
  48.  
  49. while true do
  50. local _,_,_,k=event.pull("key_down")
  51. if k==28 then return end
  52. if k==16 then os.exit() end
  53. end
  54. end
  55.  
  56. -------------------------------------------------
  57.  
  58. local player,barrels,score,lives,spawnTimer
  59. local gravity=0.15
  60. local jumpPower=-2.2
  61.  
  62. local function reset()
  63. player={x=10,y=FLOOR,vy=0,onGround=true,onLadder=false}
  64. barrels={}
  65. score=0
  66. lives=3
  67. spawnTimer=0
  68. end
  69.  
  70. -------------------------------------------------
  71.  
  72. local function onLadder(px,py)
  73. for _,l in ipairs(ladders) do
  74. if math.abs(px-l.x)<1 and py>=l.y1 and py<=l.y2 then
  75. return true
  76. end
  77. end
  78. return false
  79. end
  80.  
  81. -------------------------------------------------
  82.  
  83. local function draw()
  84. term.clear()
  85.  
  86. -- DK
  87. for i=1,#dkArt do
  88. gpu.set(math.floor(W/2-#dkArt[i]/2),3+i,dkArt[i])
  89. end
  90.  
  91. -- ladders
  92. for _,l in ipairs(ladders) do
  93. for y=l.y1,l.y2 do
  94. gpu.set(l.x,y,"#")
  95. end
  96. end
  97.  
  98. -- floor
  99. for x=1,W do gpu.set(x,FLOOR+1,"=") end
  100.  
  101. -- player
  102. gpu.set(math.floor(player.x),math.floor(player.y),"@")
  103.  
  104. -- barrels
  105. for _,b in ipairs(barrels) do
  106. gpu.set(math.floor(b.x),math.floor(b.y),"O")
  107. end
  108.  
  109. gpu.set(2,2,"Score: "..score)
  110. gpu.set(2,3,"Lives: "..lives)
  111. end
  112.  
  113. -------------------------------------------------
  114.  
  115. local function spawnBarrel()
  116. table.insert(barrels,{x=W/2,y=12,vy=0,passed=false})
  117. end
  118.  
  119. local function hit(a,b)
  120. return math.abs(a.x-b.x)<1 and math.abs(a.y-b.y)<1
  121. end
  122.  
  123. -------------------------------------------------
  124.  
  125. local function gameOver()
  126. term.clear()
  127. center(22,"GAME OVER")
  128. center(24,"Score: "..score)
  129. center(27,"Press ENTER")
  130. while true do
  131. local _,_,_,k=event.pull("key_down")
  132. if k==28 then return end
  133. end
  134. end
  135.  
  136. -------------------------------------------------
  137.  
  138. while true do
  139. menu()
  140. reset()
  141.  
  142. local last=computer.uptime()
  143.  
  144. while lives>0 do
  145. local now=computer.uptime()
  146. local dt=now-last
  147. last=now
  148.  
  149. local e={event.pull(0)}
  150. if e[1]=="key_down" then
  151. local k=e[4]
  152. if k==16 then os.exit() end
  153. if k==30 then player.x=math.max(2,player.x-1) end
  154. if k==32 then player.x=math.min(W-2,player.x+1) end
  155.  
  156. player.onLadder=onLadder(player.x,player.y)
  157.  
  158. if k==17 then -- W
  159. if player.onLadder then player.y=player.y-1
  160. elseif player.onGround then player.vy=jumpPower end
  161. end
  162.  
  163. if k==31 and player.onLadder then player.y=player.y+1 end -- S
  164.  
  165. if k==57 and not player.onLadder then -- SPACE
  166. if player.onGround then player.vy=jumpPower end
  167. end
  168. end
  169.  
  170. if not player.onLadder then
  171. player.vy=player.vy+gravity
  172. player.y=player.y+player.vy
  173. end
  174.  
  175. if player.y>=FLOOR then
  176. player.y=FLOOR
  177. player.vy=0
  178. player.onGround=true
  179. else
  180. player.onGround=false
  181. end
  182.  
  183. spawnTimer=spawnTimer+dt
  184. if spawnTimer>1.4 then
  185. spawnTimer=0
  186. spawnBarrel()
  187. end
  188.  
  189. for i=#barrels,1,-1 do
  190. local b=barrels[i]
  191. b.vy=b.vy+gravity
  192. b.y=b.y+b.vy
  193. b.x=b.x-0.35
  194.  
  195. if b.y>=FLOOR then b.y=FLOOR b.vy=0 end
  196.  
  197. if not b.passed and b.x<player.x then
  198. b.passed=true
  199. score=score+100
  200. end
  201.  
  202. if hit(player,b) then
  203. lives=lives-1
  204. player.x=10 player.y=FLOOR player.vy=0
  205. table.remove(barrels,i)
  206. break
  207. end
  208.  
  209. if b.x<1 then table.remove(barrels,i) end
  210. end
  211.  
  212. draw()
  213. os.sleep(0.03)
  214. end
  215.  
  216. gameOver()
  217. end
  218.  
Advertisement
Add Comment
Please, Sign In to add comment