Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trm=peripheral.wrap("monitor_14")
- trm.setTextScale(0.5)
- trm1=peripheral.wrap("monitor_15")
- trm1.setTextScale(2)
- cb=peripheral.wrap("command_1")
- fire="top"
- pay="right"
- start="68 73 207"
- --// The elements of Basic graphical utility API (Written by: Bobby Lucero) were used
- --// http://www.computercraft.info/forums2/index.php?/topic/20827-computercraft-graphics-library/
- function pixel(x,y)
- trm.setCursorPos(x,y)
- trm.write(" ")
- end
- function line( startX, startY, endX, endY ) --Shamelessly borrowed from cc internal source
- startX = math.floor(startX+0.5)
- startY = math.floor(startY+0.5)
- endX = math.floor(endX+0.5)
- endY = math.floor(endY+0.5)
- if startX == endX and startY == endY then
- pixel( startX, startY )
- return
- end
- local minX = math.min( startX, endX )
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- local xDiff = maxX - minX
- local yDiff = maxY - minY
- if xDiff > math.abs(yDiff) then
- local y = minY
- local dy = yDiff / xDiff
- for x=minX,maxX do
- pixel( x, math.floor( y + 0.5 ) )
- y = y + dy
- end
- else
- local x = minX
- local dx = xDiff / yDiff
- if maxY >= minY then
- for y=minY,maxY do
- pixel( math.floor( x + 0.5 ), y )
- x = x + dx
- end
- else
- for y=minY,maxY,-1 do
- pixel( math.floor( x + 0.5 ), y )
- x = x - dx
- end
- end
- end
- end
- function fillRect(x,y,w,h)
- for i = y, y+h-1 do
- trm.setCursorPos(x,i)
- trm.write(string.rep(" ",w))
- end
- end
- stretch=1.4
- function drawArc(x, y, radius, angle1, angle2)
- if angle1 == angle2 then return end
- if angle1 > angle2 then angle1,angle2=angle2,angle1 end
- local phi = angle1
- local k=1.5
- local x1,y1,x2,y2
- x1 = (stretch*radius * math.cos(math.rad(phi))) + x
- y1 = (radius * math.sin(math.rad(phi))) + y
- phi=phi+2
- while phi<angle2 do
- x2 = (stretch*radius * math.cos(math.rad(phi))) + x
- y2 = (radius * math.sin(math.rad(phi))) + y
- line(x1,y1,x2,y2)
- x1,y1=x2,y2
- phi=phi+2
- end
- x2 = (stretch*radius * math.cos(math.rad(angle2))) + x
- y2 = (radius * math.sin(math.rad(angle2))) + y
- line(x1,y1,x2,y2)
- end
- function makeArea(x,y,w,h)
- local area={X=x,Y=y,W=w,H=h}
- area.onMouse=function(clx,cly)
- return clx>=area.X and clx<area.X+area.W and cly>=area.Y and cly<area.Y+area.H
- end
- area.show=function(level,col1,col2)
- trm.setBackgroundColor(col1)
- fillRect(area.X,area.Y,area.W,area.H)
- trm.setBackgroundColor(col2)
- local hy=math.floor(level*(area.H)+0.5)
- fillRect(area.X,area.Y+area.H-hy,area.W,hy)
- end
- return area
- end
- function tostr(v)
- local s=tostring(v)
- if not s:find("%.") then s=s..".0" end
- return s
- end
- function boom(ax,ay,e)
- ay=math.rad(ay)
- ax=math.rad(ax)
- local v=math.sqrt(2*e)
- local vy=tostr(v*math.sin(ay))
- local vx=tostr(-v*math.cos(ay)*math.sin(ax))
- local vz=tostr(v*math.cos(ay)*math.cos(ax))
- cb.setCommand("playsound random.explode @a ~ ~ ~")
- cb.runCommand()
- -- print("vx=",vx," vy=",vy," vz=",vz)
- cb.setCommand("summon PrimedTnt "..start.." {Motion:["..vx..","..vy..","..vz.."], Fuse:127}")
- cb.runCommand()
- bang=bang-1
- trm1.setCursorPos(1,1)
- trm1.write(' '..bang..' ')
- end
- w,h=trm.getSize()
- cx=math.floor(w/2+0.5)
- cy=h
- r=h-2.2
- amax=45
- aymax=45
- pwmax=5
- ax=0
- ay=0
- pw=2
- bang=0
- trm1.setCursorPos(1,1)
- trm1.write(' '..bang..' ')
- function arrow()
- line(cx,cy,cx+stretch*r*math.sin(math.rad(ax)),cy-r*math.cos(math.rad(ax)))
- end
- trm.setBackgroundColor(colors.black)
- trm.clear()
- trm.setCursorBlink(false)
- horizont=makeArea(7,1,45,cy,colors.black)
- trm.setBackgroundColor(colors.white)
- drawArc(cx,cy,cy-1,-90-amax,-90+amax)
- trm.setBackgroundColor(colors.red)
- arrow()
- power=makeArea(1,1,6,cy,colors.yellow)
- power.show((pw-1)/(pwmax-1),colors.yellow,colors.orange)
- vertikal=makeArea(w-5,1,6,h,colors.green)
- vertikal.show(ay/aymax,colors.green,colors.lime)
- while true do
- event,but,mx,my=os.pullEvent()
- -- print(event,' ',but,' ',mx,' ',my)
- if event=="mouse_click" and but==1 then
- clickx=mx
- clicky=my
- elseif event=="mouse_drag" and but==1 then
- dragx=mx-clickx
- dragy=my-clicky
- clickx=mx
- clicky=my
- if power.onMouse(mx,my) then
- end
- if horizont.onMouse(mx,my) then
- trm.setBackgroundColor(colors.black)
- arrow()
- ax=ax+dragx
- if ax>amax then ax=amax end
- if ax<-amax then ax=-amax end
- trm.setBackgroundColor(colors.red)
- arrow()
- end
- if vertikal.onMouse(mx,my) then
- ay=ay-dragy
- if ay>aymax then ay=aymax end
- if ay<0 then ay=0 end
- vertikal.show(ay/aymax,colors.green,colors.lime)
- end
- if power.onMouse(mx,my) then
- pw=pw-dragy/10
- if pw>pwmax then pw=pwmax end
- if pw<1 then pw=1 end
- power.show((pw-1)/(pwmax-1),colors.yellow,colors.orange)
- end
- elseif event=="monitor_touch" then
- if onDrag then
- os.queueEvent("mouse_drag",1,mx,my)
- else
- os.queueEvent("mouse_click",1,mx,my)
- end
- onDrag=true
- clicktimer=os.startTimer(0.5)
- elseif event=="timer" then
- if but==clicktimer then
- onDrag=false
- elseif but==boomtimer then
- end
- elseif event=="redstone" then
- if redstone.getInput(fire) then
- boom(ax,ay,pw)
- end
- if redstone.getInput(pay) then
- bang=bang+10
- trm1.setCursorPos(1,1)
- trm1.write(' '..bang..' ')
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement