If you want to make a game where lasers bounce around in a box, all you need are two simple formulas. Paint the right and left side of the box Black (or any color, but we'll use black in this example) and paint the up and down side of the box gray (or any color, but again, we'll use gray as an example). Then write three scripts. The costume in theory, the costume can be any thing, a dot works the best (as long as it is slightly bigger than the pen size). If the laser doesn't work, try to increase the size of the dot, and/or decrease the size of the pen.
#1 - Make the laser move, and begin pointing at a __ angle.
<when green flag clicked>
<go to x 0 )y 0 )
<set pen size to( 1 )
<clear>
<pen down>
<set pen color to( red )
<point in direction( __ )
<forever>
<move( # )steps>
The higher the # the faster the laser.
#2 - Make it bounce off the black walls (left and right)
<when green flag clicked>
<forever if> <touching color[ black ]
<point in direction( (( <direction> <*-1> ))
<wait( .1 )secs>
#3 - Make it bounce off the gray walls (top and bottom)
This is more difficult but try it anyway
<when green flag clicked>
<forever if> <touching color[ gray ]
<point in direction [direction* (180- abs of direction)] / abs of direction
<wait( .1 )secs>
abs is absolute value, but scratch just calls it abs.
Last edited by MoreGamesNow (2009-11-11 13:40:34)
Offline
Oh, one other thing, when the laser is pointing up (0) then it doesn't work (to my regret)
Offline
MoreGamesNow wrote:
Oh, one other thing, when the laser is pointing up (0) then it doesn't work (to my regret)
You had a script that made the laser point in the direction * -1 but when it's pointing up the direction is 0 and 0 * -1 is still zero...
Offline