Guest User

powerController.lua

a guest
Jan 26th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local width = 60
  4. local height = 30
  5. local gpu = component.gpu
  6. local screen = component.screen
  7. local term = require("term")
  8.  
  9. local black = 0x000000
  10. local red = 0xFF0000
  11. local green = 0x00FF00
  12. local grey = 0x222222
  13. local white = 0xFFFFFF
  14.  
  15. local creepers = false
  16. local explosions = false
  17.  
  18. function initializeRedstone()
  19.   --ask other computers for initial redstone values
  20. end
  21.  
  22. function initializeScreen()
  23.   term.clear()
  24.   term.setCursorBlink(false)
  25.   gpu.setResolution(width, height)
  26.   gpu.setBackground(black)
  27.   gpu.setForeground(black)  
  28.   gpu.fill(1, 1, width, height, " ")
  29.   gpu.setForeground(white)
  30.   screen.setTouchModeInverted(true)
  31. end
  32.  
  33. function drawCreeper(enabled)
  34.   if enabled then
  35.     gpu.setBackground(green)
  36.   else
  37.     gpu.setBackground(grey)
  38.   end
  39.   gpu.fill(width/2+1,height/4+1,width/2,height/2," ")
  40.   gpu.setBackground(black)
  41.   gpu.fill(width/2+width/12,height/4+4,width/8,height/8," ")
  42.   gpu.fill(width-width/12*2,height/4+4,width/8,height/8," ")  
  43.   gpu.fill(width/4+width/2-width/32,height/2,width/8,height/6," ")
  44.   gpu.fill(width-width/6,height/2+height/12,width/8,height/6," ")
  45.   gpu.fill(width-width/4-width/8,height/2+height/12,width/8,height/6," ")
  46. end
  47.  
  48. function drawTNT(enabled)
  49.   if enabled then
  50.     gpu.setBackground(red)
  51.   else
  52.     gpu.setBackground(grey)
  53.   end
  54.   gpu.fill(1,height/4+1,width/2,height/2," ")
  55.   gpu.setBackground(white)
  56.   gpu.fill(1,height/2-height/32,width/2,height/8," ")
  57.   gpu.setBackground(black)
  58. end
  59.  
  60. function drawButtons()
  61.   drawCreeper(creepers)
  62.   drawTNT(explosions)
  63. end
  64.  
  65. function handleTouch(_,screen,x,y,buttonId,playerName)
  66.   if x <= width/2 and y >= height/4 and y <= height-height/4 then
  67.     explosions = not explosions
  68.   elseif x > width/2 and y >= height/4 and y <= height-height/4 then
  69.     creepers = not creepers
  70.   end  
  71.   drawButtons()
  72. end
  73.  
  74. initializeRedstone()
  75. initializeScreen()
  76. drawButtons()  
  77.  
  78. event.listen("touch", handleTouch)
Advertisement
Add Comment
Please, Sign In to add comment