Advertisement
dengmahalYT

cc_bouncing

Apr 11th, 2025 (edited)
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. ---@diagnostic disable: unused-function
  2. local function wrapPs(peripheralName)
  3.     local periTab={}
  4.     local sideTab={}
  5.     if peripheralName==nil then
  6.         print("Error")
  7.     end
  8.     local peripherals = peripheral.getNames()
  9.     local i2 = 1
  10.     for i =1, #peripherals do
  11.         if peripheral.getType(peripherals[i])==peripheralName then
  12.             periTab[i2]=peripheral.wrap(peripherals[i])
  13.             sideTab[i2]=peripherals[i]
  14.             i2=i2+1
  15.         end
  16.     end
  17.     if periTab~={} then
  18.         return periTab,sideTab
  19.     else
  20.         return nil
  21.     end
  22. end
  23. --local mon=wrapPs("monitor")[1]
  24. --local SX,SY=mon.getSize()
  25. local cs = {
  26.     colors.red,        -- R
  27.     colors.orange,     -- O
  28.     colors.yellow,     -- Y
  29.     colors.lime,       -- G (lime as a bright green)
  30.     colors.green,      -- G (darker green)
  31.     colors.lightBlue,  -- B (light blue, before deeper blues)
  32.     colors.cyan,       -- B (cyan fits between lightBlue and blue)
  33.     colors.blue,       -- B (standard blue)
  34.     colors.purple,     -- I (indigo)
  35.     colors.magenta,    -- V (magenta as a pinkish violet)
  36.     colors.pink,       -- extra (soft violet range)
  37.     colors.white,      -- neutral (not in rainbow)
  38.     colors.lightGray,  -- neutral
  39.     colors.gray,       -- neutral
  40.     colors.brown       -- extra (not in rainbow)
  41. }
  42. local ci=1
  43.  
  44. local SX,SY=term.getSize()
  45. local speed=7
  46. local dt=1/7
  47. local posx=math.random(3,SX-3)
  48. local posy=math.random(3,SY-3)
  49. local velx=speed*math.cos(0.25*math.pi)
  50. local vely=speed*math.sin(0.25*math.pi)
  51. local dimx=1
  52. local dimy=1
  53.  
  54. local function sign(x)
  55.     if x<0 then
  56.         return -1
  57.     else
  58.         return 1
  59.     end
  60. end
  61. local LX=false
  62. local LY=false
  63. local hits=0
  64. if not fs.exists("score") then
  65.     local file=fs.open("score","w")
  66.     file.write("0")
  67.     file.close()
  68. else
  69.     local file=fs.open("score","r")
  70.     local content=file.readAll()
  71.     hits=tonumber(content)
  72.     file.close()
  73. end
  74. while true do
  75.     posx=posx+velx*dt
  76.     posy=posy+vely*dt
  77.     local PX=math.floor(posx+0.5)
  78.     local PY=math.floor(posy+0.5)
  79.     local hs=0
  80.     if ((posx+dimx)>SX or posx<1)and LX==false then
  81.         velx=-velx
  82.         LX=true
  83.         hs=hs+1
  84.     elseif not ((posx+dimx)>SX or posx<1) then
  85.         LX=false
  86.     end
  87.     if ((posy+dimy)>SY or posy<1)and LY==false then
  88.         vely=-vely
  89.         LY=true
  90.         hs=hs+1
  91.     elseif not ((posy+dimy)>SY or posy<1) then
  92.         LY=false
  93.     end
  94.     if hs==2 then
  95.         hits=hits+1
  96.         --local naf=math.atan(vely,velx)+math.random(-0.01,0.01)
  97.         --velx=speed*math.cos(naf)
  98.         --vely=speed*math.sin(naf)
  99.         local file=fs.open("score","w")
  100.         file.write(tostring(hits))
  101.         file.close()
  102.     end
  103.     ci=ci+1
  104.     if ci>#cs then
  105.         ci=1
  106.     end
  107.     term.clear()
  108.     paintutils.drawFilledBox(0,0,SX,SY,colours.black)
  109.     paintutils.drawBox(PX, PY,PX+dimx, PY+dimy,cs[ci])
  110.     term.setCursorPos(1, 1)
  111.     term.setBackgroundColor(colours.black)
  112.     term.setTextColour(colours.green)
  113.     term.write("Hits: "..hits)
  114.     sleep(dt)
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement