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.

Slides:



Advertisements
Similar presentations
How to Make a Game Like Space Invaders. What IS Space Invaders? a SHMUP (shoot-em-up) Player has one ship, enemy has many Player and enemies interact.
Advertisements

Create a Simple Game in Scratch
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Teaching with Greenfoot
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Game Rules Implementation Lecture 5 1. Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and.
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.
1 Flash Actionscript Animation. 2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create.
Sketchify Tutorial Graphics and Animation in Sketchify sketchify.sf.net Željko Obrenović
MASHOOQ,RAHUL,SANAT AND YIBIN, SAVING MANKIND SINCE SPRING 2011.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
2D Physics and Camera Systems For CSE 3902 By: Matt Boggus.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Guide to Programming with Python
Lua & Love2D Game Engine GALAGUH
SOURCE 2006 Presentation by Luke Arntson Game Programming Optimization.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0 Key Abstractions in Game Maker Foundations of Interactive Game Design Prof. Jim Whitehead.
Introduction to TouchDevelop
We will be creating a spaceship that simulates real movements in space. The spaceship will fire a laser beam that can destroy targets. The spaceship will.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Section 8.1 Create a custom theme Design a color scheme Use shared borders Section 8.2 Identify types of graphics Identify and compare graphic formats.
CoderDojo Roscommon. Today's Ninja Challenge: Create a GhostBuster Game Like This.
Idea1 : Net Aooni Arcade Idea2 : Shooting Arcade Project Brainstorming Computer Game 2011 Fall ♣ Lee Sang Min.
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.
Sample Video Game & Sound. The Plan 1.Game Theme 2.Game Structure 3.Sprites 4.Trackers 5.Collisions 6.Score 7.Levels 8.Splash Screens 9.Design 10.Implementation.
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the.
Programming Video Games
Microsoft® Small Basic Collision Detection Estimated time to complete this lesson: 1 hour.
Game Maker Terminology
Geometry. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions are.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Shooters in GameMaker J Parker.
Game Creation in XNA CS470 Final Project Chris Ragland.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Team 2: Gamers & Coders Final Sprint Presentation.
Guide to Programming with Python Week 15 Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Team 2: Gamers & Coders ‘ The Last Warrior’ Android Game Application By Chinmay Kulkarni, Darshan Shinde, Matt Frey, Peng Ye, Satoshi Inoue & Shachi Chandrashekhar.
Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.
Point Sprites Course Information CVG: Programming 4 My Name: Mark Walsh Website: Recommended.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Final Project Proposal Space Invaders By Jordan Mahaffey.
Game Maker Galactic Mail Advanced Group: Complete Galactic Mail, then start developing an independent project.
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
Graphics Final Project: TANK! Zak Andree Kevin Pang Ed Kim.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Dr Nick Mitchell (Room CM 224)
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
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.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
2D Graphics CMT3311. This covers... How to make a transparent sprite How to add a sprite to your project and draw it Properties of sprites and how to.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Object Animation CMT3317. Do you need to do animation? We consider ways of animating composite objects – that have a number of different parts e.g. a.
Index Background Costumes Making object walk smoothly Controlling an object with the keyboard Control an object with the mouse Changing costume when hit.
Unit 2.6 Data Representation Lesson 3 ‒ Images
Section 8.1 Section 8.2 Create a custom theme Design a color scheme
2D Physics and Camera Systems
Example: Card Game Create a class called “Card”
Tutorial on using Java Sprite Animation
Flappy bird Demo: Lesson 5 Flappy bird Demo:
Creating a Simple Game in Scratch
Chapter 7 The Game Loop and Animation
Presentation transcript:

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 including: –game loop structuring – XNA does this –basic datatype specs for sprites and images –sprite movement –behaviour of game objects –collision detection – etc...

Example 2D game We will look at –Requirements for game –How to model game state with a finite state machine –Graphic requirements –Specification of classes –Modelling of movement –Collision detection

Stingray design Concept - game that mixes features of asteroids and frogger – you only get a powerup if there are more than 5 stars alive - leads to distinct gameplay Theme - from Stingray Sketches, some ideas on resources needed ‘Storyboard’ design of modes of game

Requirements There will be a player controlled ship, stingray, which rotates and moves and fire bullets Enemies will fly about the screen and if they collide with stingray, stingray will lose a life Stingray can kill enemies with bullets A powerup will randomly appear on screen for a few seconds (if 5+ enemies are left) and gives lives if picked up The number of enemies will increase at each level and score recorded Explosions should be generated appropriately There should be introduction, inter level, and gameover screens

Finite state machime We will model the program as a Finite State Machine (FSM) A FSM can only be in one state at a time A FSM may transition between states A FSM can be drawn with circles for states and directed line for transitions A FSM can be translated into code

