introducing your game engine part 1 games fundamentals © by jarek francik kingston university,...

13
Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

Upload: elwin-cook

Post on 01-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

Introducing your Game EnginePart 1

Games Fundamentals© by Jarek Francik

Kingston University, London

February 2008

Page 2: Introducing your Game Engine Part 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

Page 3: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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

Page 4: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

Structure of a Windowed Game

Game

GameWinAppGamePanel

Page 5: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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

Page 6: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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

Page 7: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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);

}

Page 8: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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)

Page 9: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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);}

Page 10: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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

Page 11: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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();

}}

Page 12: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

Universal Games

• Combine them both:– create a regular Applet class– add the main method for the windowed game

Page 13: Introducing your Game Engine Part 1 Games Fundamentals © by Jarek Francik Kingston University, London February 2008

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);}

}