Game Development Reference
In-Depth Information
the paddle down. The ball in the game will start at the center and will begin each
round with a random direction. When the ball crosses the left or right limit of the
screen, the opposing player will gain a point and the ball will reset at the center.
The game will be a windowed game with dimensions of 800 pixels wide by 600
pixels high.
Specification for
Pong
:EberosGML2D
The game has two
UserDefinedEntities
: Player and PongBall. The Player en-
tity has one
Sprite2D
with the bar graphics. It has a global state which listens
to the MOVE UP and MOVE DOWN
GameMessages
. The Player entity has a
BoudingRectangle
for collision detection. Finally, it has two
CompositeActuators
;
MoveUp and MoveDown, which handle the translation of the entity up or down.
The PongBall entity has one
Sprite2D
with the ball graphic. It has a
BoundingRectangle
for detecting the collision with the player's paddle and the
screen limits. The PongBall entity has three
CompositeActuators
; MoveBall, Re-
setBall, RandomizeDirection. The PongBall entity also has two
States
:
BALL RESET and BALL ACTIVE for supporting the logic of the PongBall en-
tity. Since the game is a windowed game, the GameRoot entity is 800 pixels wide
by 600 high. The GameRoot also has three
EntityReferences
: Player1, Player2,
and PongBall. The player references are then controlled by two
InputHandlers
:
Player1Input and Player2Input. The Player1Input responds to the A and Z keys,
and notifies the Player1 reference of MOVE UP and MOVE DOWN
GameMessages
.
Similarly, Player2Input responds to the up arrow and down arrow keys, and notifies
Player2 reference of MOVE UP and MOVE DOWN
GameMessages
.
19.1.1 Source Code
Once the game has been defined, the Eberos GML2D model created can be auto-
matically translated into source code, and the initial game version is created (see
Figure19.2
)
.Thegamemightstillrequiresomeprogrammingtocomplete,butyou
Figure 19.2.
Simple Game of Pong.