Advertisement
briandorBriG

BallInBox.lua

Mar 14th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. -- Use this function to perform your initial setup
  2. function setup()
  3.  
  4.     displayMode(FULLSCREEN)
  5.     boxheight =3D 50
  6.     boxwidth =3D 50
  7.     ballX =3D 400
  8.     ballY =3D 400
  9.     ballZ =3D 74
  10.     updown =3D -4
  11.     leftright =3D -4
  12.     frontback =3D 4
  13.     offset =3D 75
  14.     diameter =3D 20
  15.  --   sc =3D 1
  16.     rot =3D 0
  17. end
  18.  
  19. -- This function gets called once every frame
  20. function draw()
  21.     -- This sets a dark background color
  22.     background(46, 46, 186, 255)
  23.     orientation()
  24.  
  25.     -- This sets the line thickness
  26.     stroke(64, 43, 75, 255)
  27.     strokeWidth(5)
  28.  
  29.     -- Do your drawing here
  30.     for loop =3D 0, boxeshigh do
  31.         endX =3D startX + barwidth
  32.         endY =3D startY + loop*boxheight
  33.         line(startX, endY, endX, endY)
  34.     end
  35.         line(startX-50, startY-50, endX+50, startY-50)
  36.     line(startX-100, startY-100, endX+100, startY-100)
  37.     line(startX-150, startY-150, endX+150, startY-150)
  38.     boxadjd =3D ((barwidth + 300)/boxeswide)
  39.     for loop =3D 0, boxeswide do
  40.         newX =3D startX + loop*boxwidth
  41.         lowerX =3D startX + loop*boxadjd - 150
  42.         endY =3D startY + barheight
  43.         line(newX, startY, newX, endY)
  44.         line(newX, startY, lowerX, startY-150 )
  45.     end
  46.     endY =3D startY
  47.     endX =3D startX + barwidth
  48.     motion()
  49.     strokeWidth(2)
  50.     stroke(113, 62, 67, 255)
  51.     fill(231, 10, 10, 255)
  52.     ellipse(ballX,ballY,200,200)
  53.     for loop =3D 1, 10 do
  54.         lp =3D 11-loop
  55.         ewidth =3D lp*(30-lp)
  56.         ellipse(ballX,ballY,ewidth,200)
  57.     end
  58.     strokeWidth(2)
  59.     noFill()
  60.     for loop =3D 1, 10 do
  61.         lp =3D 11-loop
  62.         ewidth =3D lp*(30-lp)
  63.         ellipse(ballX,ballY,200,ewidth)
  64.     end
  65.     strokeWidth(4)
  66. end
  67.  
  68. function orientation()
  69.     if WIDTH > 1000 then
  70.         startX =3D 162
  71.         startY =3D 268
  72.         barwidth =3D WIDTH - 2*162
  73.         barheight =3D HEIGHT - 368
  74.     else
  75.         startX =3D 134
  76.         startY =3D 324
  77.         barwidth =3D WIDTH - 2*134
  78.         barheight =3D HEIGHT - 474
  79.     end
  80.     boxeshigh =3D barheight/boxheight
  81.     boxeswide =3D barwidth/boxwidth  
  82. end
  83.  
  84. function motion()
  85.     rot =3D rot + 1
  86.     if rot > 90 then rot =3D 0 end
  87.     if WIDTH < 1000 then
  88.         if ballY > 750 + ballZ then
  89.             sound(SOUND_HIT, 1234)
  90.             updown =3D -4      =
  91.  
  92.         elseif ballY < 450 - ballZ then
  93.             sound(SOUND_HIT, 1234)
  94.             updown =3D 4
  95.         end
  96.         if ballX > 520 + ballZ then
  97.             sound(SOUND_HIT, 1234)
  98.             leftright =3D -4
  99.         elseif ballX < 220 - ballZ then
  100.             sound(SOUND_HIT, 1234)
  101.             leftright =3D 4
  102.         end
  103.         if ballZ > 150 then
  104.             sound(SOUND_HIT, 1234)
  105.             frontback =3D - 1
  106.         elseif ballZ < 0 then
  107.             sound(SOUND_HIT, 1234)
  108.             frontback =3D 1
  109.         end
  110.     elseif WIDTH >1000 then
  111.         if ballY > 520 + ballZ then
  112.             sound(SOUND_HIT, 1234)
  113.             updown =3D -4      =
  114.  
  115.         elseif ballY < 350 - ballZ then
  116.             sound(SOUND_HIT, 1234)
  117.             updown =3D 4
  118.         end
  119.         if ballX > 800 + ballZ then
  120.             sound(SOUND_HIT, 1234)
  121.             leftright =3D -4
  122.         elseif ballX < 200 - ballZ then
  123.             sound(SOUND_HIT, 1234)
  124.             leftright =3D 4
  125.         end
  126.         if ballZ > 150 then
  127.             sound(SOUND_HIT, 1234)
  128.             frontback =3D - 1
  129.         elseif ballZ < 0 then
  130.             sound(SOUND_HIT, 1234)
  131.             frontback =3D 1
  132.         end      
  133.     end
  134.     ballY =3D ballY + updown
  135.     ballX =3D ballX + leftright
  136.     ballZ =3D ballZ + frontback
  137. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement