How do games work? Game Workshop July 4, 2006
Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects
Game entities Items the player interacts with More precisely, a self-contained piece of logical interactive content Example: Player character Enemies Walls to collide with Not: Background map & music
Game entities in GM In GameMaker, entities are OBJECTS Other items are in the game too Sprites Sounds Backgrounds Tiles
Computer runs the game How? What does it have to do? Draw the background Play music Draw entities Detect key presses Detect mouse Detect collisions of entities Send messages Do calculations (math) Control items: if no lives then end game
When do we do them? How many times a second?
Your computer Draws the screen about times in one second Games do all the tasks we wrote about times a second also
Game loops Games are driven by a game loop that performs a series of tasks every frame Some games have separate loops for the front and and the game itself Other games have a unified main loop
Game Loop Does each of the tasks for running the game Repeats times per second Does the order of tasks matter? Sometimes Sending network messages is important for time-dependent multi-player games
Tasks Handling time Gathering player input Networking Simulation Collision detection and response Object updates Rendering Other miscellaneous tasks
Coupling Can decouple the rendering step from simulation and update steps Results in higher frame rate, smoother animation, and greater responsiveness Implementation is tricky and can be error-prone To do it, we make simple calculations for the rendering, and correct them later when we get the math results
Execution order Most of the time it doesn't matter In some situations, execution order is important Can help keep player interaction seamless Can maximize parallelism Exact ordering depends on hardware
Updating game objects Updating each object once per frame can be too expensive Can use a tree structure to impose a hierarchy for updating Can use a priority queue to decide which entities to update every frame
Loading levels When we change levels we need to load all the resources and objects for the level Also have to load the “game state” – states for all the game objects/entities This can take some time