TIMAS_Bro

pong.arch

Oct 15th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.   [ "platform.nfp" ] = "0\
  3. 0\
  4. 0\
  5. 0\
  6. 0",
  7.   [ "ball.nfp" ] = "e",
  8.   [ "game.lua" ] = "local file = fs.open(\"lgame/lgame\",\"r\")\
  9. if file then\
  10.    file.close()\
  11. os.loadAPI('/lg/lg')\
  12. lg.setup('term')\
  13. os.loadAPI(\"uap\")\
  14. os.loadAPI(\"/lgame/lgame\")\
  15. lgame.setup(\"term\")\
  16. lg.clearScreen()\
  17. lgame.lggSetDefBG(colors.black)\
  18. local lefty = 1\
  19. lgame.drawSprite('left',2,1,'/games/pong/platform.nfp')\
  20. lgame.drawSprite(\"ball\",12,8,\"/games/pong/ball.nfp\")\
  21. local px = 12\
  22. local py = 8\
  23. local dir = 1\
  24. colided = false\
  25. local ly = 1\
  26. local speed = 0.2\
  27. local c = 0\
  28. local d = false\
  29. os.sleep(0.1)\
  30. local function dt(text)\
  31.  lgame.fill(1,lgame.getSize().x,lgame.getSize().y,lgame.getSize().y,colors.black)\
  32.  lgame.drawText(1,lgame.getSize().y,colors.white,colors.black,text)\
  33. end\
  34. dt(\"3\")\
  35. os.sleep(1)\
  36. dt(\"2\")\
  37. os.sleep(1)\
  38. dt(\"1\")\
  39. os.sleep(1)\
  40. --lgame.drawText(1,10,colors.white,colors.black,\"SIZE: \"..lgame.getSize().x..\" \"..lgame.getSize().y)\
  41. function click()\
  42.  while true do\
  43.  local event, key = os.pullEvent(\"key\")\
  44.  if key == keys.w then\
  45.    if ly ~= 1 then\
  46.    ly = ly - 1\
  47.    end\
  48.  elseif key == keys.s then\
  49.    if lgame.getSpriteColider(\"left\").y2 ~= lgame.getSize().y then\
  50.   ly = ly + 1\
  51.    end\
  52.  elseif key == keys.e then\
  53.    os.reboot()\
  54.  end\
  55.  lgame.moveSprite(\"left\",2,ly)\
  56.  end\
  57. end\
  58. function game()\
  59. local i = 1\
  60. while true do\
  61.    d = false\
  62.    --local bal = lgame.getSpriteColider(\"ball\").x\
  63.    if lgame.getSpriteColider('ball').x == 1 then\
  64.    lg.fillScreen(colors.black)\
  65.    lg.drawText(9,9,colors.white,colors.black, 'You lose! R: '..c)\
  66.    break\
  67.    end\
  68.    \
  69.  i = i + 1\
  70.  if not (px == lgame.getSize().x + 1 and py == lgame.getSize().y+1) then\
  71.  if px <= lgame.getSize().x and px > 0 then\
  72.    if py <= lgame.getSize().y and py > 0 then\
  73.      if lgame.getSpriteColider(\"ball\").x == lgame.getSize().x and dir == 1 then\
  74.        dir = 3\
  75.      elseif lgame.getSpriteColider(\"ball\").x == lgame.getSize().x and dir == 2 then\
  76.        dir = 4\
  77.      elseif lgame.getSpriteColider(\"ball\").x == 1 and dir == 4 then\
  78.        dir = 2\
  79.      elseif lgame.getSpriteColider(\"ball\").x == 1 and dir == 3 then\
  80.        dir = 4\
  81.      elseif lgame.getSpriteColider(\"ball\").y == lgame.getSize().y and dir == 1 then\
  82.        dir = 2   \
  83.      elseif lgame.getSpriteColider(\"ball\").y == lgame.getSize().y and dir == 3 then\
  84.        dir = 4\
  85.      elseif lgame.getSpriteColider(\"ball\").y == 1 and dir == 2 then\
  86.        dir = 1\
  87.      elseif lgame.getSpriteColider(\"ball\").y == 1 and dir == 4 then\
  88.         dir = 3                                     \
  89.      end\
  90.    elseif py == 0 then\
  91.      d = true\
  92.      if (dir == 4) then\
  93.        dir = 3\
  94.      else\
  95.      dir = 1\
  96.      end\
  97.    elseif py == lgame.getSize().y+1 then\
  98.      d = true\
  99.      if (dir == 3) then\
  100.        dir = 4\
  101.      else\
  102.        dir = 2\
  103.      end\
  104.    end\
  105.  elseif px < 1 then\
  106.    d = true\
  107.    if (dir == 4) then\
  108.      dir = 2\
  109.    else\
  110.      dir = 1\
  111.    end\
  112.  elseif px == lgame.getSize().x+1 then\
  113.    d = true\
  114.    if (dir == 1) then\
  115.    dir = 3\
  116.    else\
  117.    dir = 4\
  118.    end\
  119.  end\
  120.  if dir == 1 then\
  121.  px = px + 1\
  122.  py = py + 1\
  123.  elseif dir == 2 then\
  124.  px = px + 1\
  125.  py = py - 1\
  126.  elseif dir == 3 then\
  127.  px = px - 1\
  128.  py = py + 1\
  129.  elseif dir == 4 then\
  130.  px = px - 1\
  131.  py = py - 1\
  132.  end\
  133.  if not d  then\
  134.  lgame.moveSprite(\"ball\",px,py)\
  135.  end\
  136.  os.sleep(speed)\
  137.  dt(\"Score: \"..c..\" | EXIT - E\")\
  138.  else\
  139.    break\
  140.  end\
  141.  if colided == false and lgame.isColiding(\"ball\",\"left\") then\
  142.    lgame.moveSprite(\"ball\",lgame.getSpriteColider(\"ball\").x+2,lgame.getSpriteColider(\"ball\").y)\
  143.    speed = speed - 0.01\
  144.    colided = true\
  145.    c = c + 1\
  146.    if dir == 4 then\
  147.      dir = 2\
  148.    elseif dir == 3 then\
  149.      dir = 1\
  150.    end\
  151.  else\
  152.    colided = false\
  153.  end\
  154. end\
  155. end\
  156. parallel.waitForAny(click,game)\
  157. lg.drawBT('end',1,4,19,19,colors.white,colors.black,'exit')\
  158. while true do\
  159. local event, button, x, y = os.pullEvent( \"mouse_click\" )\
  160.   if (lg.isButton(x,y) == \"end\") then\
  161. os.reboot()\
  162. end\
  163. end\
  164. lg.exit()\
  165. lgame.exit()    \
  166. else\
  167.    term.clear()\
  168.    term.setCursorPos(1,2)\
  169.    term.write(\"Install lgame from updater!\")\
  170.    uap.upd()\
  171. end",
  172. }
Add Comment
Please, Sign In to add comment