Advertisement
guitarplayer616

Bounce Final [Working]

Dec 9th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. -- [[ startup reference ]] --
  2.  
  3. reference = {
  4.     defbackcol = colors.black,
  5.     deftxtcol = colors.white,
  6.     mon = peripheral.find("monitor"),
  7. }
  8. if reference.mon then
  9.     term.redirect(reference.mon)
  10. end
  11. reference.size = {term.getSize()}
  12.  
  13. debug = {
  14.     hit = function()
  15.         slowDraw("HIT",5,5,colors.red)
  16.     end,
  17. }
  18.  
  19. -- [[ end of line ]] --
  20.  
  21. function Monitors2Grid()
  22.     --> monitors and sizes of monitors
  23.     --< 2d grid grid
  24. end
  25.  
  26. function classicDraw(txt,x,y,txtcol,backcol)
  27.     txt = txt or " "
  28.     local currX,currY = term.getCursorPos()
  29.     x = x or currX
  30.     y = y or currY
  31.     txtcol = txtcol or reference.deftxtcol
  32.     backcol = backcol or reference.defbackcol
  33.    
  34.     term.setCursorPos(x,y)
  35.     term.setTextColor(txtcol)
  36.     term.setBackgroundColor(backcol)
  37.     term.write(txt)
  38. end
  39.  
  40. function blitDraw(txt,x,y,txtcol,backcol)
  41.     txt = txt or " "
  42.     if not x or not y then
  43.         local currX,currY = term.getCursorPos()
  44.     end
  45.     x = x or currX
  46.     y = y or currY
  47.     txtcol = txtcol or reference.deftxtcol
  48.     backcol = backcol or reference.defbackcol
  49.    
  50.     local function color2hex(color)
  51.         local y = math.log(color)/math.log(2)
  52.         if y > 9 then
  53.             y = string.char(y + 87)
  54.         end
  55.         return y
  56.     end
  57.    
  58.     txtcol = color2hex(txtcol)
  59.     backcol = color2hex(backcol)
  60.    
  61.     term.setCursorPos(x,y)
  62.     term.blit(txt,string.rep(txtcol,txt:len()),string.rep(backcol,txt:len()))
  63.     --print(txt,txtcol:rep(txt:len()),backcol:rep(txt:len()))
  64. end
  65.  
  66.  
  67. if term.blit then
  68.     slowDraw = blitDraw
  69. else
  70.     slowDraw = classicDraw
  71. end
  72.    
  73.  
  74. function createObject(txt,txtcol,backcol,x,y,dx,dy)
  75.     local class = {}
  76.     class = {
  77.        
  78.         txt=txt,
  79.         txtcol=txtcol,
  80.         backcol=backcol,
  81.         x=x,
  82.         y=y,
  83.         dir=dir,
  84.         vel=vel,
  85.         acc=acc,
  86.         dx=dx,
  87.         dy=dy,
  88.         previous = {},
  89.        
  90.         nextPos = function(self)
  91.             self.previous.x = self.x
  92.             self.previous.y = self.y
  93.             self.previous.txt = self.txt
  94.            
  95.            
  96.             if self.y + self.dy > reference.size[2] then
  97.                 self.dy = -1 * self.dy
  98.                 self.y = (2*reference.size[2]) - self.y + self.dy
  99.             elseif self.y + self.dy <= 1 then
  100.                 self.dy = -1 * self.dy
  101.                 self.y = math.abs(self.dy - self.y)
  102.             else
  103.                 self.y = self.y + self.dy
  104.             end
  105.            
  106.             if self.x + self.dx > reference.size[1] then
  107.                 self.dx = -1 * self.dx
  108.                 self.x = (2*reference.size[1]) - self.x + self.dx
  109.             elseif self.x + self.dx <= 1 then
  110.                 self.dx = -1 * self.dx
  111.                 self.x = math.abs(self.dx - self.x)
  112.             else
  113.                 self.x = self.x + self.dx
  114.             end
  115.                
  116.         end,
  117.        
  118.        
  119.         draw = function(self)
  120.             if self.previous.x then
  121.                 --debug.hit()
  122.                 slowDraw(string.rep(" ",#self.previous.txt),self.previous.x,self.previous.y,reference.defbackcol,reference.defbackcol)
  123.                
  124.                 --slowDraw(" ",self.previous.x,self.previous.y)
  125.                
  126.             end
  127.             slowDraw(self.txt,self.x,self.y,self.txtcol,self.backcol)
  128.            
  129.            
  130.            
  131.            
  132.         end,
  133.        
  134.        
  135.     }
  136.  
  137.     return class
  138. end
  139.  
  140. --[[function resetTimers(n)
  141.     for i = 1,n do
  142.         loadstring("t"..i.." = os.startTimer(0)")()
  143.     end
  144. end]]--
  145.  
  146.  
  147. function engine(objects)
  148.     local timer = os.startTimer(0)
  149.     local i = 1
  150.     while true do
  151.         e,v = os.pullEvent()
  152.         if e == "timer" and v == timer then
  153.             for i,v in pairs(objects) do
  154.                 v:draw()
  155.                 v:nextPos()
  156.             end
  157.            
  158.             timer = os.startTimer(0)
  159.         end
  160.     end
  161. end
  162.  
  163. local objects = {
  164.    
  165.     ball = createObject("x",colors.white,colors.green,9,9,1,1),
  166.     balloon = createObject("o",colors.yellow,colors.blue,3,3,2,-2),
  167.     flower = createObject("8",colors.red,colors.black,25,25,2,1),
  168.    
  169. }
  170.  
  171. local words = {
  172.     b1 = createObject("PewPewPew",colors.green,_,10,10,4,2),
  173.     b2 = createObject("fuckmoeny",colors.white,colors.green,1,1,1,-4),
  174.     b3 = createObject("pussy",colors.magenta,colors.orange,7,7,4,-2),
  175. }
  176.  
  177. function overflow(n)
  178.   overflow = {}
  179.   for i = 1,n do
  180.       local xspeed = 0
  181.       local yspeed = 0
  182.       while xspeed == 0 or yspeed ==0 do
  183.         xspeed = math.random(-5,5)
  184.         yspeed = math.random(-5,5)
  185.       end
  186.       overflow[i] = createObject(" ",_,2^(math.random(6)),math.random(reference.size[1]),math.random(reference.size[2]),xspeed,yspeed)
  187.   end    
  188. end
  189.  
  190. term.setBackgroundColor(reference.defbackcol)
  191. shell.run("clr")
  192. overflow(20)
  193. engine(overflow)
  194.  
  195. --fastDraw("stuff",5,5,colors.blue,colors.red)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement