Author Topic: Simple bouncing ball movement  (Read 2298 times)

GEEK

  • Guest
Simple bouncing ball movement
« on: August 27, 2015, 11:51:59 pm »
Code: [Select]
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   
« Last Edit: November 12, 2017, 09:17:27 am by Cybermonkey »

lelldorin

  • Guest
Re: Simple bouncing ball movement
« Reply #1 on: November 11, 2017, 08:25:58 pm »
Hello GEEK,

can i add your little program as example into my egsl-ide?

Greetings Lelldorin