23
CS 4730 Game Design Patterns CS 4730 – Computer Game Design Credit: Some slide material courtesy Walker White (Cornell)

CS 4730 Game Design Patterns CS 4730 – Computer Game Design Credit: Some slide material courtesy Walker White (Cornell)

Embed Size (px)

Citation preview

CS 4730

Game Design Patterns

CS 4730 – Computer Game Design

Credit: Some slide material courtesy Walker White (Cornell)

CS 47302

Architecture Big Picture

Credit: Walker White

CS 47303

OO to MVC• We’ve discussed how OO doesn’t quite work

for games– Not that we have to throw it all out of the window,

but class bloat can be a problem• We have also discussed MVC in which

– We have a lightweight model representing world objects

– We have a heavyweight controller in the game loop– We have a drawing method

CS 47304

The Decorator Pattern• Remember when we discussed the decorator

pattern?• The idea was that we could have objects that

we “hung” various functionality bits on that would handle how that object behaved in the world

• What if we could take that to the extreme?

CS 47305

Entity-Component-System• Another game architecture pattern is Entity-

Component-System• First really described by Scott Bilas of Gas

Powered Games and then by Adam Martin• ECS is a pattern in which each object in the

world is completely unique (as in, is represented by a single “primary key” integer)

• In fact, ECS works kinda like a database…

CS 47306

What is an Entity?• This might be a bit hard to swallow for OO

programmers• What is an Entity?

– An Entity is a globally unique number– For every discernible thing in your game-world, you

have one Entity (not one class, one actual Entity)– Entities have no data and no methods

CS 47307

What is a Component?• A Component provides an aspect of state to an

Entity– Want an Entity to have position in the world? Give

it a Spatial Component– Should the Entity have health? Add a Health

Component– Does it have velocity like a bullet? Fantastic – add

the Velocity Component

CS 47308

What is a Component?• Martin: “ALL the data goes into the

Components. ALL of it. Think you can take some “really common” data, e.g. the x/y/z co-ords of the in-game object, and put it into the Entity itself? Nope. Don’t go there. As soon as you start migrating data into the Entity, you’ve lost. BY DEFINITION the only valid place for the data is inside the Component”

• Why is this?

CS 47309

Abstraction• Everything is abstracted away!• An Entity is just a “place to hang” stuff• It’s the combination of Components that

creates a unique in-game object!• The Entity is simply a “primary key” that holds

all the Components together• Then how do things get updated?

CS 473010

What is a System?• A System is a cohesive set of functionality that

does all of one thing in the game (i.e. it holds all the behaviors)– Collision Detection– Player Input– Enemy AI and Movement– Rendering– Enemy Spawning– Physics

CS 473011

Systems

CS 473012

What good does this do?• It makes the game MUCH more modular• You can plug-and-play pretty much anything• You can change out functionality without

affecting the rest of the game• And most importantly, it can make your design

data-driven

CS 473013

Data-Driven Design• Who is involved in making a video game?

CS 473014

Data-Driven Design• Who is involved in making a game?

– Programmers– Level designers– Dialogue writers– Visual artists– Musicians– Sound effects designers– Etc…

• Not all of these folks are programmers…

CS 473015

Data-Driven Design• The idea is that all content is NOT hardcoded

into the game system• This includes:

– Art– Music– Levels– Dialogue– AI scripting– Etc…

CS 473016

Data-Driven Design• Why?

– Optimize the game creation pipeline; multiple folks working on different things

– Makes your job of creating content MUCH easier in general (put all the levels in one folder – when the game starts, it loads all the levels in that folder!)

– Could support the community to create their own content

– Easier to reuse code later (not tied to the specifics of that game)

CS 473017

Formats• How should you create your data files?• Art assets should be standard formats• Scripts, dialogue, and other text info?

– XML is a reasonable option and C# has libraries to parse it

– JSON could be an option as well, but might require more parsing

CS 473018

ECS meets Data-Driven• Users can have more control over the game if

you let them• Steam Workshop, for example• And your process should be a lot easier as well• Consider…

CS 473019

World of Warcraft – Stock UI

CS 473020

World of Warcraft – Modded UI

CS 473021

A Game Within A Game• I can’t tell you how much time I’ve spent

finding WoW mods…• Example lua code for WoW:function HelloWorld() print("Hello, World!"); end

CS 473022

A Game Within A Game• XML Document that goes with it:<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\..\FrameXML\UI.xsd"> <Script File="HelloWorld.lua"/> <Frame name="HelloWorldFrame"> <Scripts> <OnLoad> HelloWorld(); </OnLoad> </Scripts> </Frame></Ui>

CS 473023

StarWarrior Example• See the StarWarrior MonoGame example using

the Artemis ECS Framework!