image Tutorial on Plot - Collision and Resulting Actions (Eat, Kick, etc.)

image Two characters 'collide' when they touch each other. Consider the following examples:

When two rabbits collide, they both die. Two characters of the SAME type collide.
When a fox collides with a rabbit, the rabbit dies. Two characters of DIFFERENT types collide.
When a rabbit and a carrot collide, the rabbit eats the carrot.
When a rabbit touches a carrot, the carrot is eaten by the rabbit.
These sentences describe a rabbit eating a carrot through collision.
When a rabbit touches a ball, the rabbit kicks the ball. These sentences describe a rabbit pushing/kicking the ball through collision.

If no sentence describes the collision between two particular characters, then nothing will happen upon their collision. For example, in a text containing rabbits, foxes, and carrots. If no sentence describes the collision between a fox and a carrot, then nothing will happen when these two objects collide.


Try it yourself: Try typing in the following into the textbox on GameChangineer, then click "Execute" near the bottom of that page to generate the code for your game plan. If there are no typos and everything is understood, click the button at the bottom to see your code in action!

There are twenty carrots scattered in the playing area.
There is one rabbit.
The player controls the rabbit with the mouse.
There are two foxes.
The foxes start out moving in a random direction.
When a fox reaches a border, it reverses direction.
When a rabbit collides with a carrot, the rabbit eats the carrot.

Question: How would you make the rabbit die when it collides with a fox?


Programming Concepts (optional material):
This tutorial session continues with more discussion of abstract methods. Recall that methods are actions that manipulate the attributes of objects. For example, consider the sentence "When a rabbit and a carrot collide, the rabbit eats the carrot." Here we have two methods: collide and eat. Both methods relate two instances of the same or different objects. The actual implementation of these methods again is automatically generated. If you were to look at the actual code that implements these functions, you would see that they are done in a procedural fashion. In this we mean that a sequence of steps is prescribed to perform the necessary action.

When you write your game plan, some parts of the text also need to be described in a procedural manner, in which you lay out the steps logically and coherently. For example, you must put on your socks before you put on your shoes. Similarly, in computer programming, some code needs to be organized into a certain order for the program to run correctly. Thus, writing more game plans can help you become a more logical thinker as well!


Next page

Tutorials Home