Alice 3: Make a biped walk

Alice

There is a nice video on how to create procedures that allow you to make bipeds (i.e. characters with two feet) walk. It is here

The movement has been separated into two procedures, the first halfstep called “firstStep()”.

181210 Alice firstStep.jpg

Next we create a procedure for a full step with both legs called “walk()”.

For that we also need to create a Biped property that keeps track of which leg moves last so that next time the other leg moves. You create it also by clicking on the yellow hexagone and choose create Biped property. Here is the requester that comes up with all data you need to fill in. This property only has two values signaling which leg to move next. Values of type Boolean have only two values, they are suitable for this task.

181210 createBipedPropertyLeg.jpg

 

181210 Alice walk.jpg

Here are the two procedures used inside “myFirstMethod()”, the rest of the program is for another project, it also contains code to use colour effects.

181210 Alice walkInMyFirstMethod.jpg

Here is an add-on, it is the function walkSteps(steps). Here steps is a parameter that tells the method how many steps to take.

181211 walkSteps.jpg

 

Object oriented design elements with classes and their properties and methods as well as inheritance as a way to structure classes.

All sprites and props in Alice are arranged in a class hierarchy.

You have already encountered class hierarchies in biology. They allow animals and plants to be classified by certain criteria in a taxonomy or hierarchy. The criteria go from more generic at the top of the tree (Domain in biology) to more specific at the bottom of the tree (Species in biology). A species shares most of the properties of the respective genus, and has different ones to distinguish itself from other species.

640px-Taxonomic_Rank_Graph.png

Source:

The same concept is applied in the class hierarchie in Alice. Here the more generic classes are called parent classes, a class derived from one parent may be called child class. When you are on the “Setup Scene”, you see all characters and props arranged in classes at the bottom. The class Biped contains humanoids, but also monkeys and other animals, all of them are walking on two legs, at least in Alice. In order to create a biped character on your scene, you select the class Biped, being the parent class, and then define a child class with individual properties as age, clothes, hair, … . The class Biped also provides methods that allow you to let them act that inherited to the child class. Inside the child class you can then define own properties and methods that are only applicable to that particular class.

Inside Alice the class hierarchie can be visualised by clicking on the yellow hexagone beside the Scene Tab in the Code Editor. Here is a screenshot how it may look like. You can see the inhertance structure be the amount of identation, i.e. AdultPerson is a child class of Person that is a child class of Biped.

181210AliceInheritage1.jpg

If you want to create a procedure to make a biped walk, you select the Biped class, and then code your procedure. As a result, the procedure is available to all characters that are derived from the biped class, existing ones, but also those you may create in the future.

This is a major characteristic of so called Object Oriented Programming and helps you to structure your work and avoid repetitions of similar properties and methods.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.