Created
March 14, 2012 12:53
-
-
Save Bri-G/2036265 to your computer and use it in GitHub Desktop.
Ball in a box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Use this function to perform your initial setup | |
function setup() | |
displayMode(FULLSCREEN) | |
boxheight =3D 50 | |
boxwidth =3D 50 | |
ballX =3D 400 | |
ballY =3D 400 | |
ballZ =3D 74 | |
updown =3D -4 | |
leftright =3D -4 | |
frontback =3D 4 | |
offset =3D 75 | |
diameter =3D 20 | |
-- sc =3D 1 | |
rot =3D 0 | |
end | |
-- This function gets called once every frame | |
function draw() | |
-- This sets a dark background color | |
background(46, 46, 186, 255) | |
orientation() | |
-- This sets the line thickness | |
stroke(64, 43, 75, 255) | |
strokeWidth(5) | |
-- Do your drawing here | |
for loop =3D 0, boxeshigh do | |
endX =3D startX + barwidth | |
endY =3D startY + loop*boxheight | |
line(startX, endY, endX, endY) | |
end | |
line(startX-50, startY-50, endX+50, startY-50) | |
line(startX-100, startY-100, endX+100, startY-100) | |
line(startX-150, startY-150, endX+150, startY-150) | |
boxadjd =3D ((barwidth + 300)/boxeswide) | |
for loop =3D 0, boxeswide do | |
newX =3D startX + loop*boxwidth | |
lowerX =3D startX + loop*boxadjd - 150 | |
endY =3D startY + barheight | |
line(newX, startY, newX, endY) | |
line(newX, startY, lowerX, startY-150 ) | |
end | |
endY =3D startY | |
endX =3D startX + barwidth | |
motion() | |
strokeWidth(2) | |
stroke(113, 62, 67, 255) | |
fill(231, 10, 10, 255) | |
ellipse(ballX,ballY,200,200) | |
for loop =3D 1, 10 do | |
lp =3D 11-loop | |
ewidth =3D lp*(30-lp) | |
ellipse(ballX,ballY,ewidth,200) | |
end | |
strokeWidth(2) | |
noFill() | |
for loop =3D 1, 10 do | |
lp =3D 11-loop | |
ewidth =3D lp*(30-lp) | |
ellipse(ballX,ballY,200,ewidth) | |
end | |
strokeWidth(4) | |
end | |
function orientation() | |
if WIDTH > 1000 then | |
startX =3D 162 | |
startY =3D 268 | |
barwidth =3D WIDTH - 2*162 | |
barheight =3D HEIGHT - 368 | |
else | |
startX =3D 134 | |
startY =3D 324 | |
barwidth =3D WIDTH - 2*134 | |
barheight =3D HEIGHT - 474 | |
end | |
boxeshigh =3D barheight/boxheight | |
boxeswide =3D barwidth/boxwidth | |
end | |
function motion() | |
rot =3D rot + 1 | |
if rot > 90 then rot =3D 0 end | |
if WIDTH < 1000 then | |
if ballY > 750 + ballZ then | |
sound(SOUND_HIT, 1234) | |
updown =3D -4 = | |
elseif ballY < 450 - ballZ then | |
sound(SOUND_HIT, 1234) | |
updown =3D 4 | |
end | |
if ballX > 520 + ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright =3D -4 | |
elseif ballX < 220 - ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright =3D 4 | |
end | |
if ballZ > 150 then | |
sound(SOUND_HIT, 1234) | |
frontback =3D - 1 | |
elseif ballZ < 0 then | |
sound(SOUND_HIT, 1234) | |
frontback =3D 1 | |
end | |
elseif WIDTH >1000 then | |
if ballY > 520 + ballZ then | |
sound(SOUND_HIT, 1234) | |
updown =3D -4 = | |
elseif ballY < 350 - ballZ then | |
sound(SOUND_HIT, 1234) | |
updown =3D 4 | |
end | |
if ballX > 800 + ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright =3D -4 | |
elseif ballX < 200 - ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright =3D 4 | |
end | |
if ballZ > 150 then | |
sound(SOUND_HIT, 1234) | |
frontback =3D - 1 | |
elseif ballZ < 0 then | |
sound(SOUND_HIT, 1234) | |
frontback =3D 1 | |
end | |
end | |
ballY =3D ballY + updown | |
ballX =3D ballX + leftright | |
ballZ =3D ballZ + frontback | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment