game.c

来自「乒乓球游戏程序」· C语言 代码 · 共 60 行

C
60
字号
/*----------------------------------------------------------------
 * game.c -- game control routiunes
 *----------------------------------------------------------------
 *  Here I put the main game control routines.  They're normally
 *  pretty much the same, for most games.  The game_init function
 *  calls the initialisation functions for subsidiary modules as
 *  well as setting up anything this module needs.  game_shutdown
 *  reverses what game_init does -- it's generally a good idea to
 *  keep relationships between functions simple like this. 
 *  game_run plays one game; most of its work should be done by
 *  subsidiary modules.
 */


#include <allegro.h>

#include "game.h"
#include "gamevars.h"
#include "input.h"
#include "display.h"


/* game_end_flag:
 *  This flag is used to end the game -- when it is nonzero, 
 *  the game will end.
 */
int game_end_flag = 0;


/* game_init:
 *  This function sets everything up ready to play through the 
 *  game once.
 */
void game_init() {
	game_end_flag = 0;

	display_init();
	input_init();
}


/* game_shutdown:
 *  Undo everything that game_init set up.
 */
void game_shutdown() {
	input_shutdown();
	display_shutdown();
}


/* game_run:
 *  This function actually plays the game.
 */
void game_run() {
	while (!game_end_flag) {
		input_update();
		display_update();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?