image Tutorial on Describing the Setting 1 - Scattering

Recall that the Setting of a game plan describes (1) the characters involved in the game and how many of them, (2) which character the player controls, and (3) the characters' initial positions.

Describing the characters involved helps the computer understand how the game is set up. Although it is not necessary, the player usually controls some specific character in the game. This helps the game to be more engaging. The initial position and speed of the characters are also optional. If none are described, the computer will place them randomly in the playing area.

Consider the following sentences:

  • There are 30 carrots. The carrots are scattered.
  • Thirty carrots are scattered on the field.
  • There are thirty carrots scattered on the field.
These three examples are all legitimate descriptions of the same situation. Play around and see if you can find new ways to describe it. image
There are 30 carrots. They are scattered. The pronoun "they" will be associated with carrots.
30 carrots are scattered near the top. You have the option to specify where you'd like the objects placed. The place terms include "top", "bottom", "right", "left", and "center". This sentence will randomly scatter 30 carrots only in the top half of the playing area.
There are two fast foxes. You also have the option to specify the speed of the characters. More on speed in a later tutorial.

Note that every sentence must end with a period (.). It is important to note that the chance of misinterpretation increases when you write long and complex sentences. So it is recommended that when you write, keep sentences short and concise. Break long sentences into multiple sentences whenever possible. Also, pronouns should be used carefully, as vague pronouns lead to unclear game plans!

Finally, you can mark a sentence as a 'comment' by adding '//' at the beginning of the sentence. So, the first of the following 2 sentences will place 3 rabbits into the setting, while the second one will not place 4 foxes, since it is treated as a comment.

Note that comments need to have a period (.) at the end as well to mark the end of the comment. Without a period, the comment will run into the next line and include the next line as a comment as well.
Try it yourself: Try typing the following sentence 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 rabbits scattered in the playing area.

Quiz: How would you describe 10 foxes on the top half and 5 rabbits in the bottom half of the area?


Programming Concepts (optional material):
The sentence "There are 30 carrots." contains two programming concepts. The first is the notion of an object. An object is an entity that encapsulates (holds) data and actions related to this entity. In this example, we have an object of a "carrot." This object will have some data and possibly actions related to it. The associated data typically describe the information and characteristics about the object, such as its color, position, etc. On the other hand, the actions describe what the object can do, such as shoot, chase, flee, etc. A program will consist of a set of objects. In a video game, most objects are visible, such as foxes and rabbits. However, in other types of programs, objects may not be visible. The interactions among objects are what constitute an interesting program. We shall discuss these later.

The next concepts are declaration and instantiation. Declaration denotes that some objects exist in the program, and instantiation is the creation of a number of concrete instances of a given object. In this above example sentence "There are 30 carrots", we declare that there are carrots in the program, and we are asking the program to create 30 instances of the carrot object.

Now, let us discuss more about the data associated with objects, often also referred to as "attributes," of an object. Attributes come in different types, such as numbers, colors, etc. For the carrot object, one may visualize the edible red-orange vegetable. Some attributes that may be of interest include the object's location, its size, whether it has been eaten or not (though we do not physically eat the object in the digital world), etc. Can you come up with some examples of an object from your class or home? Can you list some attributes that the object has?

A related sentence, "Foxes are fast." describes another object (a fox) which has the attribute "fast". This attribute indicates that the moving speed of the fox is higher than other objects in the game plan. Other attributes for the fox object may include its location, direction that it's traveling, etc. The carrot may or may not have a speed attribute. That is, if your game plan includes sentences that talk about carrots moving around, then the carrot object will have the speed attribute as well, even though one might find this game funny. In the virtual world, anything is possible, including carrots that run around. Similarly, if foxes never get eaten, the fox will not have an attribute to indicate whether any instance of fox has been eaten or not.

The sentence, "The carrots are scattered." will require the program to somehow allocate the 30 carrots onto the playing field by assigning specific values to the carrot's positions. Thus, scattering the carrots will involve iterating through all 30 carrot instances and individually assigning positions to each of them. Since the task of assigning a position to each carrot is the same for each instance of the carrot object, we can repeat this task over and over in a loop. Having such a loop can greatly eliminate the need to explicitly assign position values for all objects. This allows us to perform many similar actions by using the same code. Imagine the case where there are hundreds or thousands of instances of an object. Having such loops will be of great help to us.


In addition to scattering the characters, there are other ways to initially position them. Continue the tutorial to learn about them.



Next page

Tutorials Home