2. Create a dance
I hope you noticed in the previous videos that things were falling off buildings. Different objects were falling, but the basic action each time was the same - moving forward, then dropping a certain distance while rotating round and round. Let's explore how this kind of behaviour can be easily set up.
We're going to choreograph a circle dance with six dancers. In circle dances, each dancer, one after another, often performs the same steps, rather like our objects falling off the building. First off, open up the world file attached to this page.
Download the world at the bottom of the screen: Mod4.2DancersStarterWorld.a2w
You should see a setup like that below:
Take a look at the code in my first method
[Q4.2.1]: WITHOUT HITTING PLAY: Write down what you think this code will do. (Remember how important this ability to predict what some code will do is - so look at the code carefully, and write down precisely what you think will happen.)
Run the world now to see if your prediction was correct.
So, that was fun. Now let's get all six dancers to do the same little dance, one after another.
[Q4.2.2]: Take a moment to think how you could do that. Write down a brief summary of what you would do.
Hmmm, did you imagine copying out all that code another five times, changing the dancer on each line as necessary - to boy, teacher, nerd, and so on? That sounds horrible!! It would be five times creating six instructions, a Do Together and a Do In Order. That's 48 lines of code. Computer Science folk never like doing things more times than they have to. But just in case you can't imagine it, and although we hated to do it, you can download this world to see what it would look like if you tried this copy and modify approach.
There must be a better way....
How about using methods, as we did earlier in "Stories from Pieces"? That was a way of not having to add in the same code again and again.
[Q4.2.3]: Could we create just one dance method and call it six times? Would that work? Why, or why not?
Hang on - the problem is that it's not the same code every time - the character doing the dancing changes each time... oh no - we can't just use the methods we saw in the previous two modules!
Don't forget: Download the file linked below. Launch Alice on your computer, then use File -> Open World and select the file you downloaded.
Save the world as LastNameFirstName-4.2Dancers.a2w