Reactor_Games

Untitled

Jul 22nd, 2020 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. local component = require("component")
  2. local reactor = component.br_reactor
  3. local event = require("event")
  4. local gpu = component.gpu
  5. local unicode = require("unicode")
  6. local term = require("term")
  7.  
  8. --function script
  9. function powerOn()
  10.   reactor.setActive(true)
  11. end
  12.  
  13. function powerOff()
  14.   reactor.setActive(false)
  15. end
  16.  
  17. while true do
  18.     local energyy = reactor.getEnergyStored()
  19.     if energyy == 9000000 then
  20.         reactor.setActive(false)
  21.     else
  22.         reactor.setActive(true)
  23.     end
  24.  
  25.     if energyy <= 50000 then
  26.         reactor.setActive(true)
  27.     else
  28.         reactor.setActive(false)
  29.     end
  30. end
  31.  
  32.  
  33. --function script
  34.  
  35.  
  36. --function button
  37.  
  38.  
  39. --function button
  40.  
  41. --button
  42. buttons = { button = {x=16, y=4, text="Вкл", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = powerOn, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF},
  43.             button2 = {x=32, y=4, text="Выкл", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = powerOff, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF},
  44.             button3 = {x=64, y=4, text="debug", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = oninfinity, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF}}
  45.            
  46.  
  47. --button
  48.  
  49. --monitor
  50. function initButtons()
  51.  
  52. for k,v in pairs(buttons) do
  53. v.width = unicode.wlen(v.text) + 2
  54. end
  55.  
  56. end
  57.  
  58. initButtons()
  59.  
  60. function drawButtons()
  61.  term.clear()
  62. for k,v in pairs(buttons) do
  63. if v.active then
  64. if not v.buttonPressed then -- если кнопка не нажата
  65. gpu.setForeground(v.cFore)
  66. gpu.setBackground(v.cBack)
  67. else                      -- в ином случае
  68. gpu.setForeground(v.cFore1)
  69. gpu.setBackground(v.cBack1)
  70. end
  71. gpu.fill(v.x, v.y, v.width, v.height, " ") -- фон для кнопки
  72. if v.height == 1 then         -- если высота кнопки равна 1
  73. gpu.set(v.x+1, v.y, v.text)
  74. elseif v.height%2 == 0 then   -- если высота кнопки равна четному числу
  75. gpu.set(v.x+1, v.y + (v.height/2 - 1), v.text)
  76. elseif v.height%2 == 1 then   -- если высота кнопки равна нечетному числу
  77. gpu.set(v.x+1, v.y + (math.ceil(v.height/2) - 1), v.text)
  78. end
  79. if v.autoSwitch == true and v.buttonPressed == true then
  80. v.buttonPressed = false
  81. os.sleep(4)
  82. drawButtons()
  83. end
  84. end
  85. end
  86. gpu.setForeground(0xFFFFFF)
  87. gpu.setBackground(0x000000)
  88.  
  89. end
  90.  
  91. function searchButton()
  92.  
  93. while true do
  94. local _,_,x,y = event.pull("touch")
  95. for k,v in pairs(buttons) do
  96. if x >= v.x and x < v.x + v.width+2 and y >= v.y and y < v.y + v.height and v.active then
  97. if v.switchedButton == true then
  98. if not v.autoSwitch then
  99. if v.buttonPressed == false then
  100. v.buttonPressed = true
  101. else
  102. v.buttonPressed = false
  103. end
  104. else
  105. v.buttonPressed = true
  106. end
  107. term.clear()
  108. drawButtons()
  109. end
  110. v.func()
  111. end
  112. end
  113. end
  114.  
  115. end
  116.  
  117. drawButtons()
  118. searchButton()--monitor
  119.  
  120.  
Add Comment
Please, Sign In to add comment