openwindow(900,500,0,'Simple bouncing ball')
sound = loadsound('ball.wav')
ball = {
x = 0,
y = 0
}
prev = {
x = 0,
y = 0
}
speed = {
x=3,
y=1
}
grav = 1
a, b = 0, 0
repeat
if ball.x > screenwidth() then
prev.x = 0
ball.x = 0
end
alphachannel(20)
color(0, 0, 0)
fillbox(0,0,screenwidth(),screenheight())
alphachannel(255)
color(100, 255, 0)
line(prev.x, prev.y,ball.x, ball.y)
sync()
prev.x = ball.x prev.y = ball.y
ball.x = ball.x + speed.x
speed.y = speed.y + grav
ball.y = ball.y + speed.y
a = speed.y
if a-1 + b == 0 then
ball.x = 0
prev.x = 0
ball.y = 0
speed.y = 1
end
if ball.y >= screenheight() then
ball.y = screenheight()
speed.y = -speed.y
b = speed.y
playsound(sound,255,0,0)
end
until getkey() == 27