Game (Chili Framework)
The Game
class is where you put the code to make the game do the things. The predefined member functions UpdateModel()
and ComposeFrame()
are where you put your game logic and your rendering code, respectively. Game
is composed of the Graphics
object used for drawing and keeps a reference to the MainWindow
object to interface with the Windows system (which includes the keyboard and mouse inputs).
Contents
How to Do the Thing
The Game
class is meant to be modified by the programmer (that's you dawg). I'm not talking some crazy bagel head shit here, I'm talking about pure C++ crack codecaine (hook it in my veins!!). Slam some drawing code into ComposeFrame()
and watch it ejaculate ropey strands of pixels onto your screen. Add some member variables to the class definition (in the Game.h
file) to keep track of game state between frames. Add some private functions to Game
to break up complex procedures into simple ones, or to allow code that appears in multiple places to unified to a single function.
Members
ComposeFrame
void Game::ComposeFrame()
This is where you draw what is happening in the game's world on the screen so that the player will know what the fuck is going on. Try to avoid putting game logic here, and Chili will try to avoid putting his Möbius dildo up your butt.
UpdateModel
void Game::UpdateModel()
This is where you put the code for updating the game's internal simulated state. Read inputs, move shit, spawn shit, kill shit, it's all good. Just don't put any drawing code here or Chili will fuck you with his Möbius dildo. When you get a little more advanced, you'll want to measure the time between frames so you can step the game simulation forward at proportional rate.
Game (constructor)
Game::Game( class MainWindow& wnd )
Gets called when the Game
object is created and creates the Graphics
object. Put your initialization code here and it gets executed once at the start of the program. Good deal.
Game (destructor)
Game::~Game()
Gets called when the Game
object is destroyed and destroys the Graphics
object. Put your final dying statements here and they get executed once at the end of the program.
Go
void Game::Go()
Go()
is called from the Windows message loop, and it causes the Game
object to simulate and render a single frame of the game. The body of Go()
calls UpdateModel()
, clears the framebuffer, calls ComposeFrame()
, and presents the frame to the user. Generally speaking, ne touche pas.
Member variables
gfx
Graphics Game::gfx
The Graphics
object is embedded in Game
. Use it to make pretty drawings. My name is Simon and I like to do drawings. - Simon
wnd
MainWindow& Game::gfx
Game
maintains a reference to the MainWindow
object so that you can get keyboard and mouse input (the Keyboard
and Mouse
objects are embedded in MainWindow
) and so that you can access certain Windows functionality (like checking if the window is minimized or displaying a message box).
See also
- The Chili Framework