Public Member Functions | |
Cgame (const char *gamename, int new_screen_width, int new_screen_height, int random_number_seed) | |
int | advance (uint32 keys, int32 joystick_x, int32 joystick_y) |
Advance the game one cycle. | |
void | set_pause (bool new_paused) |
Pause or unpause the game. | |
bool | get_pause (void) |
return the current pause status | |
Private Member Functions | |
void | draw_all (void) |
Draw everything in the view to the screen buffer. | |
Private Attributes | |
int | width |
The width of the game map in tiles. | |
int | height |
The height of the game map in tiles. | |
int * | map |
The game map. It is allocated and initialized in the constructor. | |
char | name [32] |
The name of the game. | |
int | screen_width |
The width of the screen, and the offscreen buffer. | |
int | screen_height |
The height of the screen, and the offscreen buffer. | |
bool | paused |
Paused games do not advance. They do redraw though. | |
int | view_x |
int | view_y |
All functionality to run on a machine is provided by the Host API.
|
Create a game sized for the screen. |
|
Advance the game one cycle. This performs the normal work to advance the game. It takes the input and updates the world. It then draws the results in an offscreen buffer. The offscreen buffer is copied to the screen at the start of the next cycle. By drawing at a consistent time interval the results appear smooth. Some input latency is added because the results appear one time period after the input is taken, but it is not noticeable.
|
|
Draw everything in the view to the screen buffer. The model is that the buffer is erased and then everything is drawn. An alternative model is to undraw the objects (by restoring saved pixels) and then drawing all again. The second is faster when the number of objects is small or the background is expensive to raw. The game could be tuned to switch between both, depending on which should be faster. |
|
Pause or unpause the game. The effect from pausing a games is noticeable until the game advances. A paused game ignores the input, and does not advance. It only redraws. A paused game also may display a message that it is paused, or it may display a game menu. |
|
The view's top left is at a fixed point offset from the top left of the screen buffer. The coordinates are 10 * tile, meaning the fraction has a range of ten and represents a portion of a tile. So 25 is halfway in the third tile. |