This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-11-11 13:39:14

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Laser bouncing of mirrors

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 sad  0 )y sad  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  smile

<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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#2 2009-11-11 13:41:25

jacool
Scratcher
Registered: 2008-01-25
Posts: 1000+

Re: Laser bouncing of mirrors

Thanks for sharing! I don't know if this belongs in the "New Members" forum but I think a Forum Moderator could tell...


http://i571.photobucket.com/albums/ss159/JacobKar/svensktiger-1.png

Offline

 

#3 2009-11-11 14:05:43

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Laser bouncing of mirrors

Oh, one other thing, when the laser is pointing up (0) then it doesn't work (to my regret)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2009-11-11 14:11:42

jacool
Scratcher
Registered: 2008-01-25
Posts: 1000+

Re: Laser bouncing of mirrors

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...


http://i571.photobucket.com/albums/ss159/JacobKar/svensktiger-1.png

Offline

 

Board footer