introducing your game engine part 1 games fundamentals © by jarek francik kingston university,...
TRANSCRIPT
Introducing your Game EnginePart 1
Games Fundamentals© by Jarek Francik
Kingston University, London
February 2008
KU Games Fundamental Classes
• A skeleton for:– a windowed application– full-screen application– applet
• Organising your animation loop– drawing your screen– updating your screen
• Providing Sprites
KU GFC Library Structure
• Package: kingston.gamefx– class: Game– class: GamePanel– class: GameWinApp– class: GameApplet– class: GameGraphics
• Package: kingston.sprite– class: Sprite
• subclasses: RectSprite, CircleSprite, BitmapSprite
– class: SpriteList
Structure of a Windowed Game
Game
GameWinAppGamePanel
Structure of a Windowed Game
• GameWinApp – creates Game Windowyou just need to create an instance
• GamePanel – displays and controls the gamea game panel is created automaticallyand you'll rarely use this class directly
• Game – the Game Enginethat's what's you're going to do:develop a Game-derived class to implementyour very own class
A Windowed Game – what to do?
• Develop your Game Class
• Add your main function to:– Create an instance of your Game Class– Create an instance of GameWinApp– Start your game
A Windowed Game – what to do?
public static void main(String[] args)
{
Game game = new MazeGame(800, 600);
GameWinApp app = new GameWinApp();
app.openWindow("Crazy Maze", game);
}
Full Screen Games
• GameWinApp objects can run them, too!
• to open a windowed game:
app.openWindow("Crazy Maze", game)
• to open a full-screen game:
app.openFullScreen(game)
Full Screen Games
final static boolean bFullScreen = false;
public static void main(String[] args) {Game game = new MazeGame(800, 600);GameWinApp app = new GameWinApp();if (bFullScreen)
app.openFullScreen(game);else
app.openWindow("Crazy Maze", game);}
Applets
• GameApplet class derived from JApplet, standard java applet class
• Every applet class must be initialised
1. Create a GameApplet derived class
2. Write a simple init() method
Applets
public final class Maze extends GameApplet { // mandatory... private static final long serialVersionUID = 1;
// Applet Initialisation goes here...public void init(){
setGame(new MazeGame(800, 600));super.init();
}}
Universal Games
• Combine them both:– create a regular Applet class– add the main method for the windowed game
package kingston.games.maze;
import kingston.gamefx.Game;import kingston.gamefx.GameApplet;import kingston.gamefx.GameWinApp;
public final class Maze extends GameApplet {
private static final long serialVersionUID = 1; final static boolean bFullScreen = false;
// Applet Initialisation goes here...public void init(){
setGame(new MazeGame(800, 600));super.init();
}
public static void main(String[] args) {
Game game = new MazeGame(800, 600);GameWinApp app = new GameWinApp();if (bFullScreen)
app.openFullScreen(game);else
app.openWindow("Crazy Maze", game);}
}