### Author Topic: Simple bouncing ball movement  (Read 1072 times)

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Simple bouncing ball movement
« on: 28. August 2015, 01:51:59 »
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 = 1a, b = 0, 0repeat        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) enduntil getkey() == 27   `
« Last Edit: 12. November 2017, 10:17:27 by Cybermonkey »

#### lelldorin

• Jr. Member
• Posts: 72
##### Re: Simple bouncing ball movement
« Reply #1 on: 11. November 2017, 21:25:58 »
Hello GEEK,