electronic_steve

tablet particler

Feb 3rd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. gml         = require("gml")
  2. com         = require("component")
  3. event       = require("event")
  4. gpu         = com.gpu
  5. internet    = com.tunnel
  6. send        = function(msg) status.text="_offline_" status:draw() internet.send(msg) end
  7. screen      = {x=26,y=18}
  8. gui         = gml.create(1,1,screen.x,screen.y)
  9. status      = gui:addLabel(14,14,9,"_offline_")
  10. option      = {random_speed=true,random_pos_radius=0,coord={"0.5","0.5","0.5"}}
  11. particle_N  = 0
  12. sender      = true
  13.  
  14. particle_N_label=gui:addLabel(14,16,11,"0")
  15. gpu.setResolution(screen.x,screen.y)
  16. gui:addLabel(14,13,10,"сообщение:")
  17.  
  18.  
  19. function redraw_N()
  20.     particle_N_label.text=tostring(particle_N)
  21.     particle_N_label:draw()
  22. end
  23. redraw_N()
  24.  
  25. function but_up()
  26.     send("up()")
  27. end
  28. gui:addButton(2,1,3,1,"U",but_up)
  29.  
  30.  
  31. function but_go()
  32.     send("go()")
  33. end
  34. gui:addButton(5,1,4,1," ▲",but_go)
  35.  
  36.  
  37. function but_down()
  38.     send("down()")
  39. end
  40. gui:addButton(9,1,3,1,"D",but_down)
  41.  
  42.  
  43. function but_left()
  44.     send("left()")
  45. end
  46. gui:addButton(2,2,3,1,"◄",but_left)
  47.  
  48.  
  49. function but_back()
  50.     send("back()")
  51. end
  52. gui:addButton(5,2,4,1," ▼",but_back)
  53.  
  54.  
  55. function but_right()
  56.     send("right()")
  57. end
  58. gui:addButton(9,2,3,1,"►",but_right)
  59.  
  60.  
  61. function create(...)
  62.     if sender then
  63.         particle_N=particle_N+1
  64.         redraw_N()
  65.         local arg={...}
  66.         local block=arg[2]
  67.         local x,y,z=block.posX,block.posY,block.posZ
  68.         if tonumber(option.coord.x.text) then x=block.posX+tonumber(option.coord.x.text)-1 end
  69.         if tonumber(option.coord.y.text) then y=block.posY+tonumber(option.coord.y.text) end
  70.         if tonumber(option.coord.z.text) then z=block.posZ+tonumber(option.coord.z.text)-1 end
  71.         send("add("..(x)..","..(y)..","..(z)..",'"..listbox:getSelected().."',"..tostring(option.random_speed)..","..(tonumber(option.random_pos_radius.text) or 0)..")")
  72.     end
  73. end
  74. gui:addHandler("tablet_use",create)
  75.  
  76.  
  77. function del()
  78.     send("del()")
  79.     particle_N=math.max(particle_N-1,0)
  80.     redraw_N()
  81. end
  82. stop_button=gui:addButton(1,6,12,1,"почистить",del)
  83.  
  84.  
  85. function modem_msg(_,_,_,_,_,msg)
  86.     status.text=msg
  87.     particle_N=tonumber(msg) or particle_N
  88.     status:draw()
  89. end
  90. gui:addHandler("modem_message",modem_msg)
  91.  
  92.  
  93. list={"explode","largeexplode","hugeexplosion","fireworksSpark","splash","depthsuspend","crit","magicCrit","smoke","largesmoke","spell","instantSpell","mobSpell","witchMagic","dripWater","dripLava","angryVillager","happyVillager","note","portal","enchantmenttable","flame","lava","reddust","slime","heart","cloud","snowshovel","blockcrack_11"}
  94. listbox=gui:addListBox(1,8,12,9,list)
  95.  
  96.  
  97. function edit_coord()
  98.     gpu.setBackground(0xFF0000) --костыль
  99.     gpu.setForeground(0xFFFFFF)
  100.     gpu.set(2,5,"[изм. коорд]")
  101.     edit_cord_button:draw()
  102.     sender=false
  103.     local _,block=event.pull("tablet_use")
  104.     send("editpos("..block.posX..","..block.posY..","..block.posZ..")")
  105.     sender=true
  106. end
  107. edit_cord_button=gui:addButton(1,4,12,1,"изм. коорд.",edit_coord)
  108.  
  109.  
  110. function start_robot()
  111.     com.modem.setStrength(16)
  112.     com.modem.broadcast(1,"ROBOTSTART")
  113. end
  114. gui:addButton(1,5,12,1,"запустить",start_robot)
  115.  
  116.  
  117. gui:addLabel(14,8,7,"радиус:")
  118. option.random_pos_radius=gui:addTextField(15,9,11)
  119.  
  120.  
  121. random_speed_label=gui:addLabel(14,11,3,"СС:")
  122. function rand_switch(self)
  123.     if option.random_speed then self.text="выкл" option.random_speed=false else random_speed.text="вкл" option.random_speed=true end
  124.     self:draw()
  125. end
  126. random_speed=gui:addButton(18,11,6,1,"вкл",rand_switch)
  127.  
  128.  
  129. gui:addLabel(14,4,2,"X:")
  130. option.coord.x=gui:addTextField(16,4,9)
  131. option.coord.x.text="0.5"
  132. gui:addLabel(14,5,2,"Y:")
  133. option.coord.y=gui:addTextField(16,5,9)
  134. option.coord.y.text="0.5"
  135. gui:addLabel(14,6,2,"Z:")
  136. option.coord.z=gui:addTextField(16,6,9)
  137. option.coord.z.text="0.5"
  138. gui:addLabel(14,1,12,"динамические")
  139. gui:addLabel(14,2,12," координаты")
  140. gui:addLabel(14,15,11,"колво част:")
  141. gui:run()
Add Comment
Please, Sign In to add comment