image Tutorial on Plot 5 - Power-Ups with Boolean Attributes

image In addition to dying, there are other attributes that you can apply to the characters. In the sentence, "The foxes are fast," the foxes have the attribute 'fast,' and move faster than the other characters. Consider the following examples of other attributes you can apply to characters:

When an alien hits a rock, it explodes. Another way to have a character die is by using the word 'explode'.
When a fox touches a rock, it freezes for 3 seconds. When a character 'freezes,' it holds still.

You can create other attributes if you'd like. These are useful for adding new powers to the characters in the game. To do so, you must use the new word in at least two sentences. One conditional statement uses the new word in its consequent clause, while another conditional statement uses it in its antecedent clause. You can go back to the 'Describing Plot 1 - NPC Movements' tutorial page to review conditional statements.

When the rabbit touches a spinstar, the rabbit is empowered for 4 seconds.
When the fox sees a rabbit and the rabbit is empowered, the fox flees the rabbit.
The first sentence gives the condition for a rabbit to become empowered, and the second sentence describes the effect of having this attribute.

'Dead,' 'frozen,' and 'empowered' are all Boolean attributes. Boolean attributes only have 2 values - true or false. For example, the statement, "The fox is frozen," can either be true or false. Specific colors are also Boolean attributes (for example, a character is either green, or not green). A game becomes more interesting when the value of a Boolean attribute affect the actions of a character:

When the fox sees a rabbit and the rabbit is empowered, the fox flees the rabbit.
When the fox sees an empowered rabbit, the fox flees the rabbit.
These two sentences do the same thing. In both examples, when the attribute, 'empowered,' is TRUE for a particular rabbit, it causes any foxes near it to take on the action of 'fleeing.' Notice how the first sentence contains 2 conditional expressions (the fox sees a rabbit, and the rabbit is empowered) while the second sentence only has one (the fox sees an empowered rabbit)
When the fox sees a rabbit and the rabbit is not empowered, the fox chases the rabbit.
When the fox sees a rabbit that is not empowered, the fox chases the rabbit.
These two sentences also do the same thing. However, unlike the last example, they describe what happens when the attribute, 'empowered,' is false.

To help you understand which characters are affected by these kinds of statements, consider the following examples:

When the cheese is empowered, it chases the hamster. In this example, the character in consequent is the same as the antecedent. So if there were more than one cheese in a game, ONLY the empowered cheese will chase the hamster.
When the diamond is empowered, the cheese chases the hamster. In this example, character in the antecedent results in the actions of a different character in the consequent. So, if there were more than one cheese in a game, ALL the cheeses would chase the hamster when the diamond becomes empowered.

Now, sometimes we want the character to have new power after they touch something. Let's say that the new power is the ability to shoot. We can do that in the following logical manner:

There are 3 diamonds and 1 rabbit.
You control the rabbit.
...
When the rabbit touches a diamond, it becomes empowered for 10 seconds.
When space bar is pressed and the rabbit is empowered, the rabbit shoots up.
In this example, whenever the rabbit touches a diamond, it will be able to shoot for 10 seconds.

Finally, you can associate time with attributes as shown in the examples above. Time cannot be associated with actions such as chase, shoot, etc. However, you can always add an attribute such that a character chases/shoots/etc. only when the attribute becomes true for the object. We will talk more about compound conditions below in the Experiment and try section below.


Experiment and try new attributes and see how they can help make your game more fun.

There are 3 foxes and 1 rabbit. There are 3 spinstars.
You control the rabbit with arrow keys.
When an arrow key is pressed, the rabbit moves in the same direction as the arrow.
When the rabbit hits a spinstar, it is empowered for 4 seconds.
When a fox sees the rabbit that is not empowered, it chases the rabbit.
When a fox sees the empowered rabbit, it flees the rabbit.

Next, let's replace the "empowered" attribute with the "supercharged" attribute:

When the rabbit and a spinstar collide, it eats the spinstar.
When a rabbit eats a spinstar, the rabbit becomes supercharged for 3 seconds.
When a rabbit is supercharged, the foxes become frozen.
Otherwise, the foxes are not frozen.
When a fox sees the rabbit that is not supercharged, it chases the rabbit.

Now try coming up with your own unique attribute!

Quiz: What will the following do?
When the rabbit touches a spinstar, the spinstar disappears and the rabbit is empowered for 4 seconds.
When the rabbit touches a spinstar and the rabbit is empowered, the rabbit dies.

Will the rabbit ever die? Try it and see!

The following sentence will cause a problem -- do you know how to fix it?
When the fox sees that rabbit is empowered, the fox flees the rabbit.
Fix: When the fox sees a rabbit that is empowered, the fox flees the rabbit.

How would you describe a game plan involving 2 rabbits, 10 carrots, and 1 fox, such that the fox will only chase the rabbit when the rabbit has eaten the carrot? (Hint: first attach an attribute to the rabbit when the rabbit has eaten the carrot. Then, describe the action of the fox about chasing the rabbit with the attribute.)

A possible solution is shown below:
There are 2 rabbits, 10 carrots, and one fox.
The rabbits wander around.
When a rabbit touches a carrot, the carrot is eaten.
When a rabbit touches a carrot, the rabbit becomes empowered.
When a rabbit is empowered, the fox chases it.


Complete Sample Games using Power-Ups

// Game #1. Shoot the Aliens: Touch the spinstar to be able to shoot.

// Game #2. Get the Cheese: Press A or S to make the hamster empowered or happy, and arrow keys to move.

// Game #3. Explode the pearls


Programming Concepts (optional material):
Test the example program below. We would like to make sure all characters remain on the screen. Do you remember how to add border control conditional statements? See if you can fix it.

There are 30 birds near the top.
There are 3 fast foxes near the bottom.
The foxes wander around.
The birds wander around.
When a fox sees a bird, the fox chases the bird.
When a bird sees a fox, the bird flees from the fox.
When a fox catches a bird, the fox eats the bird.
When all the birds are gone, the game is over.


Next page

Tutorials Home