cs 179.14 pc/console game programming/development

31
CS 179.14 PC/CONSOLE G AME PROG RAMMING/DEVELOPMENT CHA PTER 2: DRAW ING, DATA AND CONTROLS

Upload: joyce

Post on 22-Feb-2016

78 views

Category:

Documents


0 download

DESCRIPTION

CS 179.14 PC/Console Game Programming/development. Chapter 2: Drawing, Data and controls. Table of Contents. Final Project Guidelines XNA Programming: - Data Storage - Basic Graphics - Player Input Game Design Notes: Game Genres (Expanded). Final Project guidelines. Breaking it down. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 179.14 PC/Console Game Programming/development

CS 179.14 PC/CONSOLE GAME

PROGRAMMING/DEVELO

PMENT

C H A P T E R 2: D

R A W I NG , D

A T A AN D C

O N T R O L S

Page 2: CS 179.14 PC/Console Game Programming/development

TABLE OF CONTENTSFinal Project GuidelinesXNA Programming:

- Data Storage- Basic Graphics- Player Input

Game Design Notes: Game Genres (Expanded)

Page 3: CS 179.14 PC/Console Game Programming/development

FINAL P

ROJECT

GUIDELINES

B R E A K I NG I T

DO W N

Page 4: CS 179.14 PC/Console Game Programming/development

PROGRAMMING PROJECTThis programming project is targeted for CS Major Student

groupsCreate a game that consists of the following requirements:a.) Genre: Any Genre will fitb.) Game Length: Trial Length (10-20 minutes long / 1 – 2

stages) and will automatically show top score, and go back to main title

c.) Graphics: 2D or 3D (no bonus points for high level 3D)d.) Sound: No profanities or anything similare.) Content: Basic story, not epic. A kid – adult game.

Page 5: CS 179.14 PC/Console Game Programming/development

PROGRAMMING PROJECTGrade Breakdown:Graphics: 30%Sound: 10%Story / Content: 40%Controls / Ease of use: 20%Total 100% (or A)

Page 6: CS 179.14 PC/Console Game Programming/development

GAME DESIGN PROJECTThis project is targeted for non CS Major groupsThe premise of this project is to have the groups create a game

concept from the ground up until marketing the game, without having programming the game.

The game will need to have the following elements:a.) Game Concept: Genre and Theme and Elementsb.) Character/s - background of the character and their designsc.) Game Story – Major events of the game in detaild.) Availability – which platform will it be?e.) Marketing – Market the created Design and Concept of the

Game.

Page 7: CS 179.14 PC/Console Game Programming/development

GAME DESIGN PROJECTGrade Breakdown:Game Concept: 20%Character Design: 15%Game’s Story: 25%Marketing: 20%Appeal: 20%Total: 100% (or A)

Page 8: CS 179.14 PC/Console Game Programming/development

XNA PROGRAMMING

D R A W I NG , D

A T A AN D C

O N T R O L S

Page 9: CS 179.14 PC/Console Game Programming/development

DRAWING OBJECTS IN XNAIn this section, we will learn more about the creation of

drawings in XNA, how data is savedWe will create a sample program called MoodLight to simulate

the various drawing or coloring the application can do.It will for now, be without controls and will change colors using

combinations of if statements.

Page 10: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNABasic Programing Diagram:

DataCompu

ter Progra

mData

Page 11: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNATo begin programming, we open up our previous sample file

we’ve created. Else, we open up a new Project and save it as MoodLight.

We open up the file called Game1.csLook at the following method:

Protected override void Draw(GameTime gameTime){

GraphicsDevice.Clear(Color.CornflowerBlue);

//TODO: Add your drawing code here

base.Draw(gameTime);}

Page 12: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNAThe method contains instructions to draw something on the

screen. GraphicsDevice.Clear(Color.CornflowerBlue);

This method implies to clear the screen of the device with the color called CornflowerBlue. The method Clear (it’s already a premade method like Draw without the need to change the code) is one of the built in methods belonging in the XNA Framework. We can change it to another color if we want it to.

We will modify this method to provide our own color. We will be declaring variables to set the new color.Color backgroundColor;

Page 13: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNAAssigning a color value to the variable backgroundColor:

We now replace the previous value in the Clear method with backgroundColor.

GraphicsDevice.Clear(backgroundColor);

= new Color (0,0,0);backgroundColor

Page 14: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNAThe resulting updated method will now have:

Protected override void Draw(GameTime gameTime){

Color backgroundColor;backgroundColor = New Color (0,0,0);GraphicsDevice.Clear(backgroundColor);base.Draw(gameTime);

}

Page 15: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNAThe behavior of the graphic depends on the update method

being run. We will now manipulate the colors using conditions inside the

Update method of the code. Later in the next part, manual controls shall be used to update the colors.

Firstly, we will need to create several variables for the colors Red, Green and Blue. They are named redIntensity, greenIntensity, and blueIntensity. They are declared as type byte (smallest unit of memory used in a game).

We will use byte as it saves up on memory, especially in this case that we might end up creating a game for XBOX or even a phone or Zune device which has very limited memory (512MB for XBOX).

// The Game World - our color values byte redIntensity; byte greenIntensity; byte blueIntensity;

Page 16: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNAIn order to make the colors change, we will have to add in logic

that will make the values change. We will be using IF statements to control the change when we

update the colors.

The simple diagram above shows the basic IF statement that if the redCountingUP value is still counting up (TRUE) then the value of redIntensity is increased by 1.

If ( redCountingUP ) redIntensity++;

condition statement

Page 17: CS 179.14 PC/Console Game Programming/development

DRAWING IN XNAHowever, there are cases where we may need to do an

alternative step if the statement is false.

If ( redCountingUP ) redIntensity++ else redIntensity--;

