image Tutorial on Describing Plot - Player control

You don't have to give the player a character to control, but doing so will help make the game be more engaging. The player can only control one character. All the other characters will be controlled by the computer as non-player characters (NPCs). If the player doesn’t control a character, all the characters will be controlled by the computer. Both example sentences below give the player control of a single rabbit: By default, player characters are controlled with the keyboard. If you want the character to be controlled with the mouse, you must specify "with the mouse" in the sentence. If we declare that the player controls the rabbit with the mouse, you can still control the rabbit with keyboard as well.

Note that the player can control only one character. In other words, if there is more than one instance of the rabbit, it will not accept that the player controls the multiple rabbits. In the case that no character is controlled, all objects will be NPCs, as in a simulation environment.

Keyboard control is relatively straight-forward. When describing control, always use a conditional statement. The following gives a couple of examples.

When the up arrow is pressed, the rabbit moves up. This conditional statement connects the up arrow key with the up movement.
When the left arrow is pressed, the rabbit moves right. The key doesn't necessarily have to match the movement. You can use the left arrow to move right (as in this example), or the down arrow to move left.
When a is pressed, the rabbit moves left. You can also use alphabetic keys to control. A popular method is the WASD keys, where w is for up, a for left, s for down, and d for right.

Note that all the sentences above are descriptive, just like all other sentences in Game Changineer. That is, each sentence is written in the third-person form, describing the action / interaction among the characters. This is different from imperative sentences, such as commands. For example, it would be wrong to write "When the up arrow is pressed, move up." Since "move up" is a command, lacking a subject. Thus, remember to write each sentences as a description rather than as a command.


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!

Example 1:
There are twenty carrots scattered in the playing area.
There is one rabbit.
There are two foxes.
The foxes start out moving in a random direction.
When a fox reaches a border, it reverses direction.
When a fox sees the rabbit, it chases the rabbit.
When up arrow is pressed, the rabbit moves up.
When down arrow is pressed, the rabbit moves down.
When right arrow is pressed, the rabbit moves right.

Question: How would you make the rabbit eat the carrot? How would you make the rabbit go left?

Example 2:
There is one fox and one rabbit.
The rabbit wanders around.
When W is pressed, the fox moves up.
When S is pressed, the fox moves down.
When A is pressed, the fox moves left.
When D is pressed, the fox moves right.
When a fox reaches a border, it wraps around.
When a fox and a rabbit collide, the fox eats the rabbit.

Question: How would you make the rabbit flee the fox when it sees the fox?

Quiz: What would happen in the following:
There are two rabbits. The player controls the rabbit.


Optional Material on Mouse Control

Using the mouse to control is simple. Recall that we must declare that the mouse is used to control in the Setting. "The rabbit is controlled by the mouse." Here, the rabbit will go wherever the mouse goes.

If you wish the rabbit to only move in one direction, we can say the following.

When the mouse moves, the horizontal position of the rabbit is determined. The mouse only controls the side-to-side movement of the rabbit. The up-and-down movement of the rabbit is unaffected. You can replace 'horizontal' with 'vertical' to have the mouse control the up-and-down movement.

You can also click the mouse to make the object change. For example:


Programming Concepts (optional material):

Nearly in every program, there is user interaction involved. There is an entire field of human-computer interaction (HCI) devoted to studying the many ways of how humans and computers can interact. You may have seen that gesture, speech, steering wheel, etc. can be used to interact with the computer. Some examples of applications that use HCI are drawing programs, text editing, computer aided design, video games, and so on. In this tutorial session, however, we consider only the keyboard and mouse to interact with the objects in our program.

We can also view the keyboard and mouse as objects, each with its own attributes. The keyboard has many keys on it, each of which has a unique identification. Hence, the attributes of a keyboard consist of the keys and whether they are pressed. Whenever we press a key, the keyboard will communicate that information (which specific key was pressed) to our program. Each key has a unique, seven-bit ID number, known as an ASCII (American Standard Code for Information Interchange) code. Likewise, the mouse has attributes of its position and whether a button is clicked. It also communicates its attributes to the program. How can we use these attributes received from these input devices? We shall address these in the subsequent tutorial sessions.

Consider the following sentence, "When the up arrow is pressed, the rabbit moves up," the antecedent is checking if the up-arrow of the keyboard has been pressed. Whenever a key is pressed, the keyboard will send that information to us. We just need to determine if a specific key was pressed.

In this example sentence, whenever the up arrow is pressed, we perform the necessary consequent action, which is moving the rabbit up, via that move method associated with the rabbit. Both the methods for checking if the right key is pressed and moving the rabbit are low-level implementation details. They are automatically generated for you to allow you to focus on big-picture ideas among the objects in your game plan.



Next page

Tutorials Home