Follow the Bouncing Ball

soccer ball


Video Tutorial

Click here for a YouTube video of Lloyd building this project. The video has been optimized for viewing on an iPad.

(Note: For a "crystal clear" video, you may have to manually change the quality settings in YouTube to "720p HD" - just look for the gear symbol in the bottom right-hand corner of the YouTube window.)

I built this project solely with local variables as a help to see the difference between global and local variables.

LiveCode File for this Project

Script for the button "Bounce":

on mouseUp

hide me

put item 1 of the location of button "ball" into x
put item 2 of the location of button "ball" into y

put line 1 of field "speed" into varSpeedx
put line 2 of field "speed" into varSpeedy

repeat until the mouseclick

if x > 320 then put -1*varSpeedx into varSpeedx
if x < 0 then put -1*varSpeedx into varSpeedx
if y > 480 then put -1*varSpeedy into varSpeedy
if y < 0 then put -1*varSpeedy into varSpeedy

wait 1 millisecond
add varSpeedx to x
add varSpeedy to y

set the location of button "ball" to x, y

end repeat

show me

end mouseUp