FSM of Stingray game

A FSM gives us an overall control structure – a top down approach The states are defined by an enumeration type

FSM in Code Both the Update and Draw functions will now implement the FSM by if statements If(gamestate==START){... } If(gamestate==PLAYING){... } If(gamestate==PREPARELEVEL){... } If(gamestate==GAMEOVER){... } And the game exits when escape is pressed

Transitions Transitions between states are coded in Some transitions depend on internal logic Others depend on user input e.g. moving from PREPARELEVEL to PLAYING

Graphics requirements A Set of sprites will be needed In this version of the program it was decided to not have bitmaps for backgrounds so that the window size can be resized easily The coding supported this, the screen width and height are set in the GameConstants file

Image sizes and format Aim to have your game in a 640x480 window - could be bigger or smaller though... Sprite size will be related to window size, you can scale though Powers of two are good eg: 64*64, 8*8 Various tools like Paintshop Pro/Photoshop will allow you to change the colour depth and size of sprites

Stingray sprites Stingray Bullet Explosion Enemy Powerup

Classes From the requirements a two classes were designed –Class Ship to model the stingray –Class PowerUp to model the powerup Two utility classes were also planned –Class GameConstants to store global game constants in one place –Class Helper to store any useful little functions that don’t fit in other classes

Classes The explosion, enemy and bullet objects all need more than one instance An arbitrary decision was made to implement the basic objects as structs and build a manager class for each type of struct which manages an array of them Leading to the structs: explosion, enemy and bullet And the classes ExplosionManager, EnemyManager and BulletManager

Class Ship Gets user input and responds to it while playing, rotating, moving and firing bullets Arbitrarily is responsible for doing collision detection and response with enemies and the powerup Has four functions Initialise() Reset() and Draw() are trival, Update() is more interesting though

Movement Its easy to move in eight directions (rotation by 45deg intervals) How do we do it? What if we want to move in any direction?

2D Vectors and points are both specified by 2 numbers

Unit or Normalised Vector Has a length of 1 From Pythagorus sqrt(x*x+y*y) = length =1 Unit vectors are often convenient to use in many applications But we may want to use other vector eg. A velocity vector may define both orientation in the usual way and describe speed by the length

Tracking orientation If we know the sprite’s starting orientation vector... Then when we rotate the sprite we can work out its current orientation by rotating the starting vector by the same amount

Tracking orientation

Class Ship – class variables

Rotating vectors in Update() Implements 2D rotation formula in update –x’=x*cos(theta)- y*sin(theta) and –y’= x*cos(theta)+y*sin(theta) Note how the cos and sin functions are accessed via the Math class Also note the casting going on – C# is very fussy about types …

Moving in the direction you are pointing If you know the direction you are pointing it is very easy to move forward This basic model is use to move all moving sprites including bullets and enemies

Fire bullet When the ship fires a bullet it send its position and direction

Collision detection with enemies

Collision response When ship and enemy collide a large explosion it initiated The controller is also vibrated. You have to be careful to manage vibration. It is attenuated by the Update function. It is zeroed in the Game1 function when lives fall to zero or the level is completed – otherwise it can be left vibrating when it shouldn’t be.

Ship Class The update function also does collision detection with the powerUp

Struct PowerUp The PowerUp struct is pretty straightforward. In the update function the powerup will spawn itself randomly If its already alive it will fade transparency to a certain level and then kill off the PowerUp

PowerUp Class – Update()

Manager classes The manager classes are similar they all have an array of structs to manage They all have constructor that initialise their arrays and associate the right texture with struxt They all have loops that update and draw their structs In the following we only note interesting points of these classes – see the source code for full examples

Struct Enemy This struct has an initialise function that gives the struct a random unit vector for direction a random starting position by one of the four corners of the screen a random speed

Struct Enemy

Class EnemyManager Just manages the array of enemies One interesting feature is that the distance an enemy moves is scaled by the time since it was last called This is official MS advice but I do not always or consistently implement it – you are not required to either but its not a bad thing if you do

The basic formula where factor is an arbitrary scale factor is: X’ = X+((X.direction*speed)*factor*timeDelta); Eg in EnemyManager.Update() it is:

Bullet struct The bullet struct is unremarkable It has similar variables to stingray and enemy for movement

BulletManager This class is straight forward The interesting thing is has to do is collision detection and response between bullets and enemies – shown next

BulletManager Update()

Explosion effect The explosion effect implemented is very simple The sprite is rotated and scaled and made increasingly transparent over time The scale factor is varied to ditinguish between a big explosion (and enemy hitting the ship) and a little on (a bullet hitting an enemy)

CreateExplosions

Explosion.Update()