<< Chapter < Page Chapter >> Page >

Two primary objects

You learned in an earlier module that a Slick2D game that runs as an application (not an applet) consists of at least two cooperating objects:

  1. An object instantiated from a subclass of the Slick2D class named GameContainer .
  2. An object instantiated from a class that implements the Slick2D interface named Game .

Behavior of an object of the AppGameContainer class

The GameContainer object ( item 1 above ) manages the program startup and the game play after the game program starts running. For example, this is the object that managesthe game loop.

As shown in Listing 1 , for the program named Slick0120a , this object is an object of the class named AppGameContainer , which extends the class named GameContainer .

The AppGameContainer class provides many public methods (including the method named start , which is called in Listing 1 ) by which you can manipulate the behavior of the container object. Theauthors of the Slick2D library did not intend for you to physically modify the source code in the GameContainer class or the AppGameContainer class.

Behavior of an object that implements the Game interface

The behaviors of the methods of the Game object ( item 2 above ) are what distinguishes one Slick2D game from another Slick2D game.

You need not implement the Game interface directly. The authors of the Slick2D libraryprovided a helper class named BasicGame that implements the Game interface and provides a number of useful methods. They intended for you to extend the BasicGame class and to override at least three of the methods declared in the Game interface in order to provide the desired behavior for your game..

As mentioned earlier, the class named Slick0120a extends the BasicGame class, thereby implementing the Game interface and getting the benefit of methods defined in the BasicGame class.

The code in the main method in Listing 1 instantiates an object of the Slick0120a class and passes that object's reference to the constructor for the class named AppGameContainer . Therefore, Listing 1 instantiates both of the required objects and connects them in the manner intended by the authors of the Slick2D library.

Starting the game

The main purpose of this module is to analyze the behavior of the Slick2D game engine when you start aSlick2D game running.

Listing 1 calls the start method on a reference to the AppGameContainer object. The source code for the start method is shown in Listing 2 .

Listing 2 . The start method of the AppGameContainer class.
public void start() throws SlickException { try {setup();getDelta(); while (running()) {gameLoop(); }} finally { destroy();}if (forceExit) {System.exit(0); }}//end start

Copyright and license information

Copyright and license information:

I was unable to find any copyright or license information in the zip file that I downloaded from (External Link) . I acknowledge that I am not the author of the code in that zip file and the copyrights for thatmaterial are held by someone other than myself.

Constructors and methods

This and the next few modules will explore and discuss the constructors for the AppGameContainer class (see Listing 1 ) along with salient aspects of the following methods that are called in Listing 2 :

Questions & Answers

how to study physic and understand
Ewa Reply
what is conservative force with examples
Moses
what is work
Fredrick Reply
the transfer of energy by a force that causes an object to be displaced; the product of the component of the force in the direction of the displacement and the magnitude of the displacement
AI-Robot
why is it from light to gravity
Esther Reply
difference between model and theory
Esther
Is the ship moving at a constant velocity?
Kamogelo Reply
The full note of modern physics
aluet Reply
introduction to applications of nuclear physics
aluet Reply
the explanation is not in full details
Moses Reply
I need more explanation or all about kinematics
Moses
yes
zephaniah
I need more explanation or all about nuclear physics
aluet
Show that the equal masses particles emarge from collision at right angle by making explicit used of fact that momentum is a vector quantity
Muhammad Reply
yh
Isaac
A wave is described by the function D(x,t)=(1.6cm) sin[(1.2cm^-1(x+6.8cm/st] what are:a.Amplitude b. wavelength c. wave number d. frequency e. period f. velocity of speed.
Majok Reply
what is frontier of physics
Somto Reply
A body is projected upward at an angle 45° 18minutes with the horizontal with an initial speed of 40km per second. In hoe many seconds will the body reach the ground then how far from the point of projection will it strike. At what angle will the horizontal will strike
Gufraan Reply
Suppose hydrogen and oxygen are diffusing through air. A small amount of each is released simultaneously. How much time passes before the hydrogen is 1.00 s ahead of the oxygen? Such differences in arrival times are used as an analytical tool in gas chromatography.
Ezekiel Reply
please explain
Samuel
what's the definition of physics
Mobolaji Reply
what is physics
Nangun Reply
the science concerned with describing the interactions of energy, matter, space, and time; it is especially interested in what fundamental mechanisms underlie every phenomenon
AI-Robot
what is isotopes
Nangun Reply
nuclei having the same Z and different N s
AI-Robot
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Anatomy of a game engine. OpenStax CNX. Feb 07, 2013 Download for free at https://legacy.cnx.org/content/col11489/1.13
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Anatomy of a game engine' conversation and receive update notifications?

Ask