<< Chapter < Page Chapter >> Page >

What is a concrete method definition

Not much is required to provide a concrete method definition. All that is necessary to define concrete methods that return void is to replicate the signature of the abstract method and to provide an empty body delineated by apair of empty curly brackets. If the return type for the abstract method is not void, the body of the concrete version must contain a return statement that matches the specified return type.

Five abstract methods

The interface named Game declares the five abstract methods shown in Figure 4 :

Figure 4 . Abstract methods declared in the Game interface.
boolean closeRequested() - Notification that a game close has been requested Returns: True if the game should closeString getTitle() - Get the title of this game Returns: The title of the gamevoid init(GameContainer container) throws SlickException - Initialise the game.This can be used to load static resources. It's called before the game loop starts Parameters: container - The container holding the gamevoid render(GameContainer container, Graphics g) throws SlickException - Render thegame's screen here. Parameters: container - The container holing this game,g - The graphics context that can be used to render. However, normal rendering routines can also be used.void update(GameContainer container,int delta) throws SlickException - Update the game logic here. No rendering should take place in this method though it won'tdo any harm. Parameters: container - The container holding this game,delta - The amount of time that has passed since last update in milliseconds

Concrete versions of the inherited abstract methods

As you can see in Listing 1 , the new class named Slick0110a is not declared abstract. Therefore, it must provide concrete versions of the inherited abstract methods shown in Figure 4 .

The init , update , and render methods in Listing 1 return void and are defined with empty bodies. The getTitle and closeRequested methods do not return void. Therefore each of these concrete versions contains a return statement of the required type.

Not much fun to play

As you learned earlier, the skeleton code for this Slick2D game program shown in Listing 1 can be compiled and executed. However, it isn't very much fun to play because it doesn't do anything otherthan to sit there and display the frames per second (FPS) rate in the upper-left corner of the game window. Make no mistake about it, however, thegame loop is running meaning that the game is active.

Not the recommended form

While this is probably the simplest Slick2D game program that can be written to run as a Java application, it is not the recommended form for an empty Slick2Dgame skeleton. You will learn in the next module that instead of implementing the Game interface directly, it is better to extend a Slick2D helper class named BasicGame that implements the Game interface and provides some additional services that may be useful to the gameprogrammer. However, even when you do that, it is still necessary to write code to put some meat on the skeleton'sbones to create a playable game.

Run the program

I encourage you to copy the code from Listing 1 and Listing 2 Compile the code and execute it,making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.

Summary

The main purpose of this module is to teach you about some of the characteristics of game engines and frameworks in general, and to teach you howSlick2D fits those characteristics.

More specifically, you learned what we often mean when we speak of a "game engine." You learned how that terminology relates to something that we often refer to as a "software framework."

You learned how to write a minimal Java application in conjunction with a set of Slick2D jar files to create your own Slick2D game engine. Using that programas an example, you learned about the overall structure of the Slick2D game engine.

You learned that game engines are typically service provider programs and you learned about a common set of services that is provided bymost game engines.

You learned about the two cooperating objects that form the heart of the Slick2D game engine.

You learned about the methods declared in the interface named Game .

You learned that in order to write a game program using the Slick2D game engine that will run as a Java application, you must, as a minimum,perform the steps shown in Figure 1 .

What's next?

In the next module, I will begin explaining the purpose of the methods that are inherited from the Game interface and will begin showing how you can override those methods to control the behavior of your Slick2D gameprogram.

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Slick0110: Overview
  • File: Slick0110.htm
  • Published: 02/03/13
  • Revised 06/09/15 for 64-bit
Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

-end-

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