/*This is a game.You can use the keyboard to play it */
#include"stdio.h"
#include"allegro.h"
#include"map.h" //header file for data file created by grabber
#define NO_INPUT -1 //when keyboard no input,return it.
int game_end=0; //It is to withdraw the game's marking or not.
volatile int timer = 0; //initialization for the timer
int bean_number; //the beans numbers.
int old_number; //the number alike the beans numbers.
int turn_number=1; //表示关数。等于1是表示第一关。
int left_number=22; //表示向左走时的调用的图片号。用在void show_pacleft(int row,int line)函数中
int right_number=25; //表示向右走时的调用的图片号。用在void show_pacright(int,row,int line)函数中
int up_number=27; //表示向上走时的调用的图片号。用在void show_pacup(int row,int line)函数中
int down_number=20; //表示向下走时的调用的图片号。用在void show_pacdown(int row,int line)函数中
DATAFILE *datafile; //用来装载map.dat的数据文件
BITMAP *background; //用来实现双缓冲的指针变量
/*用来在碰撞检测中记录map数组的下标号*/
int pos_x, pos_y;
int pos2_x,pos2_y;
int x=32,y=128; //the pac-man's start position
int exit_game; //标志是否退出主菜单
int grade = 1; //主菜单上的选择标志,为1时即表示开始游戏
int high=246; //主菜单上选择标志在屏幕上高的象素值
int life=4; //the pac-man's life numbers
int old_life=4;
int old_score; //用来做跟新的分数作比较,记录增加生命前的分数
int high2=178; //选项中选择标志在屏幕上高的象素值
int width=235; //选项中难度设置标志在屏幕上宽的象素值
int width2=230; //选项中选关标志在屏幕上宽的象素值
int width3=450; //选项中读取进度标志在屏幕上宽的象素值
int music=17; //选项中音乐开关的图片号
int grade2=1; //选项中的选择标志,为1时即表示设置难度
int turn=1; //作为关数设置的一个传送变量
int option_end=0; //选项菜单的退出条件
int save_life=4; //保存下的生命数,初始化值为4
int save_score; //保存下的分数值
int scores=0; //上次保存的分数
int save_level=1; //保存上次的关数,初始化值为1
int prop_x,prop_y; //道具所在位置的行列号
int quick_number=35; //表示加速道具的图片号
int score_number=33; //表示加分道具的图片号
int big_number=3; //大豆的图片号
int sign=50; //控制pac-man行走速度的比较时间,初值为50毫秒
static int quick_time=0; //加速道具的有效时间
int chance; //随机生成的道具,为1是加速道具,为2是加分道具,为3是大豆。
int g1_x=32,g1_y=32; //红色敌人的坐标值
int g2_x=576,g2_y=32; //蓝色敌人的坐标值
int g3_x=32,g3_y=352; //青色敌人的坐标值
int g4_x=576,g4_y=352; //绿色敌人的坐标值
int out=0; //强制跳出循环的标志
int weak=0; //表示敌人状态,为0表示正常。为1表示虚弱。
/* There are nine maps.The 1 means waprop_y,the 0 means beans. */
int map01[13][20]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1},
{1,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,1},
{1,0,0,0,1,0,0,1,0,1,1,0,1,0,0,1,0,0,0,1},
{1,0,1,1,0,0,1,0,0,0,0,0,0,1,0,0,1,1,0,1},
{1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1},
{1,0,0,0,0,1,0,0,1,1,0,1,0,0,1,0,0,0,0,1},
{1,0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,1},
{1,0,1,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,1},
{1,0,1,0,1,1,0,0,0,1,1,0,0,0,1,1,0,1,0,1},
{1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
int map02[13][20]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1},
{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
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