alice-teacher variables

Richard Guenther guenther_richard at shsfalcons.com
Thu Oct 21 11:50:56 EDT 2010


On Tue, Oct 19, 2010 at 9:24 AM, Ella Glazer <ella.glazer at gmail.com> wrote:

I am teaching Alice to a group of 11 and 12 graders; hopefully as a lead-in
> to Java.  I am trying to use variables to calculate the distance between two
> objects, to use an if statement to avoid a collision.  Is there any book out
> there that does this using version 2.3?
>
>
>
Hi Ella,

I'm not sure if this answers your question, but it is a great example of
Alice's simplicity for programming events:

A classic example is letting the user slide a penguin around on the ice and
if they move over a "hole" in the ice, the penguin splashes into the water
and sinks.  This can easily be done and shows how easy it is to handle
events in Alice.  Here are the basic steps for this:

1.  Create a snow world and put a penguin into it.
2.  For the hole, simply use a Circle Shape and change it's color property
to blue--it should already be lying flat on the ice, so the illusion works
great.
3.  In events, choose "Let Arrow Keys Move" the penguin (default is the
camera).

Now we only need one event, really.

4.  Move the penguin away from the hole and create a new event "While
Something is True."  The default values will be printed in red, but we'll
change these.
5.  In the field between "While" and "is true", we are going to drop a
function from the penguin's built-in functions--in fact it's the topmost
function called "is within threshold of."  When you drop it to replace the
current "None" setting in the event, choose "1 meter" and "Circle".  When
completed it should read as "While penguin is within 1 meter of circle."
6.  Now, in the "begin" field, where it currently says nothing, put a method
in there to have the penguin move down 5 meters in, lets say, 0.25 seconds.
You can combine that in a "do together" with Penguin.playSound("splash") to
complete the effect (see attached picture).

Now, all of this could be modified to use variables.  You could declare a
variable for, say, distance to circle and then trigger an event if that
value got too low--i.e. too close to the hole in the ice.  You could then
have the penguin turn away from the circle, move, or whatever you want to
happen.  If you want to lead into Java, you may discuss with your students
where the variable should be stored--with the World object or with the
Penguin, etc.

Hope that helps.  If you need more help, just describe where you're at on
this.  :-)

Richard




-- 

Richard Guenther
Computer Science
Skyline High School
600 E Mtn Ave.
Longmont CO 80501
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20101021/0e8f7985/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: penguinExample.png
Type: image/png
Size: 108733 bytes
Desc: not available
Url : https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20101021/0e8f7985/attachment-0001.png 


More information about the alice-teachers mailing list