ARCHITECTURE FOR CASUAL GAMES How to finish coding a game without despising it. Keith Peters BIT-101 / Wicked Pissah Games
Great Idea! Complete (or not...) Prototype/ Proof of Concept Pain and Suffering Start Coding Complexity Enters
GAME ARCHITECTURE The cure to all your problems. (probably not, but it will help)
FRAMEWORKS & TOOLKITS flixel http://flixel.org PushButton Engine http://pushbuttonengine.com
THREE QUESTIONS Is there a need for Game Architecture? How about Casual Game Architecture? If so, what should it consist of?
Controller Model
Input Model
THE GAME LOOP while(!gameover) { pollinput(); updategame(); renderscreen(); sleep(16); }
INPUT Where is the mouse? Is it up? down? Did it click? Double click? Which keys are down? Which formerly down keys are now up? Which keys were tapped?
UPDATE GAME Input moveleft() Model update() Object update() update() update() Character Item
Domain Driven Design by Eric Evans
RENDER SCREEN Draw everything in the model to the screen.
GAME LOOP SUMMARY Input Update model Render Controller Model View
SO WHAT ABOUT FLASH?
FLASH GAME LOOP Obviously, no while loop, no sleep EnterFrame or Timer
addeventlistener(event.enter_frame, onenterframe); function onenterframe(event:event):void { pollinput(); updategame(); renderscreen(); }
INPUT Built in input events: Keyboard, Mouse, etc. Keyboard Manager? KeyboardManager.keyIsDown(Key.SPACE) Poll for input 30x a second? Or use events?
Polling Events Model Model the shift key is down! the shift key is down! Controller Input Layer is the shift key down? is the shift key down? is the shift key down? Controller Input Layer the shift key is down!
POLLING // do every frame: function pollinput():void { if(keymanager.keyisdown(key.shift)){ model.doublespeed(); } else { model.normalspeed(); } }
EVENTS function onkeydown(event:keyboardevent):void { if(event.keycode == Key.SHIFT){ model.doublespeed(); } } function onkeyup(event:keyboardevent):void { if(event.keycode == Key.SHIFT){ model.normalspeed(); } }
ADDITIONAL INPUT Flash Microphone Camera iphone Accelerometer Touch
RENDERING Sprites and MovieClips: you dont need to re-render every frame. Change position, maybe rotation to match model. Update animation (timeline frame, bitmap sprite sheet)
MODEL Integrate view and model?
Controller View Model render loop update loop Item Item Item Item Item Item (Display Objects) (Data Objects)
Controller View Model update and render loop Item Item Item (Display Objects)
ANEMIC MODEL Model objects with little or no behavior little more than bags of getters and setters Logic implemented outside the model objects.
ship.position.x += ship.velocity.x; ship.position.y += ship.velocity.y; ship.shootbuttondown = inputlayer.shoot; if(ship.canshoot && ship.shootbuttondown) { ship.isshooting = true; } if(ship.isshooting) { ship.canaccelerate = false; }
ship.shootbuttondown = inputlayer.shoot; ship.update(); // in ship.update(): position.x += velocity.x; position.y += velocity.y; if(canshoot && shootbuttondown){ isshooting = true; } if(isshooting){ canaccelerate = false; }
A GAME IS MORE THAN A GAME LOOP
WHAT DOES A GAME NEED? State Machine Scenes and Transitions UI Elements Buttons Menus Text Asset Management Sound / Music Management Level Management Level Editor External Level Definitions Level Chooser
ASOBU GAME TOOLKIT Loosely based on parts of cocos2d for iphone Done: State Machine Scenes and Transitions UI Elements Buttons In Progress: Asset Management Sound / Music Management Level Management External Level Definitions Menus Text
STATE MACHINE: A game is an application. Game play is one small part of that application.
High Score/ Leaderboard Help/ Instructions Level Chooser About/ Credits Game Modes Loading Game Splash Screen Sponsored by Advertisement Intro Main Menu Settings/ Options Sub Menus
STATE MACHINE a model of behavior composed of a finite number of states, transitions between those states, and actions
var director:director = new Director(); addchild(director); director.setscene(new MainMenuScene());
var director:director = new Director(); addchild(director); director.settransitionclass(slidelefttransition); director.setscene(new MainMenuScene());
UI ELEMENTS Usually don t need full component set, but almost always need: a quick and easy way to style and display text text or image based buttons - toggle-able a menu system with layout
ASSETS MANAGEMENT Loading assets Embedding Assets Runtime Shared Library based assets
SOUND MANAGEMENT Similar to asset management but... Ability to play a specific sound by ID Loop a sound Play a sound with a delay Play a sound at a volume Overall volume Mute / unmute
LEVEL MANAGEMENT Load levels as external files Embed levels Tile maps
COMPONENT ORIENTED DESIGN aka Entity Based Design
OBJECT ORIENTED Entity Character GameObject Enemy Player Weapon Vehicle Boss??? Tank
COMPONENT ORIENTED Entity Components Player Enemy Boss Character Character Character Attack Attack Gun Tank Weapon Weapon Vehicle
THAT S ALL. THANKS! www.bit-101.com www.wickedpissahgames.com kp@bit-101.com