📄 pac-man.c
字号:
/*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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1}};
int savedata(); //写文件
void read_print(); //读文件
void inc_time(void); //定时器函数
void initialization_timer(); //初始化定时器,为定时器锁住内存
void environment_initialization(); //环境初始化
void game_initialization(); //游戏初始化
int get_input(); //游戏控制输入
int left(); //向左的碰撞检测
int right(); //向右的碰撞检测
int up(); //向上的碰撞检测
int down(); //向下的碰撞检测
void show_enemy(); //敌人的搜索算法
int pac_death(); //检测敌人是否抓住Pac-Man
void instauration(); //豆子的数据恢复
void add(); //豆子数的正确性维护
void change(); //实现豆子被吃效果
void show_number(); //豆子数据初始化
void show_bean(); //显示豆子
void score(); //显示豆子数、分数、生命、关卡等
void life_add(); //增加生命
void input_prop(); //载入道具
void prop_change(); //实现道具被吃效果
void show_pacman(int row, int line); //pac-man不动时的画面
void show_pacleft(int row,int line); //pac-man向左运动时的画面切换
void show_pacright(int row,int line); //pac-man向右运动时的画面切换
void show_pacup(int row,int line); //pac-man向上运动时的画面切换
void show_pacdown(int row,int line); //pac-man向下运动时的画面切换
void instauration_pac(); //恢复pac-man的位置
void show_game(); //pac-man不动时的显示
void show_left(); //pac-man向左运动时的显示
void show_right(); //pac-man向右运动时的显示
void show_up(); //pac-man向上运动时的显示
void show_down(); //pac-man向下运动时的显示
int game_over(); //游戏失败结束显示
int happy_over(); //游戏胜利结束显示
void update_data(int input); //游戏的数据更新
void update_option(int input3); //选项菜单的数据更新
int get_option(); //选项菜单的控制输入
void option(); //选项菜单的显示
void update_menu(int input2); //主菜单的数据更新
int get_menu(); //主菜单的控制输入
void mainmenu(); //主菜单显示
void game_exit(); //清除位图和数据文件
void environment_clearup(); //环境维护
struct save
{
int l;
int s;
int t;
};
int savedata()
{
struct save stu={save_life,save_score,save_level};
FILE *fp;
if((fp=fopen("sa.dat","wb"))==NULL )
{
printf("cannot open out file!\n");
return (0);
}
fwrite(&stu,sizeof(struct save),1,fp);
fclose(fp);
return (1);
}
void read_print()
{
struct save stu;
FILE *fp;
if((fp=fopen("sa.dat","rb"))==NULL)
{
printf("cannot open out file!\n");
exit(0);
}
while(!feof(fp))
{
fread(&stu,sizeof(struct save),1,fp);
{
save_life=stu.l;
save_score=stu.s;
save_level=stu.t;
}
}
fclose(fp);
}
void inc_time(void)
{
timer++; //在每一个时钟单位就自增一
}
END_OF_FUNCTION(inc_time);
void initialization_timer()
{
//为定时器锁住内存
LOCK_VARIABLE(timer);
LOCK_FUNCTION(inc_time);
install_int(inc_time, 1); //为定时器设定时钟单位为1毫秒
}
/*environment initialization for the game engine */
void environment_initialization()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -