2.3. A RCHITECTURAL D ESIGN I Example approach for game screen management.

Slides:



Advertisements
Similar presentations
2000 Prentice Hall, Inc. All rights reserved. 1 Outline 3.1Introduction 3.2Game Loop Components 3.3How to Implement in C# 3.4Adding Image to XNA Project.
Advertisements

Chapter 4 Computation Bjarne Stroustrup
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Introduction to Programming and Software Development CMPCD1017 Session 3:Requirements Analysis and Specification, Cont’d.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
ITEC113 Algorithms and Programming Techniques
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Tutorial 6 & 7 Symbol Table
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Stacks (Revised and expanded from CIT 591). What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on.
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Developing the Game User Interface (UI) Lesson 5.
Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone
9.3. P ARTICLE S YSTEMS Development of a particle system.
KeyListener and Keyboard Events Another type of listener listens for keyboard entry – the KeyListener which generates KeyEvents –to implement KeyListener,
6 th Annual Focus Users’ Conference 6 th Annual Focus Users’ Conference Teacher Uploads, Tests, and Answer Key Only Tests Presented by: Kori Watkins Presented.
Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#
Rob Miles. Creating a Working MoodLight We know that colours in XNA are stored as values which represent the amount of red, blue, green and transparency.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Module 3: Steering&Arrays #1 2000/01Scientific Computing in OOCourse code 3C59 Module 3: Algorithm steering elements If, elseif, else Switch and enumerated.
GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar.
2.1. T HE G AME L OOP Central game update and render processes.
Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is written in a programming language – C# is a programming.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 1.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Data Structures & Algorithms
Object Oriented Analysis & Design Game Patterns. Contents  What patterns are  Delegation  Game Loop  Scene Graph  Double Buffering  Component 
CHAPTER 3 Getting Player Input XNA Game Studio 4.0.
M1G Introduction to Programming 2 5. Completing the program.
MOBILE COMPUTING D10K-7D02 MC05: Android UI Design Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
11 Using the Keyboard in XNA Session 9.1. Session Overview  Discover more detail on how the XNA keyboard is implemented  Find out how to use arrays.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Rob Miles. Using data in an XNA game program An XNA game program Draw and Update methods that are called to run the game Colours are held in XNA as four.
5.3. S ECTION R OUNDUP Exploration of project hand-in and section roundup.
Rob Miles. Creating a Broken MoodLight An XNA game contains game data which is used by the Draw and Update methods – Update updates the game data – Draw.
HTBN Batches These slides are intended as a starting point for further discussion of how eTime might be extended to allow easier processing of HTBN data.
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
Selection Using IF THEN ELSE CASE Introducing Loops.
Introducing Instructions
Eclipse Navigation & Usage.
Project Snake. Project Snake Snake For this project, we’re going to make Snake This includes Making the overall game logic (using a 2D array) Handling.
Sequence Diagrams.
Increased Efficiency and Effectiveness
Stacks.
int [] scores = new int [10];
2.3. Architectural Design I
Central game update and render processes
Stacks.
Development of a particle system
True / False Variables.
Stacks.
Presentation transcript:

2.3. A RCHITECTURAL D ESIGN I Example approach for game screen management

In lecture exploration of answers to frequently asked student questions

Exploration of an example game screen manager

The front-end to most games will feature a series of navigatable screens (e.g. configuration, high- score, etc.). Additionally, whilst being played, many games will permit other screens (e.g. options screen) to sometimes appear on top of the main game screen. Also, the different levels, etc. within a game can also be viewed as a set of screens. It is desirable to have some means of easily controlling the management (adding, removing, displaying, etc.) of screens.

The following draws upon the Game State Management XNA tutorial Game Engine loop { ScreenManager.Update () ScreenManager.Draw() } Game Screen Update { Update objects() } Draw { Draw objects() } Screen Manager Update () { Update screens } Draw() { Consider screen rendering } The core game engine makes use of a screen manager that is responsible for updating and rendering game screens. The screen manager contains a list of screens to be managed.

Design/implementation highlights of a screen manager class

Aside: The ScreenManager is added to the Game instance as a drawable game component ScreenManager screenManager = new ScreenManager(this); Components.Add(screenManager); public class ScreenManager { List screens = new List (); Stack screensToUpdate = new Stack (); InputState input = new InputState(); SpriteBatch spriteBatch; } The ScreenManager contains a list of managed GameScreens. A stack of GameScreens to be updated is formed each update. Input (InputState) and output (SpriteBatch) setup is handled within the Screen Manager and made available to each screen.

The input state is evolved for the update tick. GameScreens are pushed onto the update stack (screens added last will be updated first) Flags are assigned initial values. public override void Update(GameTime gameTime) { input.Update(); foreach (GameScreen screen in screens) screensToUpdate.Push(screen); bool otherScreenHasFocus = !Game.IsActive; bool coveredByOtherScreen = false; // Update screens... }

while (screensToUpdate.Count > 0) { GameScreen screen = screensToUpdate.Pop(); screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (screen.ScreenState == ScreenState.TransitionOn || screen.ScreenState == ScreenState.Active) { if (!otherScreenHasFocus) { screen.HandleInput(input); otherScreenHasFocus = true; } if (!screen.IsPopup) coveredByOtherScreen = true; } } Each screen is updated in reverse add order (those added last are updated first) The flags permit context specific screen update Only the topmost ‘active’ screen is permitted to handle user input.

public override void Draw(GameTime gameTime) { foreach (GameScreen screen in screens) { if (screen.ScreenState != ScreenState.Hidden) screen.Draw(gameTime); } } All non-hidden screens are asked to draw themselves. GameScreens can be added to the manager public void AddScreen(GameScreen screen) { screen.ScreenManager = this; screens.Add(screen); } Aside: It is intended that the GameScreen instance will decide when to remove itself by calling a RemoveScreen method. Think about the usage assumptions this design decision introduces.

Design/implementation highlights of a game screen class

public enum ScreenState { TransitionOn, Active, TransitionOff, Hidden } bool isPopup = false; bool isExiting = false; bool otherScreenHasFocus; ScreenState screenState = ScreenState.TransitionOn; TimeSpan transitionOnTime = TimeSpan.Zero; TimeSpan transitionOffTime = TimeSpan.Zero; An enumerated type of the valid screen states is defined. The GameScreen holds flags defining if it is a pop-up screen (assumed persistent), or if it is currently exiting (valid over several frames), or another screen has the input focus (valid for this update only). A fade transition time for the screen appearing and disappearing is also defined.

The update firstly checks to see if the GameScreen is exiting. If not, it then checks to see if it is a covered screen If not, it finally checks to see if the screen needs to transition on and become active public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (isExiting) { // Deal with exit } else if (coveredByOtherScreen) { // Deal with covered screen } else { // Check for transition on } } Why is it good to declare this as virtual? Extending classes will extend Update() to provide screen specific behaviour

If exiting, wait until the fade is complete and then remove the screen If covered, fade screen out and enter hidden state Otherwise, if screen is not already active, fade it in and make active if (isExiting) { screenState = ScreenState.TransitionOff; if (!UpdateTransition(gameTime, transitionOffTime, 1)) ScreenManager.RemoveScreen(this); } else if (coveredByOtherScreen) { if (UpdateTransition(gameTime, transitionOffTime, 1)) screenState = ScreenState.TransitionOff; else screenState = ScreenState.Hidden; } The UpdateTransition method fades the screen in / out, returning true whilst doing this and false when finished else { if (UpdateTransition(gameTime, transitionOnTime, -1)) screenState = ScreenState.TransitionOn; else screenState = ScreenState.Active; }

public virtual void Draw(GameTime gameTime) { } The Draw method is declared virtual, with no inheritable implementation – i.e. it’s up to each game screen how it will be drawn To explore this tutorial in greater depth, see the Game State Management tutorial from:

To do: Submit Project Development Report with details of game idea, team, development language Complete setup of development environment (XNA / Java) and play about with some tutorials, etc. Today we explored: An example implemen-tation of a game screen manager