Created
June 8, 2012 18:39
-
-
Save Bri-G/2897503 to your computer and use it in GitHub Desktop.
A crude bouncing 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
-- saveProjectInfo("Description", "Amiga Ball-in-Box") | |
-- saveProjectInfo("Version", "1.001 beta") | |
-- saveProjectInfo("Author", "Bri_G") | |
-- if require ~= nil then | |
-- require("loveCodea") | |
-- end | |
-- Use this function to perform your initial setup | |
function setup() | |
displayMode(FULLSCREEN) | |
boxheight = 50 | |
boxwidth = 50 | |
ballX = 400 | |
ballY = 400 | |
ballZ = 74 | |
updown = -4 | |
leftright = -4 | |
frontback = 4 | |
offset = 75 | |
diameter = 20 | |
-- sc = 1 | |
rot = 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 = 0, boxeshigh do | |
endX = startX + barwidth | |
endY = 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 = ((barwidth + 300)/boxeswide) | |
for loop = 0, boxeswide do | |
newX = startX + loop*boxwidth | |
lowerX = startX + loop*boxadjd - 150 | |
endY = startY + barheight | |
line(newX, startY, newX, endY) | |
line(newX, startY, lowerX, startY-150 ) | |
end | |
endY = startY | |
endX = startX + barwidth | |
motion() | |
strokeWidth(2) | |
stroke(113, 62, 67, 255) | |
fill(231, 10, 10, 255) | |
ellipse(ballX,ballY,200,200) | |
for loop = 1, 10 do | |
lp = 11-loop | |
ewidth = lp*(30-lp) | |
ellipse(ballX,ballY,ewidth,200) | |
end | |
strokeWidth(2) | |
noFill() | |
for loop = 1, 10 do | |
lp = 11-loop | |
ewidth = lp*(30-lp) | |
ellipse(ballX,ballY,200,ewidth) | |
end | |
strokeWidth(4) | |
end | |
function orientation() | |
if WIDTH > 1000 then | |
startX = 162 | |
startY = 268 | |
barwidth = WIDTH - 2*162 | |
barheight = HEIGHT - 368 | |
else | |
startX = 134 | |
startY = 324 | |
barwidth = WIDTH - 2*134 | |
barheight = HEIGHT - 474 | |
end | |
boxeshigh = barheight/boxheight | |
boxeswide = barwidth/boxwidth | |
end | |
function motion() | |
rot = rot + 1 | |
if rot > 90 then rot = 0 end | |
if WIDTH < 1000 then | |
if ballY > 750 + ballZ then | |
sound(SOUND_HIT, 1234) | |
updown = -4 | |
elseif ballY < 450 - ballZ then | |
sound(SOUND_HIT, 1234) | |
updown = 4 | |
end | |
if ballX > 520 + ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright = -4 | |
elseif ballX < 220 - ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright = 4 | |
end | |
if ballZ > 150 then | |
sound(SOUND_HIT, 1234) | |
frontback = - 1 | |
elseif ballZ < 0 then | |
sound(SOUND_HIT, 1234) | |
frontback = 1 | |
end | |
elseif WIDTH >1000 then | |
if ballY > 520 + ballZ then | |
sound(SOUND_HIT, 1234) | |
updown = -4 | |
elseif ballY < 350 - ballZ then | |
sound(SOUND_HIT, 1234) | |
updown = 4 | |
end | |
if ballX > 800 + ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright = -4 | |
elseif ballX < 200 - ballZ then | |
sound(SOUND_HIT, 1234) | |
leftright = 4 | |
end | |
if ballZ > 150 then | |
sound(SOUND_HIT, 1234) | |
frontback = - 1 | |
elseif ballZ < 0 then | |
sound(SOUND_HIT, 1234) | |
frontback = 1 | |
end | |
end | |
ballY = ballY + updown | |
ballX = ballX + leftright | |
ballZ = ballZ + frontback | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A very simple bouncing ball in a box, written in Lua to learn Codea. Need to improve on this, rotation of sphere and colour cycling of the ellipses involved.