SHARE
TWEET

Физика в OpenComputers (Minecraft)

rollton Sep 4th, 2017 (edited) 152 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Можно тыкать на экран, запуская пиксель как птичку в Angry Birds :)
  2. local koef = 2 -- коэффициент стартового запуска
  3.  
  4. local component = require("component")
  5. local gpu = component.gpu
  6. local term = require('term')
  7. local event = require('event')
  8.  
  9. local h = {['x'] = 20,['y'] = 30,['dx'] = 5,['dy'] = -3}
  10. local xm,ym = gpu.getResolution()
  11.  
  12. function line(x1,y1,x2,y2)
  13.     x= x1
  14.     y= y1
  15.     for i = 1 , math.floor( ( (x2-x1 )^2+( y1-y2 )^2)^0.5) do
  16.         gpu.set(math.floor(x),math.floor(y),'█')
  17.  
  18.         rad = math.atan2(y1-y2,x2-x1)
  19.         x = x + math.cos(rad)
  20.         y = y - math.sin(rad)
  21.     end
  22. end
  23.  
  24. function fiz(usl,dxx,dyy,xx,yy)
  25.     if usl then
  26.         h.dx = h.dx * dxx
  27.         h.dy = h.dy * dyy
  28.         h.x = xx
  29.         h.y = yy
  30.     end
  31. end
  32.  
  33. term.clear()
  34. while true do
  35.  
  36.     local e1 = {event.pull(0.05)}
  37.     gpu.set(math.floor(h.x),math.floor(h.y),' ')
  38.  
  39.     if e1[1] == 'touch' then
  40.         local e2
  41.         repeat
  42.             e2 = {event.pull()}
  43.             if e2[1] == 'drag' then term.clear() line(e1[3],e1[4],e2[3],e2[4]) end
  44.             if (e2[1] == 'touch') then break end
  45.             gpu.set(1,1,'dx '..tostring((e1[3] - e2[3])/koef))
  46.             gpu.set(1,2,'dy '..tostring((e1[4] - e2[4])/koef))
  47.         until e2[1] == 'drop'
  48.         term.clear()
  49.         if e2[1] == 'drop' then
  50.             h.x = e1[3]
  51.             h.y = e1[4]
  52.             h.dx = (e1[3] - e2[3])/koef
  53.             h.dy = (e1[4] - e2[4])/koef
  54.         end
  55.     end
  56.     h.dx = h.dx
  57.     h.dy = h.dy + 0.45
  58.     h.x = h.x + h.dx
  59.     h.y = h.y + h.dy
  60.  
  61.     fiz(h.y > ym,0.9,-0.85,h.x,ym) -- низ
  62.     fiz(h.y < 0 ,0.9,-0.85,h.x,0) -- верх
  63.     fiz(h.x > xm,-0.85,0.9,xm,h.y) -- право
  64.     fiz(h.x < 0 ,-0.85,0.9 ,0,h.y) -- лево
  65.     gpu.set(math.floor(h.x),math.floor(h.y),'█')
  66.     gpu.set(1,1,'dx '..tostring(h.dx))
  67.     gpu.set(1,2,'dy '..tostring(h.dy))
  68. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top