condition statement Statement done if false

Page 18: CS 179.14 PC/Console Game Programming/development

DRAWING XNAOpen the folder 04 MoodLight in the samples folder of XNA

development to see the final product.

Another variation is found in 05 MoodLight folder, which has a different behavior in changing lights.

Page 19: CS 179.14 PC/Console Game Programming/development

CONTROLS IN XNAIn video games, there are several ways to control it.a.) Joysticksb.) Control Padsc.) Keyboard and Moused.) Touche.) Motion

Page 20: CS 179.14 PC/Console Game Programming/development

CONTROLS IN XNATo make games work in XNA, we need to understand the basic

control statement when codingWe use the GamePad class to reference our controls to a game

pad. We use the method GetState to read the state of our game pad. Here’s an exampleGamePadState

ButtonsGreen A ButtonState.PressedRed BButtonState.ReleasedBlue XButtonState.ReleasedYellow YButtonState.ReleasedStartButtonState.ReleasedBackButtonState.Released

Page 21: CS 179.14 PC/Console Game Programming/development

CONTROLS IN XNATo read a specific gamepad, we implement this line inside the

game code:GamepadState pad1 = GamePad . GetState ( PlayerIndex.One );

GamepadState called pad1 GamePad class that

looks after gamepads

Method that getsthe state of a gamepad

GamePad being read

Page 22: CS 179.14 PC/Console Game Programming/development

CONTROLS IN XNAWe can test out the controls in XNA by modifying the previous

exercise (MoodLight) code to allow controls.

If ( pad1.Buttons.B == ButtonState.Pressed ) redIntensity++ ;

Button pressed Statement done if trueValue we’re looking for

Page 23: CS 179.14 PC/Console Game Programming/development

CONTROLS IN XNAWe modify the Moodlight code with the following:

We also modify the MoodLight code to remove the previous exercise of automating the color change

Protected override void Update(GameTime gameTime){

// Allows the game to exitif (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)

this.Exit();

GamePadState pad1 = GamePad.GetState(PlayerIndex.One);

if(pad1.Buttons.B == ButtonState.Pressed) redIntensity++;if(pad1.Buttons.X == ButtonState.Pressed) blueIntensity++;if(pad1.Buttons.A == ButtonState.Pressed) greenIntensity++;

base.Update(gameTime);}

Page 24: CS 179.14 PC/Console Game Programming/development

CONTROLS IN XNATo find out more on Game Controller Input. Get this file from: http://create.msdn.com/en-US/education/catalog/utility/input_reporter

Input Reporter

Page 25: CS 179.14 PC/Console Game Programming/development

GAME DESIGN NOTES

G A M E GE N R E S

Page 26: CS 179.14 PC/Console Game Programming/development

GAME GENRESAction / Adventure Games- Objective: to get to the other side of the map, exploration,

earn treasure/points, use tools to defeat enemies- Graphics: early years are in 2D, current generation of games

moving into open world (3D).- Early sample of action/adventure games: Pitfall! - Notable existing works: Super Mario, Sonic the Hedgehog,

Prince of Persia, Megaman, Metroid, Assassins Creed, Metal Gear, Grand Theft Auto, Devil May Cry, Resident Evil

Page 27: CS 179.14 PC/Console Game Programming/development

GAME GENRESRhythm GamesObjective: Time the button presses correctly to stay in rhythm

and earn more points. Try to perfect a round without missing a beat/step

Graphics: 3D or 2DMusic: Driven by either Japanese pop music, Pop Music, Rock

MusicEarly sample of Rhythm Games: Pa Rappa the Rapper,

BeatmaniaNotable Existing Works: Dance Dance Revolution, Guitar Hero,

Rockband, Guitar Mania, Drum Mania

Page 28: CS 179.14 PC/Console Game Programming/development

GAME GENRESReal Time Strategy GamesObjective: Beat your enemy/enemies by building structures,

training units and gathering resourcesGraphics: 2D Grid or 3D 2/3 Isometric ViewEarly Sample: Dune I and Dune IINotable Existing works: StarCraft series, Command and

Conquer series, Age of Empire Series, Company of Heroes series, Sins of a Solar Empire, Star Control series

Page 29: CS 179.14 PC/Console Game Programming/development

GAME GENRESRacing GamesObjective: earn the highest score until time runs out / beat all

opponents to the finish line / earn the highest points in drifting / get to the finish line before time runs out / get the fastest time in a race / Out Drag everyone

Graphics: Overhead 2D, Rearview 2D, 3D (various angles)Early Sample: Pole Position, Out Run, Road BlastersNotable Existing works: Need for Speed, Gran Turismo, Grid,

F1, Midnight Club, GTR, Burnout, Auto Modellista

Page 30: CS 179.14 PC/Console Game Programming/development

GAME GENRESShooting GamesObjective: Shoot down as many ships as possible and beat the

final boss. Earn the most number of points in a game.Graphics: 2D overhead, sideways, front facing, 3D first person,

third personEarly Samples: Battle City, Wolfenstein , SpaceWar, Space

Invaders, Macross, Operation WolfNotable Existing Works: Ace Combat, Gears of War, Counter

Strike, Medal of Honor, Call of Duty, Halo, Unreal Tournament, Time Crisis, Rainbow Six, Ghost Recon, ARMA, Bioshock

Page 31: CS 179.14 PC/Console Game Programming/development

GAME GENRESRole Playing GamesObjective: Be the strongest possible to beat the final boss,

save the world and get the girlGraphics: 2D side scrolling, overhead, isometric / 3D Early Samples: Dungeons and Dragons, Phantasy Star, Final

FantasyNotable Existing works: Final Fantasy, Xenogears, Fallout,

Kingdom Hearts, Suikoden, Fable, Dragon Age, Diablo