huge c语言,C语言大项目 · GrandPaLee/C语言大项目 - Gitee.com
#include
#include
#include
#include
#include
#include
#include
#pragma comment(lib,"Winmm.lib")
#define HIGH 640
#define WIDTH 1180
IMAGE gamingbk, startbk; //背景图片
IMAGE player_mask, player; //初始鱼右图片
IMAGE mode_choose; //模式选择图片
IMAGE gameover; //游戏结束图片
IMAGE setsurface; //设置界面图片
IMAGE gamehelp; //游戏帮助
IMAGE gamingset; //游戏中设置
IMAGE gamecontinue; //选择继续游戏
IMAGE score_history; //历史分数图片
IMAGE conductor; //制作人图片
FILE* fp_single_survive, * fp_double_survive, * fp_double_versus, * fp_score_history; //文件指针
int i, j, k; //循环变量,j,k只用于赋值show
int score; //分数
int score_player1, score_player2; //双人pk分数
int shark_count; //鲨鱼数量
int rebirth; //重生玩家
char mark[5] = { NULL }; //分数字符串(打印用)
char vstime[100] = { NULL }; //时间字符串
char survive[100] = { NULL }; //时间字符串
char scoremax[100] = { NULL }; //历史分数字符串
int rollback_quitstartplay; //从开始游戏返回的标志
int rollback_gamerestart; //重新开始游戏标志
int rollback_quitset; //从设置退出标志
int rollback_quitgamingplay; //从游戏中退出
int png_flag; //背景图标志
int max_single_survive, max_double_survive, max_double_versus; //分数
enum gamemode { single_survive, double_survive, double_versus }; //单/双人生存/竞技模式选择
enum mainmenu { set, play, quit }; //初始界面选择:设置,开始游戏,退出
enum musicset { musicon, musicoff }; //音乐选项
enum sharkset { sharkoff, sharkon }; //鲨鱼选项
enum continuegame { newgame, continueold };//是否继续游戏
struct gamer { //玩家结构体
IMAGE png; //原图片
IMAGE mask; //遮盖图
int x; //横坐标
int y; //纵坐标
int length; //图片长
int broad; //图片宽
int show = 1; //是否存活(出现)
};
struct fish { //往左游的小鱼结构体
IMAGE png; //原图片
IMAGE mask; //遮盖图
int x; //横坐标
int y; //纵坐标
int show; //是否出现
int speed; //游的速度
int count = 0; //计数器
int length; //图片长
int broad; //图片宽
};
fish small_left[19]; //往左游的小鱼的数组
fish small_right[19]; //往右游的小鱼的数组
fish mid_left[19]; //往左游的中鱼的数组
fish mid_right[19]; //往右游的中鱼的数组
fish shark_left[19]; //往左游的鲨鱼的数组
fish shark_right[19]; //往右游的鲨鱼的数组
gamer player1; //玩家一
gamer player2; //玩家二
gamemode mode; //游戏前的选择
mainmenu choice; //初始界面选择
musicset musicturn; //音乐开关
sharkset sharkturn; //鲨鱼开关
continuegame continueturn; //继续游戏开关
clock_t start_player1, end_player1, start_player2, end_player2; //计时死亡时间
clock_t start_vs, end_vs; //vs计时
clock_t start_unbeat, end_unbeat; //无敌时间
void loadimg(IMAGE* png_left, IMAGE* mask_left, IMAGE* png_right, IMAGE* mask_right, char* name_left, char* name_right) { //加载图片函数
//往左游的鱼的路径字符串
char s1_png_left[100] = "D:\\GAME\\鱼\\"; //往左游的小鱼的原图的初始路径字符串
char s2_png_left[100] = ".png"; //原图片的后缀
char s1_mask_left[100] = "D:\\GAME\\鱼\\"; //往左游的小鱼的遮盖图的初始路径字符串
char s2_mask_left[100] = "_mask.png"; //遮盖图的后缀
strcat_s(s1_png_left, name_left); //拼接路径字符串为 D:\\GAME\\鱼\\()
strcat_s(s1_png_left, s2_png_left); //拼接路径字符串为 D:\\GAME\\鱼\\().png
strcat_s(s1_mask_left, name_left); //拼接路径字符串为 D:\\GAME\\鱼\\()
strcat_s(s1_mask_left, s2_mask_left); //拼接路径字符串为 D:\\GAME\\鱼\\()_mask.png
//往右游的鱼的路径字符串
char s1_png_right[100] = "D:\\GAME\\鱼\\"; //往左游的小鱼的原图的初始路径字符串
char s2_png_right[100] = ".png"; //原图片的后缀
char s1_mask_right[100] = "D:\\GAME\\鱼\\"; //往左游的小鱼的遮盖图的初始路径字符串
char s2_mask_right[100] = "_mask.png"; //遮盖图的后缀
strcat_s(s1_png_right, name_right); //拼接路径字符串为 D:\\GAME\\鱼\\()
strcat_s(s1_png_right, s2_png_right); //拼接路径字符串为 D:\\GAME\\鱼\\().png
strcat_s(s1_mask_right, name_right); //拼接路径字符串为 D:\\GAME\\鱼\\()
strcat_s(s1_mask_right, s2_mask_right); //拼接路径字符串为 D:\\GAME\\鱼\\()_mask.png
//加载图片
loadimage(png_left, _T(s1_png_left));
loadimage(png_right, _T(s1_png_right));
loadimage(mask_left, _T(s1_mask_left));
loadimage(mask_right, _T(s1_mask_right));
}
void load_all_picture() { //定义一个画面
//加载选择背景图片
loadimage(&startbk, _T("D:\\GAME\\bk0.png"));
//加载模式选择图片
loadimage(&mode_choose, _T("D:\\GAME\\gamemode.png"));
//加载制作人图片
loadimage(&conductor, _T("D:\\GAME\\制作人.png"));
//加载历史分数图片
loadimage(&score_history, _T("D:\\GAME\\历史分数.png"));
//加载游戏中暂停界面
loadimage(&gamingset, _T("D:\\GAME\\gamingset.png"));
//加载游戏结束图片
loadimage(&gameover, _T("D:\\GAME\\gameover.png"));
//记载选择继续游戏
loadimage(&gamecontinue, _T("D:\\GAME\\gamecontinue.png"));
//加载设置界面图片
loadimage(&setsurface, _T("D:\\GAME\\设置界面.jpg"));
//加载游戏背景图片
loadimage(&gamingbk, _T("D:\\GAME\\bk1.png"));
//加载游戏帮助图片
loadimage(&gamehelp, _T("D:\\GAME\\游戏帮助.png"));
//加载初始鱼右图片
loadimage(&player1.png, _T("D:\\GAME\\初始鱼左1.bmp"));
loadimage(&player1.mask, _T("D:\\GAME\\初始鱼左_mask.bmp"));
loadimage(&player2.png, _T("D:\\GAME\\初始鱼右2.bmp"));
loadimage(&player2.mask, _T("D:\\GAME\\初始鱼右_mask.bmp"));
//小鱼全体赋值图片
for (i = 0; i < 19; i++) {
char str_small_left[100] = "fish"; //往左游的小鱼名称字符串首
char str_small_right[100] = "fish"; //往右游的小鱼名称字符串首
char str_small_num[5]; //序号
char str_small_character_left[5] = "小左"; //往左游的小鱼名称字符串尾
char str_small_character_right[5] = "小右"; //往右游的小鱼名称字符串尾
_stprintf_s(str_small_num, _T("%d"), i); //序号转为字符串形式
strcat_s(str_small_left, str_small_num); //拼接为 fish()
strcat_s(str_small_left, str_small_character_left); //拼接为 fish()小左
strcat_s(str_small_right, str_small_num); //拼接为 fish()
strcat_s(str_small_right, str_small_character_right); //拼接为 fish()小右
loadimg(&small_left[i].png, &small_left[i].mask, &small_right[i].png, &small_right[i].mask, str_small_left, str_small_right);
}
//中鱼全体赋值图片
for (i = 0; i < 19; i++) {
char str_mid_left[100] = "fish";
char str_mid_right[100] = "fish";
char str_mid_num[5];
char str_mid_character_left[5] = "中左";
char str_mid_character_right[5] = "中右";
_stprintf_s(str_mid_num, _T("%d"), i);
strcat_s(str_mid_left, str_mid_num);
strcat_s(str_mid_left, str_mid_character_left);
strcat_s(str_mid_right, str_mid_num);
strcat_s(str_mid_right, str_mid_character_right);
loadimg(&mid_left[i].png, &mid_left[i].mask, &mid_right[i].png, &mid_right[i].mask, str_mid_left, str_mid_right);
}
//鲨鱼全体赋值
for (i = 0; i < 19; i++) {
loadimage(&shark_left[i].png, _T("D:\\GAME\\shark左.png"));
loadimage(&shark_left[i].mask, _T("D:\\GAME\\shark左_mask.png"));
loadimage(&shark_right[i].png, _T("D:\\GAME\\shark右.png"));
loadimage(&shark_right[i].mask, _T("D:\\GAME\\shark右_mask.png"));
}
//小鱼的图片大小赋值
small_left[0].length = small_right[0].length = 25, small_left[0].broad = small_right[0].broad = 14;
small_left[1].length = small_right[1].length = 25, small_left[1].broad = small_right[1].broad = 14;
small_left[2].length = small_right[2].length = 19, small_left[2].broad = small_right[2].broad = 17;
small_left[3].length = small_right[3].length = 24, small_left[3].broad = small_right[3].broad = 14;
small_left[4].length = small_right[4].length = 26, small_left[4].broad = small_right[4].broad = 13;
small_left[5].length = small_right[5].length = 34, small_left[5].broad = small_right[5].broad = 16;
small_left[6].length = small_right[6].length = 29, small_left[6].broad = small_right[6].broad = 24;
small_left[7].length = small_right[7].length = 31, small_left[7].broad = small_right[7].broad = 26;
small_left[8].length = small_right[8].length = 38, small_left[8].broad = small_right[8].broad = 18;
small_left[9].length = small_right[9].length = 33, small_left[9].broad = small_right[9].broad = 19;
small_left[10].length = small_right[10].length = 36, small_left[10].broad = small_right[10].broad = 17;
small_left[11].length = small_right[11].length = 46, small_left[11].broad = small_right[11].broad = 22;
small_left[12].length = small_right[12].length = 39, small_left[12].broad = small_right[12].broad = 25;
small_left[13].length = small_right[13].length = 37, small_left[13].broad = small_right[13].broad = 30;
small_left[14].length = small_right[14].length = 38, small_left[14].broad = small_right[14].broad = 26;
small_left[15].length = small_right[15].length = 34, small_left[15].broad = small_right[15].broad = 35;
small_left[16].length = small_right[16].length = 44, small_left[16].broad = small_right[16].broad = 30;
small_left[17].length = small_right[17].length = 46, small_left[17].broad = small_right[17].broad = 24;
small_left[18].length = small_right[18].length = 32, small_left[18].broad = small_right[18].broad = 19;
//中鱼图片大小赋值
mid_left[0].length = mid_right[0].length = 58, mid_left[0].broad = mid_right[0].broad = 32;
mid_left[1].length = mid_right[1].length = 57, mid_left[1].broad = mid_right[1].broad = 30;
mid_left[2].length = mid_right[2].length = 40, mid_left[2].broad = mid_right[2].broad = 36;
mid_left[3].length = mid_right[3].length = 47, mid_left[3].broad = mid_right[3].broad = 24;
mid_left[4].length = mid_right[4].length = 43, mid_left[4].broad = mid_right[4].broad = 26;
mid_left[5].length = mid_right[5].length = 69, mid_left[5].broad = mid_right[5].broad = 37;
mid_left[6].length = mid_right[6].length = 68, mid_left[6].broad = mid_right[6].broad = 47;
mid_left[7].length = mid_right[7].length = 69, mid_left[7].broad = mid_right[7].broad = 58;
mid_left[8].length = mid_right[8].length = 82, mid_left[8].broad = mid_right[8].broad = 37;
mid_left[9].length = mid_right[9].length = 64, mid_left[9].broad = mid_right[9].broad = 39;
mid_left[10].length = mid_right[10].length = 78, mid_left[10].broad = mid_right[10].broad = 35;
mid_left[11].length = mid_right[11].length = 94, mid_left[11].broad = mid_right[11].broad = 47;
mid_left[12].length = mid_right[12].length = 85, mid_left[12].broad = mid_right[12].broad = 54;
mid_left[13].length = mid_right[13].length = 83, mid_left[13].broad = mid_right[13].broad = 68;
mid_left[14].length = mid_right[14].length = 89, mid_left[14].broad = mid_right[14].broad = 55;
mid_left[15].length = mid_right[15].length = 69, mid_left[15].broad = mid_right[15].broad = 73;
mid_left[16].length = mid_right[16].length = 94, mid_left[16].broad = mid_right[16].broad = 66;
mid_left[17].length = mid_right[17].length = 94, mid_left[17].broad = mid_right[17].broad = 48;
mid_left[18].length = mid_right[18].length = 70, mid_left[18].broad = mid_right[18].broad = 44;
//鲨鱼图片大小赋值
for (i = 0; i < 19; i++) {
shark_left[i].broad = shark_right[i].broad = 64;
shark_left[i].length = shark_right[i].length = 120;
}
//玩家图片大小赋值
player1.length = player2.length = 94;
player1.broad = player2.broad = 57;
}
void start_surface() { //游戏开始界面
mciSendString("close bkmusic", NULL, 0, NULL);
putimage(0, 0, &startbk); //显示选择背景图片
MOUSEMSG m; // 定义鼠标消息
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) { //按下鼠标左键
if (m.x >= 475 && m.x <= 705) {
//点击到开始游戏
if (m.y >= 282 && m.y <= 352) {
modechoose_surface:putimage(0, 0, &mode_choose);
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
if (m.y >= 284 && m.y <= 352) {
if (m.x >= 86 && m.x <= 312) { mode = single_survive; break; }
if (m.x >= 473 && m.x <= 701) { mode = double_survive; break; }
if (m.x >= 857 && m.x <= 1089) { mode = double_versus; break; }
}
if (m.x >= 861 && m.x <= 1089 && m.y >= 473 && m.y <= 540) { rollback_quitstartplay = 1; break; }
}
}
choice = play;
//加载是否继续游戏界面
if (rollback_quitstartplay != 1) {
putimage(0, 0, &gamecontinue);
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN && m.x >= 469 && m.x <= 705) {
//选择了继续游戏
if (m.y >= 229 && m.y <= 303) {
continueturn = continueold;
break;
}
//选择了新游戏
if (m.y >= 372 && m.y <= 446) {
continueturn = newgame;
break;
}
//选择返回
if (m.y >= 514 && m.y <= 585) {
goto modechoose_surface;
}
}
}
}
goto end;
}
//点击到退出游戏图标变暗
if (m.y >= 566 && m.y <= 634) {
choice = quit;
goto end;
}
//点击到设置
if (m.y >= 424 && m.y <= 492) {
choice = set;
goto end;
}
}
}
}
end:; //点击后,跳出循环
}
void initialize() { //数据初始化
score = 0;
score_player1 = score_player2 = 0;
player1.show = player2.show = 1;
i = j = k = 0;
shark_count = 0;
rollback_gamerestart = 0;
rollback_quitset = 0;
png_flag = 1;
start_vs = end_vs = 0;
start_unbeat = end_unbeat = 0;
rebirth = 0;
srand((unsigned)time(NULL));
for (i = 0; i < 19; i++) { //速度初始化
small_left[i].speed = 1 + (rand() % 8) / 2;
small_right[i].speed = 1 + rand() % 4;
mid_left[i].speed = 1 + (rand() % 2) * 2;
mid_right[i].speed = 1 + (rand() % 1) * 4;
shark_left[i].speed = shark_right[i].speed = 1;
}
for (i = 0; i < 19; i++) { //坐标赋值
small_left[i].y = 25 + rand() % (HIGH / 10) * 9, small_left[i].x = WIDTH;
small_right[i].y = 25 + rand() % (HIGH / 10) * 9, small_right[i].x = -50;
mid_left[i].y = 25 + rand() % (HIGH / 10) * 9, mid_left[i].x = WIDTH;
mid_right[i].y = 25 + rand() % (HIGH / 10) * 9, mid_right[i].x = -100;
shark_left[i].y = (rand() % 10) * 64, shark_left[i].x = WIDTH;
shark_right[i].y = (rand() % 10) * 64, shark_right[i].x = -100;
}
back:for (i = 0; i < 19; i++) { //是否出现赋值0,1
small_left[i].show = rand() % 9;
small_right[i].show = rand() % 9;
mid_left[i].show = rand() % 9;
mid_right[i].show = rand() % 9;
shark_left[i].show = shark_right[i].show = 0;
player1.show = player2.show = 1;
if (small_left[i].show == 1)j++;
if (small_right[i].show == 1)j++;
if (mid_left[i].show == 1)k++;
if (mid_right[i].show == 1)k++;
}
if (j + k <= 20 || k < 8 || k > 13) { //控制鱼的数量
j = k = 0;
goto back;
}
player1.x = WIDTH / 3, player1.y = HIGH / 2;
player2.x = 2 * WIDTH / 3, player2.y = HIGH / 2;
}
void read_file() {
if (mode == single_survive)fopen_s(&fp_single_survive, "D:\\GAME\\单人生存.txt", "r+");
if (mode == double_survive)fopen_s(&fp_double_survive, "D:\\GAME\\双人生存.txt", "r+");
if (mode == double_versus)fopen_s(&fp_double_versus, "D:\\GAME\\双人竞技.txt", "r+");
if (mode == single_survive && fp_single_survive != NULL) {
fscanf_s(fp_single_survive, "%d %d %d %d %d ", &score, &player1.x, &player1.y, &player1.show, &player2.show);
for (i = 0; i < 19; i++) {
//读档速度
fscanf_s(fp_single_survive, "%d %d %d %d %d %d ", &small_left[i].speed, &small_right[i].speed, &mid_left[i].speed, &mid_right[i].speed, &shark_left[i].speed, &shark_right[i].speed);
//读档坐标
fscanf_s(fp_single_survive, "%d %d %d %d %d %d ", &small_left[i].x, &small_right[i].x, &mid_left[i].x, &mid_right[i].x, &shark_left[i].x, &shark_right[i].x);
fscanf_s(fp_single_survive, "%d %d %d %d %d %d ", &small_left[i].y, &small_right[i].y, &mid_left[i].y, &mid_right[i].y, &shark_left[i].y, &shark_right[i].y);
//读档是否出现
fscanf_s(fp_single_survive, "%d %d %d %d %d %d ", &small_left[i].show, &small_right[i].show, &mid_left[i].show, &mid_right[i].show, &shark_left[i].show, &shark_right[i].show);
}
fclose(fp_single_survive);
}
if (mode == double_survive && fp_double_survive != NULL) {
fscanf_s(fp_double_survive, "%d %d %d %d %d ", &score, &player1.x, &player1.y, &player2.x, &player2.y);
for (i = 0; i < 19; i++) {
//读档速度
fscanf_s(fp_double_survive, "%d %d %d %d %d %d ", &small_left[i].speed, &small_right[i].speed, &mid_left[i].speed, &mid_right[i].speed, &shark_left[i].speed, &shark_right[i].speed);
//读档坐标
fscanf_s(fp_double_survive, "%d %d %d %d %d %d ", &small_left[i].x, &small_right[i].x, &mid_left[i].x, &mid_right[i].x, &shark_left[i].x, &shark_right[i].x);
fscanf_s(fp_double_survive, "%d %d %d %d %d %d ", &small_left[i].y, &small_right[i].y, &mid_left[i].y, &mid_right[i].y, &shark_left[i].y, &shark_right[i].y);
//读档是否出现
fscanf_s(fp_double_survive, "%d %d %d %d %d %d ", &small_left[i].show, &small_right[i].show, &mid_left[i].show, &mid_right[i].show, &shark_left[i].show, &shark_right[i].show);
}
fclose(fp_double_survive);
}
if (mode == double_versus && fp_double_versus != NULL) {
fscanf_s(fp_double_versus, "%d %d %d %d %d %d ", &score_player1, &score_player2, &player1.x, &player1.y, &player2.x, &player2.y);
for (i = 0; i < 19; i++) {
//读档速度
fscanf_s(fp_double_versus, "%d %d %d %d %d %d ", &small_left[i].speed, &small_right[i].speed, &mid_left[i].speed, &mid_right[i].speed, &shark_left[i].speed, &shark_right[i].speed);
//读档坐标
fscanf_s(fp_double_versus, "%d %d %d %d %d %d ", &small_left[i].x, &small_right[i].x, &mid_left[i].x, &mid_right[i].x, &shark_left[i].x, &shark_right[i].x);
fscanf_s(fp_double_versus, "%d %d %d %d %d %d ", &small_left[i].y, &small_right[i].y, &mid_left[i].y, &mid_right[i].y, &shark_left[i].y, &shark_right[i].y);
//读档是否出现
fscanf_s(fp_double_versus, "%d %d %d %d %d %d ", &small_left[i].show, &small_right[i].show, &mid_left[i].show, &mid_right[i].show, &shark_left[i].show, &shark_right[i].show);
//读档时间
fscanf_s(fp_double_versus, "%ld %ld ", &start_vs, &end_vs);
}
fclose(fp_double_versus);
}
}
void shark_emerge() { //判断鲨鱼出现
int shark_num;
if (mode != double_versus) {
shark_num = score / 50;
for (i = 0; i < shark_num; i++) {
if (shark_num % 2 == 0 && shark_left[i].show != 1)shark_left[i].show = 1;
else if (shark_num % 2 != 0 && shark_right[i].show != 1)shark_right[i].show = 1;
}
}
else {
shark_num = (score_player1 + score_player2) / 50;
for (i = 0; i < shark_num; i++) {
if (shark_num % 2 == 0 && shark_left[i].show != 1)shark_left[i].show = 1;
else if (shark_num % 2 != 0 && shark_right[i].show != 1)shark_right[i].show = 1;
}
}
}
void single_gaming_survive_surface() { //单人游戏游戏
shark_emerge();
BeginBatchDraw();
putimage(0, 0, &gamingbk);
setbkmode(TRANSPARENT);
settextcolor(RGB(255, 252, 153));
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(5 * WIDTH / 6, HIGH / 100, "SCORE:");
_stprintf_s(mark, _T("%d"), score);
outtextxy(9 * WIDTH / 10, HIGH / 100, mark);
//显示玩家
if (player1.show == 1) {
putimage(player1.x, player1.y, &player1.mask, SRCAND);
putimage(player1.x, player1.y, &player1.png, SRCINVERT);
}
//显示鱼
for (i = 0; i < 19; i++) {
if (small_left[i].show == 1) {
putimage(small_left[i].x, small_left[i].y, &small_left[i].mask, SRCAND);
putimage(small_left[i].x, small_left[i].y, &small_left[i].png, SRCINVERT);
}
if (small_right[i].show == 1) {
putimage(small_right[i].x, small_right[i].y, &small_right[i].mask, SRCAND);
putimage(small_right[i].x, small_right[i].y, &small_right[i].png, SRCINVERT);
}
if (mid_left[i].show == 1) {
putimage(mid_left[i].x, mid_left[i].y, &mid_left[i].mask, SRCAND);
putimage(mid_left[i].x, mid_left[i].y, &mid_left[i].png, SRCINVERT);
}
if (mid_right[i].show == 1) {
putimage(mid_right[i].x, mid_right[i].y, &mid_right[i].mask, SRCAND);
putimage(mid_right[i].x, mid_right[i].y, &mid_right[i].png, SRCINVERT);
}
if (shark_left[i].show == 1) {
putimage(shark_left[i].x, shark_left[i].y, &shark_left[i].mask, SRCAND);
putimage(shark_left[i].x, shark_left[i].y, &shark_left[i].png, SRCINVERT);
}
if (shark_right[i].show == 1) {
putimage(shark_right[i].x, shark_right[i].y, &shark_right[i].mask, SRCAND);
putimage(shark_right[i].x, shark_right[i].y, &shark_right[i].png, SRCINVERT);
}
}
FlushBatchDraw();
}
void single_auto_update() { //单人生存自动更新
//随机数播种
srand((unsigned)time(NULL));
int m;
//鱼按照一定速度游
for (i = 0; i < 19; i++) {
//计数器count累加到大于speed时,鱼移动,否则不然
//.show==1是为了只让出现在界面里的鱼游
if (small_left[i].count >= small_left[i].speed && small_left[i].show == 1) {
small_left[i].x--;
small_left[i].count = 0;
}
else if (small_left[i].count < small_left[i].speed && small_left[i].show == 1)small_left[i].count++;
if (small_right[i].count >= small_right[i].speed && small_right[i].show == 1) {
small_right[i].x++;
small_right[i].count = 0;
}
else if (small_right[i].count != small_right[i].speed && small_right[i].show == 1)small_right[i].count++;
if (mid_left[i].count >= mid_left[i].speed && mid_left[i].show == 1) {
mid_left[i].x--;
mid_left[i].count = 0;
}
else if (mid_left[i].count < mid_left[i].speed && mid_left[i].show == 1)mid_left[i].count++;
if (mid_right[i].count >= mid_right[i].speed && mid_right[i].show == 1) {
mid_right[i].x++;
mid_right[i].count = 0;
}
else if (mid_right[i].count < mid_right[i].speed && mid_right[i].show == 1)mid_right[i].count++;
//鲨鱼速度最大,不需要计数器
if (shark_left[i].show == 1)shark_left[i].x--;
if (shark_right[i].show == 1)shark_right[i].x++;
}
//判断是否出界
for (i = 0; i < 19; i++) {
/*出界后复原横坐标,重新随机纵坐标*/
if (small_left[i].x <= -50 && small_left[i].show == 1)small_left[i].x = WIDTH, small_left[i].y = 25 + rand() % (HIGH / 10) * 9, small_left[i].speed = 1 + (rand() % 16) / 2;
if (small_right[i].x >= WIDTH && small_right[i].show == 1)small_right[i].x = -50, small_right[i].y = 25 + rand() % (HIGH / 10) * 9, small_right[i].speed = 1 + rand() % 8;
if (mid_left[i].x <= -100 && mid_left[i].show == 1)mid_left[i].x = WIDTH, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9, mid_left[i].speed = 1 + (rand() % 4) * 2;
if (mid_right[i].x >= WIDTH && mid_right[i].show == 1)mid_right[i].x = -100, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9, mid_right[i].speed = 1 + (rand() % 2) * 4;
if (shark_left[i].x <= -200 && shark_left[i].show == 1)shark_left[i].x = WIDTH, shark_left[i].y = (rand() % 10) * 64;
if (shark_right[i].x >= WIDTH && shark_right[i].show == 1)shark_right[i].x = -200, shark_right[i].y = (rand() % 10) * 64;
}
/*判断小鱼是否被吃*/
for (i = 0; i < 19; i++) {
if ((small_left[i].x >= player1.x && small_left[i].x <= player1.x + 94 && small_left[i].y >= player1.y && small_left[i].y <= player1.y + 57) ||
(small_left[i].x + small_left[i].length >= player1.x && small_left[i].x + small_left[i].length <= player1.x + 94 && small_left[i].y >= player1.y && small_left[i].y <= player1.y + 57) ||
(small_left[i].x >= player1.x && small_left[i].x <= player1.x + 94 && small_left[i].y + small_left[i].broad >= player1.y && small_left[i].y + small_left[i].broad <= player1.y + 94) ||
(small_left[i].x + small_left[i].length >= player1.x && small_left[i].x + small_left[i].length <= player1.x + 94 && small_left[i].y + small_left[i].broad >= player1.y && small_left[i].y + small_left[i].broad <= player1.y + 94) ||
(small_left[i].x + small_left[i].length / 2 >= player1.x && small_left[i].x + small_left[i].length / 2 <= player1.x + 94 && small_left[i].y + small_left[i].broad / 2 >= player1.y && small_left[i].y + small_left[i].broad / 2 <= player1.y + 57)) {
small_left[i].x = WIDTH + 50, small_left[i].y = 25 + rand() % (HIGH / 10) * 9;//被吃后更新纵坐标,复原横坐标
small_left[i].show = 0;//被吃后更新一条新的鱼图片
m = rand() % 19;//被吃后更新一条新的鱼图片
while (small_left[m].show == 1)m = rand() % 19;//被吃后更新一条新的鱼图片
small_left[m].show = 1;//被吃后更新一条新的鱼图片
score += small_left[i].length * small_left[i].broad / 500;//分数与鱼的大小有关系
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((small_right[i].x >= player1.x && small_right[i].x <= player1.x + 94 && small_right[i].y >= player1.y && small_right[i].y <= player1.y + 57) ||
(small_right[i].x + small_right[i].length >= player1.x && small_right[i].x + small_right[i].length <= player1.x + 94 && small_right[i].y >= player1.y && small_right[i].y <= player1.y + 57) ||
(small_right[i].x >= player1.x && small_right[i].x <= player1.x + 94 && small_right[i].y + small_right[i].broad >= player1.y && small_right[i].y + small_right[i].broad <= player1.y + 94) ||
(small_right[i].x + small_right[i].length >= player1.x && small_right[i].x + small_right[i].length <= player1.x + 94 && small_right[i].y + small_right[i].broad >= player1.y && small_right[i].y + small_right[i].broad <= player1.y + 94) ||
(small_right[i].x + small_right[i].length / 2 >= player1.x && small_right[i].x + small_right[i].length / 2 <= player1.x + 94 && small_right[i].y + small_right[i].broad / 2 >= player1.y && small_right[i].y + small_right[i].broad / 2 <= player1.y + 57)) {
small_right[i].x = -70, small_right[i].y = 25 + rand() % (HIGH / 10) * 9;
small_right[i].show = 0;
m = rand() % 19;
while (small_right[m].show == 1)m = rand() % 19;
small_right[m].show = 1;
score += small_right[i].length * small_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
/*判断中鱼是否被吃*/
for (i = 0; i < 19; i++) {
if ((mid_left[i].x >= player1.x && mid_left[i].x <= player1.x + 94 && mid_left[i].y >= player1.y && mid_left[i].y <= player1.y + 57) ||
(mid_left[i].x + mid_left[i].length >= player1.x && mid_left[i].x + mid_left[i].length <= player1.x + 94 && mid_left[i].y >= player1.y && mid_left[i].y <= player1.y + 57) ||
(mid_left[i].x >= player1.x && mid_left[i].x <= player1.x + 94 && mid_left[i].y + mid_left[i].broad >= player1.y && mid_left[i].y + mid_left[i].broad <= player1.y + 94) ||
(mid_left[i].x + mid_left[i].length >= player1.x && mid_left[i].x + mid_left[i].length <= player1.x + 94 && mid_left[i].y + mid_left[i].broad >= player1.y && mid_left[i].y + mid_left[i].broad <= player1.y + 94) ||
(mid_left[i].x + mid_left[i].length / 2 >= player1.x && mid_left[i].x + mid_left[i].length / 2 <= player1.x + 94 && mid_left[i].y + mid_left[i].broad / 2 >= player1.y && mid_left[i].y + mid_left[i].broad / 2 <= player1.y + 57)) {
mid_left[i].x = WIDTH + 100, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_left[i].show = 0;
m = rand() % 19;
while (mid_left[m].show == 1)m = rand() % 19;
mid_left[m].show = 1;
score += mid_left[i].length * mid_left[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((mid_right[i].x >= player1.x && mid_right[i].x <= player1.x + 94 && mid_right[i].y >= player1.y && mid_right[i].y <= player1.y + 57) ||
(mid_right[i].x + mid_right[i].length >= player1.x && mid_right[i].x + mid_right[i].length <= player1.x + 94 && mid_right[i].y >= player1.y && mid_right[i].y <= player1.y + 57) ||
(mid_right[i].x >= player1.x && mid_right[i].x <= player1.x + 94 && mid_right[i].y + mid_right[i].broad >= player1.y && mid_right[i].y + mid_right[i].broad <= player1.y + 94) ||
(mid_right[i].x + mid_right[i].length >= player1.x && mid_right[i].x + mid_right[i].length <= player1.x + 94 && mid_right[i].y + mid_right[i].broad >= player1.y && mid_right[i].y + mid_right[i].broad <= player1.y + 94) ||
(mid_right[i].x + mid_right[i].length / 2 >= player1.x && mid_right[i].x + mid_right[i].length / 2 <= player1.x + 94 && mid_right[i].y + mid_right[i].broad / 2 >= player1.y && mid_right[i].y + mid_right[i].broad / 2 <= player1.y + 57)) {
mid_right[i].x = -150, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_right[i].show = 0;
m = rand() % 19;
while (mid_right[m].show == 1)m = rand() % 19;
mid_right[m].show = 1;
score += mid_right[i].length * mid_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
//判断玩家是否被吃
for (i = 0; i < 19; i++) {
//使用了多个点进行判断
if (shark_left[i].show == 1) //只有出现的鲨鱼才能吃玩家(左游)
if ((player1.x + 32 >= shark_left[i].x && player1.x + 32 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 33 >= shark_left[i].x && player1.x + 33 <= shark_left[i].x + shark_left[i].length && player1.y + 22 >= shark_left[i].y + 19 && player1.y + 22 <= shark_left[i].y + 49) ||
(player1.x + 20 >= shark_left[i].x && player1.x + 20 <= shark_left[i].x + shark_left[i].length && player1.y + 30 >= shark_left[i].y + 19 && player1.y + 30 <= shark_left[i].y + 49) ||
(player1.x + 32 >= shark_left[i].x && player1.x + 32 <= shark_left[i].x + shark_left[i].length && player1.y + 36 >= shark_left[i].y + 19 && player1.y + 36 <= shark_left[i].y + 49) ||
(player1.x + 43 >= shark_left[i].x && player1.x + 43 <= shark_left[i].x + shark_left[i].length && player1.y + 46 >= shark_left[i].y + 19 && player1.y + 46 <= shark_left[i].y + 49) ||
(player1.x + 53 >= shark_left[i].x && player1.x + 53 <= shark_left[i].x + shark_left[i].length && player1.y + 48 >= shark_left[i].y + 19 && player1.y + 48 <= shark_left[i].y + 49) ||
(player1.x + 77 >= shark_left[i].x && player1.x + 77 <= shark_left[i].x + shark_left[i].length && player1.y + 29 >= shark_left[i].y + 19 && player1.y + 29 <= shark_left[i].y + 49) ||
(player1.x + 54 >= shark_left[i].x && player1.x + 54 <= shark_left[i].x + shark_left[i].length && player1.y + 14 >= shark_left[i].y + 19 && player1.y + 14 <= shark_left[i].y + 49) ||
(player1.x + 67 >= shark_left[i].x && player1.x + 67 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 31 >= shark_left[i].x && player1.x + 31 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 17 >= shark_left[i].x && player1.x + 17 <= shark_left[i].x + shark_left[i].length && player1.y + 29 >= shark_left[i].y + 19 && player1.y + 29 <= shark_left[i].y + 49) ||
(player1.x + 39 >= shark_left[i].x && player1.x + 39 <= shark_left[i].x + shark_left[i].length && player1.y + 47 >= shark_left[i].y + 19 && player1.y + 47 <= shark_left[i].y + 49)) {
//删除存档
fopen_s(&fp_single_survive, "D:\\GAME\\单人生存.txt", "w+");
fclose(fp_single_survive);
//判断是否最高分
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
if (max_single_survive < score) {
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "w+");
fprintf(fp_score_history, "%d %d %d", score, max_double_survive, max_double_versus);
fclose(fp_score_history);
}
//关闭背景音乐
if (musicturn == musicon) {
mciSendString("close bkmusic", NULL, 0, NULL);
//播放音乐
mciSendString("close overmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\gameover.mp3 alias overmusic", NULL, 0, NULL);
mciSendString("play overmusic", NULL, 0, NULL);
}
putimage(0, 0, &gameover);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(WIDTH / 4, HIGH / 4, "你的得分是:");
outtextxy(2 * WIDTH / 3, HIGH / 4, mark);
f.lfHeight = 24; // 设置字体高度
settextcolor(WHITE);
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, 4 * HIGH / 5, "左键任意区域以重玩......");
outtextxy(2 * WIDTH / 5, 6 * HIGH / 7, "右键任意区域以退出......");
EndBatchDraw();
MOUSEMSG m;
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
rollback_gamerestart = 1;
break;
}
if (m.uMsg == WM_RBUTTONDOWN)exit(0);
}
}
if (shark_right[i].show == 1) //只有出现的鲨鱼才能吃玩家(右游)
if ((player1.x + 32 >= shark_right[i].x && player1.x + 32 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 33 >= shark_right[i].x && player1.x + 33 <= shark_right[i].x + shark_right[i].length && player1.y + 22 >= shark_right[i].y + 19 && player1.y + 22 <= shark_right[i].y + 49) ||
(player1.x + 20 >= shark_right[i].x && player1.x + 20 <= shark_right[i].x + shark_right[i].length && player1.y + 30 >= shark_right[i].y + 19 && player1.y + 30 <= shark_right[i].y + 49) ||
(player1.x + 32 >= shark_right[i].x && player1.x + 32 <= shark_right[i].x + shark_right[i].length && player1.y + 36 >= shark_right[i].y + 19 && player1.y + 36 <= shark_right[i].y + 49) ||
(player1.x + 43 >= shark_right[i].x && player1.x + 43 <= shark_right[i].x + shark_right[i].length && player1.y + 46 >= shark_right[i].y + 19 && player1.y + 46 <= shark_right[i].y + 49) ||
(player1.x + 53 >= shark_right[i].x && player1.x + 53 <= shark_right[i].x + shark_right[i].length && player1.y + 48 >= shark_right[i].y + 19 && player1.y + 48 <= shark_right[i].y + 49) ||
(player1.x + 77 >= shark_right[i].x && player1.x + 77 <= shark_right[i].x + shark_right[i].length && player1.y + 29 >= shark_right[i].y + 19 && player1.y + 29 <= shark_right[i].y + 49) ||
(player1.x + 54 >= shark_right[i].x && player1.x + 54 <= shark_right[i].x + shark_right[i].length && player1.y + 14 >= shark_right[i].y + 19 && player1.y + 14 <= shark_right[i].y + 49) ||
(player1.x + 67 >= shark_right[i].x && player1.x + 67 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 31 >= shark_right[i].x && player1.x + 31 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 17 >= shark_right[i].x && player1.x + 17 <= shark_right[i].x + shark_right[i].length && player1.y + 29 >= shark_right[i].y + 19 && player1.y + 29 <= shark_right[i].y + 49) ||
(player1.x + 39 >= shark_right[i].x && player1.x + 39 <= shark_right[i].x + shark_right[i].length && player1.y + 47 >= shark_right[i].y + 19 && player1.y + 47 <= shark_right[i].y + 49)) {
//删除存档
fopen_s(&fp_single_survive, "D:\\GAME\\单人生存.txt", "w+");
fclose(fp_single_survive);
//判断是否最高分
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
if (max_single_survive < score) {
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "w+");
fprintf(fp_score_history, "%d %d %d", score, max_double_survive, max_double_versus);
fclose(fp_score_history);
}
//关闭背景音乐
if (musicturn == musicon) {
mciSendString("close bkmusic", NULL, 0, NULL);
//播放音乐
mciSendString("close overmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\gameover.mp3 alias overmusic", NULL, 0, NULL);
mciSendString("play overmusic", NULL, 0, NULL);
}
putimage(0, 0, &gameover);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(WIDTH / 4, HIGH / 4, "你的得分是:");
outtextxy(2 * WIDTH / 3, HIGH / 4, mark);
f.lfHeight = 24; // 设置字体高度
settextcolor(WHITE);
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, 4 * HIGH / 5, "左键任意区域以重玩......");
outtextxy(2 * WIDTH / 5, 6 * HIGH / 7, "右键任意区域以退出......");
EndBatchDraw();
MOUSEMSG m;
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
rollback_gamerestart = 1;
break;
}
if (m.uMsg == WM_RBUTTONDOWN)exit(0);
}
}
}
}
void single_input_update_key() { //键盘输入更新
if ((GetAsyncKeyState(0x41) & 0x8000)) {
loadimage(&player1.png, _T("D:\\GAME\\初始鱼左1.bmp"));
loadimage(&player1.mask, _T("D:\\GAME\\初始鱼左_mask.bmp"));
if (player1.x > -10)player1.x--;
}
if ((GetAsyncKeyState(0x44) & 0x8000)) {
loadimage(&player1.png, _T("D:\\GAME\\初始鱼右1.bmp"));
loadimage(&player1.mask, _T("D:\\GAME\\初始鱼右_mask.bmp"));
if (player1.x < WIDTH - player1.length + 10)player1.x++;
}
if ((GetAsyncKeyState(0x57) & 0x8000))if (player1.y > -5)player1.y--;
if ((GetAsyncKeyState(0x53) & 0x8000))if (player1.y < HIGH - player1.broad + 5)player1.y++;
if ((GetAsyncKeyState(0x1B) & 0x8000)) {
putimage(0, 0, &gamingset);
EndBatchDraw();
MOUSEMSG n, m;
while (1) {
n = GetMouseMsg();
if (n.uMsg == WM_LBUTTONDOWN && n.x >= 470 && n.x <= 706) {
//点击设置
if (n.y >= 364 && n.y <= 432) {
putimage(0, 0, &setsurface);
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) { //按下鼠标左键
//开启音乐
if (m.x >= 30 && m.x <= 180 && m.y >= 21 && m.y <= 193) {
musicturn = musicon;
mciSendString("open D:\\GAME\\bkmusic.mp3 alias bkmusic", NULL, 0, NULL);
mciSendString("play bkmusic repeat", NULL, 0, NULL);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "音乐已开启!");
}
//关闭音乐
if (m.x >= 330 && m.x <= 480 && m.y >= 24 && m.y <= 193) {
musicturn = musicoff;
mciSendString("close bkmusic", NULL, 0, NULL);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "音乐已关闭!");
}
//显示游戏说明
if (m.x >= 35 && m.x <= 181 && m.y >= 319 && m.y <= 494) {
putimage(0, 0, &gamehelp);
while (1) {
m = GetMouseMsg();
if (m.x >= 1114 && m.x <= 1166 && m.y >= 10 && m.y <= 62 && m.uMsg == WM_LBUTTONDOWN) {
break;
}
}
putimage(0, 0, &setsurface);
}
//开启鲨鱼
if (m.x >= 637 && m.x <= 786 && m.y >= 20 && m.y <= 193) {
sharkturn = sharkon;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "鲨鱼已开启!");
}
//关闭鲨鱼
if (m.x >= 932 && m.x <= 1080 && m.y >= 26 && m.y <= 196) {
sharkturn = sharkoff;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "鲨鱼已关闭!");
}
//返回
if (m.x >= 923 && m.x <= 1153 && m.y >= 549 && m.y <= 618) {
putimage(0, 0, &gamingset);
break;
}
}
}
}
//点击返回
if (n.y >= 217 && n.y <= 287)break;
//点击存档返回
if (n.y >= 507 && n.y <= 578) {
fopen_s(&fp_single_survive, "D:\\GAME\\单人生存.txt", "r+");
if (fp_single_survive == NULL)exit(-1);
fprintf(fp_single_survive, "%d %d %d %d %d ", score, player1.x, player1.y, player1.show, player2.show);
for (i = 0; i < 19; i++) {
// 储存速度
fprintf(fp_single_survive, "%d %d %d %d %d %d ", small_left[i].speed, small_right[i].speed, mid_left[i].speed, mid_right[i].speed, shark_left[i].speed, shark_right[i].speed);
//储存坐标
fprintf(fp_single_survive, "%d %d %d %d %d %d ", small_left[i].x, small_right[i].x, mid_left[i].x, mid_right[i].x, shark_left[i].x, shark_right[i].x);
fprintf(fp_single_survive, "%d %d %d %d %d %d ", small_left[i].y, small_right[i].y, mid_left[i].y, mid_right[i].y, shark_left[i].y, shark_right[i].y);
//储存是否出现
fprintf(fp_single_survive, "%d %d %d %d %d %d ", small_left[i].show, small_right[i].show, mid_left[i].show, mid_right[i].show, shark_left[i].show, shark_right[i].show);
}
fclose(fp_single_survive);
rollback_quitgamingplay = 1;
break;
}
}
}
}
}
void double_gaming_survive_surface() {
shark_emerge();
BeginBatchDraw();
putimage(0, 0, &gamingbk);
setbkmode(TRANSPARENT);
settextcolor(RGB(255, 252, 153));
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(5 * WIDTH / 6, HIGH / 100, "SCORE:");
_stprintf_s(mark, _T("%d"), score);
outtextxy(9 * WIDTH / 10, HIGH / 100, mark);
//显示玩家
if (player1.show == 1) {
putimage(player1.x, player1.y, &player1.mask, SRCAND);
putimage(player1.x, player1.y, &player1.png, SRCINVERT);
}
if (player2.show == 1) {
putimage(player2.x, player2.y, &player2.mask, SRCAND);
putimage(player2.x, player2.y, &player2.png, SRCINVERT);
}
//显示鱼
for (i = 0; i < 19; i++) {
if (small_left[i].show == 1) {
putimage(small_left[i].x, small_left[i].y, &small_left[i].mask, SRCAND);
putimage(small_left[i].x, small_left[i].y, &small_left[i].png, SRCINVERT);
}
if (small_right[i].show == 1) {
putimage(small_right[i].x, small_right[i].y, &small_right[i].mask, SRCAND);
putimage(small_right[i].x, small_right[i].y, &small_right[i].png, SRCINVERT);
}
if (mid_left[i].show == 1) {
putimage(mid_left[i].x, mid_left[i].y, &mid_left[i].mask, SRCAND);
putimage(mid_left[i].x, mid_left[i].y, &mid_left[i].png, SRCINVERT);
}
if (mid_right[i].show == 1) {
putimage(mid_right[i].x, mid_right[i].y, &mid_right[i].mask, SRCAND);
putimage(mid_right[i].x, mid_right[i].y, &mid_right[i].png, SRCINVERT);
}
if (shark_left[i].show == 1) {
putimage(shark_left[i].x, shark_left[i].y, &shark_left[i].mask, SRCAND);
putimage(shark_left[i].x, shark_left[i].y, &shark_left[i].png, SRCINVERT);
}
if (shark_right[i].show == 1) {
putimage(shark_right[i].x, shark_right[i].y, &shark_right[i].mask, SRCAND);
putimage(shark_right[i].x, shark_right[i].y, &shark_right[i].png, SRCINVERT);
}
}
}
void double_survive_auto_update() {
srand((unsigned)time(NULL));
int m;
//鱼按照一定速度游
for (i = 0; i < 19; i++) {
//计数器count累加到大于speed时,鱼移动,否则不然
//.show==1是为了只让出现在界面里的鱼游
if (small_left[i].count >= small_left[i].speed && small_left[i].show == 1) {
small_left[i].x--;
small_left[i].count = 0;
}
else if (small_left[i].count < small_left[i].speed && small_left[i].show == 1)small_left[i].count++;
if (small_right[i].count >= small_right[i].speed && small_right[i].show == 1) {
small_right[i].x++;
small_right[i].count = 0;
}
else if (small_right[i].count != small_right[i].speed && small_right[i].show == 1)small_right[i].count++;
if (mid_left[i].count >= mid_left[i].speed && mid_left[i].show == 1) {
mid_left[i].x--;
mid_left[i].count = 0;
}
else if (mid_left[i].count < mid_left[i].speed && mid_left[i].show == 1)mid_left[i].count++;
if (mid_right[i].count >= mid_right[i].speed && mid_right[i].show == 1) {
mid_right[i].x++;
mid_right[i].count = 0;
}
else if (mid_right[i].count < mid_right[i].speed && mid_right[i].show == 1)mid_right[i].count++;
//鲨鱼速度最大,不需要计数器
if (shark_left[i].show == 1)shark_left[i].x--;
if (shark_right[i].show == 1)shark_right[i].x++;
}
//判断是否出界
for (i = 0; i < 19; i++) {
/*出界后复原横坐标,重新随机纵坐标*/
if (small_left[i].x <= -50 && small_left[i].show == 1)small_left[i].x = WIDTH, small_left[i].y = 25 + rand() % (HIGH / 10) * 9, small_left[i].speed = 1 + (rand() % 16) / 2;
if (small_right[i].x >= WIDTH && small_right[i].show == 1)small_right[i].x = -50, small_right[i].y = 25 + rand() % (HIGH / 10) * 9, small_right[i].speed = 1 + rand() % 8;
if (mid_left[i].x <= -100 && mid_left[i].show == 1)mid_left[i].x = WIDTH, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9, mid_left[i].speed = 1 + (rand() % 4) * 2;
if (mid_right[i].x >= WIDTH && mid_right[i].show == 1)mid_right[i].x = -100, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9, mid_right[i].speed = 1 + (rand() % 2) * 4;
if (shark_left[i].x <= -200 && shark_left[i].show == 1)shark_left[i].x = WIDTH, shark_left[i].y = (rand() % 10) * 64;
if (shark_right[i].x >= WIDTH && shark_right[i].show == 1)shark_right[i].x = -200, shark_right[i].y = (rand() % 10) * 64;
}
if (player1.show == 1) {
/*判断小鱼是否被吃(玩家一)*/
for (i = 0; i < 19; i++) {
if ((small_left[i].x >= player1.x && small_left[i].x <= player1.x + 94 && small_left[i].y >= player1.y && small_left[i].y <= player1.y + 57) ||
(small_left[i].x + small_left[i].length >= player1.x && small_left[i].x + small_left[i].length <= player1.x + 94 && small_left[i].y >= player1.y && small_left[i].y <= player1.y + 57) ||
(small_left[i].x >= player1.x && small_left[i].x <= player1.x + 94 && small_left[i].y + small_left[i].broad >= player1.y && small_left[i].y + small_left[i].broad <= player1.y + 94) ||
(small_left[i].x + small_left[i].length >= player1.x && small_left[i].x + small_left[i].length <= player1.x + 94 && small_left[i].y + small_left[i].broad >= player1.y && small_left[i].y + small_left[i].broad <= player1.y + 94) ||
(small_left[i].x + small_left[i].length / 2 >= player1.x && small_left[i].x + small_left[i].length / 2 <= player1.x + 94 && small_left[i].y + small_left[i].broad / 2 >= player1.y && small_left[i].y + small_left[i].broad / 2 <= player1.y + 57)) {
small_left[i].x = WIDTH + 50, small_left[i].y = 25 + rand() % (HIGH / 10) * 9;//被吃后更新纵坐标,复原横坐标
small_left[i].show = 0;//被吃后更新一条新的鱼图片
m = rand() % 19;//被吃后更新一条新的鱼图片
while (small_left[m].show == 1)m = rand() % 19;//被吃后更新一条新的鱼图片
small_left[m].show = 1;//被吃后更新一条新的鱼图片
score += small_left[i].length * small_left[i].broad / 500;//分数与鱼的大小有关系
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((small_right[i].x >= player1.x && small_right[i].x <= player1.x + 94 && small_right[i].y >= player1.y && small_right[i].y <= player1.y + 57) ||
(small_right[i].x + small_right[i].length >= player1.x && small_right[i].x + small_right[i].length <= player1.x + 94 && small_right[i].y >= player1.y && small_right[i].y <= player1.y + 57) ||
(small_right[i].x >= player1.x && small_right[i].x <= player1.x + 94 && small_right[i].y + small_right[i].broad >= player1.y && small_right[i].y + small_right[i].broad <= player1.y + 94) ||
(small_right[i].x + small_right[i].length >= player1.x && small_right[i].x + small_right[i].length <= player1.x + 94 && small_right[i].y + small_right[i].broad >= player1.y && small_right[i].y + small_right[i].broad <= player1.y + 94) ||
(small_right[i].x + small_right[i].length / 2 >= player1.x && small_right[i].x + small_right[i].length / 2 <= player1.x + 94 && small_right[i].y + small_right[i].broad / 2 >= player1.y && small_right[i].y + small_right[i].broad / 2 <= player1.y + 57)) {
small_right[i].x = -70, small_right[i].y = 25 + rand() % (HIGH / 10) * 9;
small_right[i].show = 0;
m = rand() % 19;
while (small_right[m].show == 1)m = rand() % 19;
small_right[m].show = 1;
score += small_right[i].length * small_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
/*判断中鱼是否被吃(玩家一)*/
for (i = 0; i < 19; i++) {
if ((mid_left[i].x >= player1.x && mid_left[i].x <= player1.x + 94 && mid_left[i].y >= player1.y && mid_left[i].y <= player1.y + 57) ||
(mid_left[i].x + mid_left[i].length >= player1.x && mid_left[i].x + mid_left[i].length <= player1.x + 94 && mid_left[i].y >= player1.y && mid_left[i].y <= player1.y + 57) ||
(mid_left[i].x >= player1.x && mid_left[i].x <= player1.x + 94 && mid_left[i].y + mid_left[i].broad >= player1.y && mid_left[i].y + mid_left[i].broad <= player1.y + 94) ||
(mid_left[i].x + mid_left[i].length >= player1.x && mid_left[i].x + mid_left[i].length <= player1.x + 94 && mid_left[i].y + mid_left[i].broad >= player1.y && mid_left[i].y + mid_left[i].broad <= player1.y + 94) ||
(mid_left[i].x + mid_left[i].length / 2 >= player1.x && mid_left[i].x + mid_left[i].length / 2 <= player1.x + 94 && mid_left[i].y + mid_left[i].broad / 2 >= player1.y && mid_left[i].y + mid_left[i].broad / 2 <= player1.y + 57)) {
mid_left[i].x = WIDTH + 100, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_left[i].show = 0;
m = rand() % 19;
while (mid_left[m].show == 1)m = rand() % 19;
mid_left[m].show = 1;
score += mid_left[i].length * mid_left[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((mid_right[i].x >= player1.x && mid_right[i].x <= player1.x + 94 && mid_right[i].y >= player1.y && mid_right[i].y <= player1.y + 57) ||
(mid_right[i].x + mid_right[i].length >= player1.x && mid_right[i].x + mid_right[i].length <= player1.x + 94 && mid_right[i].y >= player1.y && mid_right[i].y <= player1.y + 57) ||
(mid_right[i].x >= player1.x && mid_right[i].x <= player1.x + 94 && mid_right[i].y + mid_right[i].broad >= player1.y && mid_right[i].y + mid_right[i].broad <= player1.y + 94) ||
(mid_right[i].x + mid_right[i].length >= player1.x && mid_right[i].x + mid_right[i].length <= player1.x + 94 && mid_right[i].y + mid_right[i].broad >= player1.y && mid_right[i].y + mid_right[i].broad <= player1.y + 94) ||
(mid_right[i].x + mid_right[i].length / 2 >= player1.x && mid_right[i].x + mid_right[i].length / 2 <= player1.x + 94 && mid_right[i].y + mid_right[i].broad / 2 >= player1.y && mid_right[i].y + mid_right[i].broad / 2 <= player1.y + 57)) {
mid_right[i].x = -150, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_right[i].show = 0;
m = rand() % 19;
while (mid_right[m].show == 1)m = rand() % 19;
mid_right[m].show = 1;
score += mid_right[i].length * mid_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
}
if (player2.show == 1) {
/*判断小鱼是否被吃(玩家2)*/
for (i = 0; i < 19; i++) {
if ((small_left[i].x >= player2.x && small_left[i].x <= player2.x + 94 && small_left[i].y >= player2.y && small_left[i].y <= player2.y + 57) ||
(small_left[i].x + small_left[i].length >= player2.x && small_left[i].x + small_left[i].length <= player2.x + 94 && small_left[i].y >= player2.y && small_left[i].y <= player2.y + 57) ||
(small_left[i].x >= player2.x && small_left[i].x <= player2.x + 94 && small_left[i].y + small_left[i].broad >= player2.y && small_left[i].y + small_left[i].broad <= player2.y + 94) ||
(small_left[i].x + small_left[i].length >= player2.x && small_left[i].x + small_left[i].length <= player2.x + 94 && small_left[i].y + small_left[i].broad >= player2.y && small_left[i].y + small_left[i].broad <= player2.y + 94) ||
(small_left[i].x + small_left[i].length / 2 >= player2.x && small_left[i].x + small_left[i].length / 2 <= player2.x + 94 && small_left[i].y + small_left[i].broad / 2 >= player2.y && small_left[i].y + small_left[i].broad / 2 <= player2.y + 57)) {
small_left[i].x = WIDTH + 50, small_left[i].y = 25 + rand() % (HIGH / 10) * 9;//被吃后更新纵坐标,复原横坐标
small_left[i].show = 0;//被吃后更新一条新的鱼图片
m = rand() % 19;//被吃后更新一条新的鱼图片
while (small_left[m].show == 1)m = rand() % 19;//被吃后更新一条新的鱼图片
small_left[m].show = 1;//被吃后更新一条新的鱼图片
score += small_left[i].length * small_left[i].broad / 500;//分数与鱼的大小有关系
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((small_right[i].x >= player2.x && small_right[i].x <= player2.x + 94 && small_right[i].y >= player2.y && small_right[i].y <= player2.y + 57) ||
(small_right[i].x + small_right[i].length >= player2.x && small_right[i].x + small_right[i].length <= player2.x + 94 && small_right[i].y >= player2.y && small_right[i].y <= player2.y + 57) ||
(small_right[i].x >= player2.x && small_right[i].x <= player2.x + 94 && small_right[i].y + small_right[i].broad >= player2.y && small_right[i].y + small_right[i].broad <= player2.y + 94) ||
(small_right[i].x + small_right[i].length >= player2.x && small_right[i].x + small_right[i].length <= player2.x + 94 && small_right[i].y + small_right[i].broad >= player2.y && small_right[i].y + small_right[i].broad <= player2.y + 94) ||
(small_right[i].x + small_right[i].length / 2 >= player2.x && small_right[i].x + small_right[i].length / 2 <= player2.x + 94 && small_right[i].y + small_right[i].broad / 2 >= player2.y && small_right[i].y + small_right[i].broad / 2 <= player2.y + 57)) {
small_right[i].x = -70, small_right[i].y = 25 + rand() % (HIGH / 10) * 9;
small_right[i].show = 0;
m = rand() % 19;
while (small_right[m].show == 1)m = rand() % 19;
small_right[m].show = 1;
score += small_right[i].length * small_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
/*判断中鱼是否被吃(玩家2)*/
for (i = 0; i < 19; i++) {
if ((mid_left[i].x >= player2.x && mid_left[i].x <= player2.x + 94 && mid_left[i].y >= player2.y && mid_left[i].y <= player2.y + 57) ||
(mid_left[i].x + mid_left[i].length >= player2.x && mid_left[i].x + mid_left[i].length <= player2.x + 94 && mid_left[i].y >= player2.y && mid_left[i].y <= player2.y + 57) ||
(mid_left[i].x >= player2.x && mid_left[i].x <= player2.x + 94 && mid_left[i].y + mid_left[i].broad >= player2.y && mid_left[i].y + mid_left[i].broad <= player2.y + 94) ||
(mid_left[i].x + mid_left[i].length >= player2.x && mid_left[i].x + mid_left[i].length <= player2.x + 94 && mid_left[i].y + mid_left[i].broad >= player2.y && mid_left[i].y + mid_left[i].broad <= player2.y + 94) ||
(mid_left[i].x + mid_left[i].length / 2 >= player2.x && mid_left[i].x + mid_left[i].length / 2 <= player2.x + 94 && mid_left[i].y + mid_left[i].broad / 2 >= player2.y && mid_left[i].y + mid_left[i].broad / 2 <= player2.y + 57)) {
mid_left[i].x = WIDTH + 100, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_left[i].show = 0;
m = rand() % 19;
while (mid_left[m].show == 1)m = rand() % 19;
mid_left[m].show = 1;
score += mid_left[i].length * mid_left[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((mid_right[i].x >= player2.x && mid_right[i].x <= player2.x + 94 && mid_right[i].y >= player2.y && mid_right[i].y <= player2.y + 57) ||
(mid_right[i].x + mid_right[i].length >= player2.x && mid_right[i].x + mid_right[i].length <= player2.x + 94 && mid_right[i].y >= player2.y && mid_right[i].y <= player2.y + 57) ||
(mid_right[i].x >= player2.x && mid_right[i].x <= player2.x + 94 && mid_right[i].y + mid_right[i].broad >= player2.y && mid_right[i].y + mid_right[i].broad <= player2.y + 94) ||
(mid_right[i].x + mid_right[i].length >= player2.x && mid_right[i].x + mid_right[i].length <= player2.x + 94 && mid_right[i].y + mid_right[i].broad >= player2.y && mid_right[i].y + mid_right[i].broad <= player2.y + 94) ||
(mid_right[i].x + mid_right[i].length / 2 >= player2.x && mid_right[i].x + mid_right[i].length / 2 <= player2.x + 94 && mid_right[i].y + mid_right[i].broad / 2 >= player2.y && mid_right[i].y + mid_right[i].broad / 2 <= player2.y + 57)) {
mid_right[i].x = -150, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_right[i].show = 0;
m = rand() % 19;
while (mid_right[m].show == 1)m = rand() % 19;
mid_right[m].show = 1;
score += mid_right[i].length * mid_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
}
//判断玩家是否被吃
for (i = 0; i < 19; i++) {
//使用了多个点进行判断
if (player1.show == 1) {
if (shark_left[i].show == 1) //只有出现的鲨鱼才能吃玩家1(左游)
if ((player1.x + 32 >= shark_left[i].x && player1.x + 32 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 33 >= shark_left[i].x && player1.x + 33 <= shark_left[i].x + shark_left[i].length && player1.y + 22 >= shark_left[i].y + 19 && player1.y + 22 <= shark_left[i].y + 49) ||
(player1.x + 20 >= shark_left[i].x && player1.x + 20 <= shark_left[i].x + shark_left[i].length && player1.y + 30 >= shark_left[i].y + 19 && player1.y + 30 <= shark_left[i].y + 49) ||
(player1.x + 32 >= shark_left[i].x && player1.x + 32 <= shark_left[i].x + shark_left[i].length && player1.y + 36 >= shark_left[i].y + 19 && player1.y + 36 <= shark_left[i].y + 49) ||
(player1.x + 43 >= shark_left[i].x && player1.x + 43 <= shark_left[i].x + shark_left[i].length && player1.y + 46 >= shark_left[i].y + 19 && player1.y + 46 <= shark_left[i].y + 49) ||
(player1.x + 53 >= shark_left[i].x && player1.x + 53 <= shark_left[i].x + shark_left[i].length && player1.y + 48 >= shark_left[i].y + 19 && player1.y + 48 <= shark_left[i].y + 49) ||
(player1.x + 77 >= shark_left[i].x && player1.x + 77 <= shark_left[i].x + shark_left[i].length && player1.y + 29 >= shark_left[i].y + 19 && player1.y + 29 <= shark_left[i].y + 49) ||
(player1.x + 54 >= shark_left[i].x && player1.x + 54 <= shark_left[i].x + shark_left[i].length && player1.y + 14 >= shark_left[i].y + 19 && player1.y + 14 <= shark_left[i].y + 49) ||
(player1.x + 67 >= shark_left[i].x && player1.x + 67 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 31 >= shark_left[i].x && player1.x + 31 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 17 >= shark_left[i].x && player1.x + 17 <= shark_left[i].x + shark_left[i].length && player1.y + 29 >= shark_left[i].y + 19 && player1.y + 29 <= shark_left[i].y + 49) ||
(player1.x + 39 >= shark_left[i].x && player1.x + 39 <= shark_left[i].x + shark_left[i].length && player1.y + 47 >= shark_left[i].y + 19 && player1.y + 47 <= shark_left[i].y + 49)) {
start_player1 = clock();
player1.show = 0;
break;
}
if (shark_right[i].show == 1) //只有出现的鲨鱼才能吃玩家1(右游)
if ((player1.x + 32 >= shark_right[i].x && player1.x + 32 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 33 >= shark_right[i].x && player1.x + 33 <= shark_right[i].x + shark_right[i].length && player1.y + 22 >= shark_right[i].y + 19 && player1.y + 22 <= shark_right[i].y + 49) ||
(player1.x + 20 >= shark_right[i].x && player1.x + 20 <= shark_right[i].x + shark_right[i].length && player1.y + 30 >= shark_right[i].y + 19 && player1.y + 30 <= shark_right[i].y + 49) ||
(player1.x + 32 >= shark_right[i].x && player1.x + 32 <= shark_right[i].x + shark_right[i].length && player1.y + 36 >= shark_right[i].y + 19 && player1.y + 36 <= shark_right[i].y + 49) ||
(player1.x + 43 >= shark_right[i].x && player1.x + 43 <= shark_right[i].x + shark_right[i].length && player1.y + 46 >= shark_right[i].y + 19 && player1.y + 46 <= shark_right[i].y + 49) ||
(player1.x + 53 >= shark_right[i].x && player1.x + 53 <= shark_right[i].x + shark_right[i].length && player1.y + 48 >= shark_right[i].y + 19 && player1.y + 48 <= shark_right[i].y + 49) ||
(player1.x + 77 >= shark_right[i].x && player1.x + 77 <= shark_right[i].x + shark_right[i].length && player1.y + 29 >= shark_right[i].y + 19 && player1.y + 29 <= shark_right[i].y + 49) ||
(player1.x + 54 >= shark_right[i].x && player1.x + 54 <= shark_right[i].x + shark_right[i].length && player1.y + 14 >= shark_right[i].y + 19 && player1.y + 14 <= shark_right[i].y + 49) ||
(player1.x + 67 >= shark_right[i].x && player1.x + 67 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 31 >= shark_right[i].x && player1.x + 31 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 17 >= shark_right[i].x && player1.x + 17 <= shark_right[i].x + shark_right[i].length && player1.y + 29 >= shark_right[i].y + 19 && player1.y + 29 <= shark_right[i].y + 49) ||
(player1.x + 39 >= shark_right[i].x && player1.x + 39 <= shark_right[i].x + shark_right[i].length && player1.y + 47 >= shark_right[i].y + 19 && player1.y + 47 <= shark_right[i].y + 49)) {
start_player1 = clock();
player1.show = 0;
break;
}
}
}
for (i = 0; i < 19; i++) {
if (player2.show == 1) {
if (shark_left[i].show == 1) //只有出现的鲨鱼才能吃玩家2(左游)
if ((player2.x + 32 >= shark_left[i].x && player2.x + 32 <= shark_left[i].x + shark_left[i].length && player2.y + 8 >= shark_left[i].y + 19 && player2.y + 8 <= shark_left[i].y + 49) ||
(player2.x + 33 >= shark_left[i].x && player2.x + 33 <= shark_left[i].x + shark_left[i].length && player2.y + 22 >= shark_left[i].y + 19 && player2.y + 22 <= shark_left[i].y + 49) ||
(player2.x + 20 >= shark_left[i].x && player2.x + 20 <= shark_left[i].x + shark_left[i].length && player2.y + 30 >= shark_left[i].y + 19 && player2.y + 30 <= shark_left[i].y + 49) ||
(player2.x + 32 >= shark_left[i].x && player2.x + 32 <= shark_left[i].x + shark_left[i].length && player2.y + 36 >= shark_left[i].y + 19 && player2.y + 36 <= shark_left[i].y + 49) ||
(player2.x + 43 >= shark_left[i].x && player2.x + 43 <= shark_left[i].x + shark_left[i].length && player2.y + 46 >= shark_left[i].y + 19 && player2.y + 46 <= shark_left[i].y + 49) ||
(player2.x + 53 >= shark_left[i].x && player2.x + 53 <= shark_left[i].x + shark_left[i].length && player2.y + 48 >= shark_left[i].y + 19 && player2.y + 48 <= shark_left[i].y + 49) ||
(player2.x + 77 >= shark_left[i].x && player2.x + 77 <= shark_left[i].x + shark_left[i].length && player2.y + 29 >= shark_left[i].y + 19 && player2.y + 29 <= shark_left[i].y + 49) ||
(player2.x + 54 >= shark_left[i].x && player2.x + 54 <= shark_left[i].x + shark_left[i].length && player2.y + 14 >= shark_left[i].y + 19 && player2.y + 14 <= shark_left[i].y + 49) ||
(player2.x + 67 >= shark_left[i].x && player2.x + 67 <= shark_left[i].x + shark_left[i].length && player2.y + 8 >= shark_left[i].y + 19 && player2.y + 8 <= shark_left[i].y + 49) ||
(player2.x + 31 >= shark_left[i].x && player2.x + 31 <= shark_left[i].x + shark_left[i].length && player2.y + 8 >= shark_left[i].y + 19 && player2.y + 8 <= shark_left[i].y + 49) ||
(player2.x + 17 >= shark_left[i].x && player2.x + 17 <= shark_left[i].x + shark_left[i].length && player2.y + 29 >= shark_left[i].y + 19 && player2.y + 29 <= shark_left[i].y + 49) ||
(player2.x + 39 >= shark_left[i].x && player2.x + 39 <= shark_left[i].x + shark_left[i].length && player2.y + 47 >= shark_left[i].y + 19 && player2.y + 47 <= shark_left[i].y + 49)) {
start_player2 = clock();
player2.show = 0;
break;
}
if (shark_right[i].show == 1) //只有出现的鲨鱼才能吃玩家2(右游)
if ((player2.x + 32 >= shark_right[i].x && player2.x + 32 <= shark_right[i].x + shark_right[i].length && player2.y + 8 >= shark_right[i].y + 19 && player2.y + 8 <= shark_right[i].y + 49) ||
(player2.x + 33 >= shark_right[i].x && player2.x + 33 <= shark_right[i].x + shark_right[i].length && player2.y + 22 >= shark_right[i].y + 19 && player2.y + 22 <= shark_right[i].y + 49) ||
(player2.x + 20 >= shark_right[i].x && player2.x + 20 <= shark_right[i].x + shark_right[i].length && player2.y + 30 >= shark_right[i].y + 19 && player2.y + 30 <= shark_right[i].y + 49) ||
(player2.x + 32 >= shark_right[i].x && player2.x + 32 <= shark_right[i].x + shark_right[i].length && player2.y + 36 >= shark_right[i].y + 19 && player2.y + 36 <= shark_right[i].y + 49) ||
(player2.x + 43 >= shark_right[i].x && player2.x + 43 <= shark_right[i].x + shark_right[i].length && player2.y + 46 >= shark_right[i].y + 19 && player2.y + 46 <= shark_right[i].y + 49) ||
(player2.x + 53 >= shark_right[i].x && player2.x + 53 <= shark_right[i].x + shark_right[i].length && player2.y + 48 >= shark_right[i].y + 19 && player2.y + 48 <= shark_right[i].y + 49) ||
(player2.x + 77 >= shark_right[i].x && player2.x + 77 <= shark_right[i].x + shark_right[i].length && player2.y + 29 >= shark_right[i].y + 19 && player2.y + 29 <= shark_right[i].y + 49) ||
(player2.x + 54 >= shark_right[i].x && player2.x + 54 <= shark_right[i].x + shark_right[i].length && player2.y + 14 >= shark_right[i].y + 19 && player2.y + 14 <= shark_right[i].y + 49) ||
(player2.x + 67 >= shark_right[i].x && player2.x + 67 <= shark_right[i].x + shark_right[i].length && player2.y + 8 >= shark_right[i].y + 19 && player2.y + 8 <= shark_right[i].y + 49) ||
(player2.x + 31 >= shark_right[i].x && player2.x + 31 <= shark_right[i].x + shark_right[i].length && player2.y + 8 >= shark_right[i].y + 19 && player2.y + 8 <= shark_right[i].y + 49) ||
(player2.x + 17 >= shark_right[i].x && player2.x + 17 <= shark_right[i].x + shark_right[i].length && player2.y + 29 >= shark_right[i].y + 19 && player2.y + 29 <= shark_right[i].y + 49) ||
(player2.x + 39 >= shark_right[i].x && player2.x + 39 <= shark_right[i].x + shark_right[i].length && player2.y + 47 >= shark_right[i].y + 19 && player2.y + 47 <= shark_right[i].y + 49)) {
start_player2 = clock();
player2.show = 0;
break;
}
}
}
//双方同时死亡,游戏结束,否则过3s复活死亡者
if (player1.show == 0 && player2.show == 0 && rebirth == 0) {
//删除存档
fopen_s(&fp_double_survive, "D:\\GAME\\双人竞技.txt", "w+");
fclose(fp_double_survive);
//判断是否最高分
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
if (max_double_survive < score) {
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "w+");
fprintf(fp_score_history, "%d %d %d", max_single_survive, score, max_double_versus);
fclose(fp_score_history);
}
//关闭背景音乐
if (musicturn == musicon) {
mciSendString("close bkmusic", NULL, 0, NULL);
//播放音乐
mciSendString("close overmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\gameover.mp3 alias overmusic", NULL, 0, NULL);
mciSendString("play overmusic", NULL, 0, NULL);
}
putimage(0, 0, &gameover);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(WIDTH / 4, HIGH / 4, "你的得分是:");
outtextxy(2 * WIDTH / 3, HIGH / 4, mark);
f.lfHeight = 24; // 设置字体高度
settextcolor(WHITE);
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, 4 * HIGH / 5, "左键任意区域以重玩......");
outtextxy(2 * WIDTH / 5, 6 * HIGH / 7, "右键任意区域以退出......");
EndBatchDraw();
MOUSEMSG m;
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
rollback_gamerestart = 1;
break;
}
if (m.uMsg == WM_RBUTTONDOWN)exit(0);
}
}
else if (player1.show == 0 && player2.show == 1 && rebirth == 0) {
end_player1 = clock();
setbkmode(TRANSPARENT);
settextcolor(BLACK);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
_stprintf_s(survive, _T("%lf"), 3 - ((double)end_player1 - (double)start_player1) / CLOCKS_PER_SEC);
outtextxy(7 * WIDTH / 20, HIGH / 100, "距离复活还剩:");
outtextxy(WIDTH / 2, HIGH / 100, survive);
outtextxy(59 * WIDTH / 100, HIGH / 100, "s");
if (((double)end_player1 - (double)start_player1) / CLOCKS_PER_SEC >= 3.000000) {
player1.show = 1;
player1.x = rand() % (WIDTH - player1.length), player1.y = rand() % (HIGH - player1.broad);
rebirth = 1;
start_unbeat = clock();
}
}
else if (player1.show == 1 && player2.show == 0 && rebirth == 0) {
end_player2 = clock();
setbkmode(TRANSPARENT);
settextcolor(BLACK);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
_stprintf_s(survive, _T("%lf"), 3 - ((double)end_player2 - (double)start_player2) / CLOCKS_PER_SEC);
outtextxy(7 * WIDTH / 20, HIGH / 100, "距离复活还剩:");
outtextxy(WIDTH / 2, HIGH / 100, survive);
outtextxy(59 * WIDTH / 100, HIGH / 100, "s");
if (((double)end_player2 - (double)start_player2) / CLOCKS_PER_SEC >= 3.000000) {
player2.show = 1;
player2.x = rand() % (WIDTH - player2.length), player2.y = rand() % (HIGH - player2.broad);
rebirth = 2;
start_unbeat = clock();
}
}
if (rebirth != 0) {
end_unbeat = clock();
if (((double)end_unbeat - (double)start_unbeat) / CLOCKS_PER_SEC <= 2) {
setbkmode(TRANSPARENT);
settextcolor(BLACK);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
_stprintf_s(survive, _T("%lf"), 2 - ((double)end_unbeat - (double)start_unbeat) / CLOCKS_PER_SEC);
outtextxy(7 * WIDTH / 20, HIGH / 100, "无敌结束还剩:");
outtextxy(WIDTH / 2, HIGH / 100, survive);
outtextxy(59 * WIDTH / 100, HIGH / 100, "s");
}
else rebirth = 0, start_unbeat = 0, end_unbeat = 0;
}
if (rebirth == 1)player1.show = 1;
else if (rebirth == 2)player2.show = 1;
FlushBatchDraw();
}
void double_gaming_versus_surface() {
if (sharkturn == sharkon) {
shark_emerge();
}
BeginBatchDraw();
putimage(0, 0, &gamingbk);
setbkmode(TRANSPARENT);
settextcolor(RGB(255, 252, 153));
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
//显示玩家一分数
outtextxy(WIDTH / 20, HIGH / 100, "SCORE1:");
_stprintf_s(mark, _T("%d"), score_player1);
outtextxy(WIDTH / 20 + 100, HIGH / 100, mark);
//显示玩家二分数
outtextxy(5 * WIDTH / 6, HIGH / 100, "SCORE2:");
_stprintf_s(mark, _T("%d"), score_player2);
outtextxy(5 * WIDTH / 6 + 100, HIGH / 100, mark);
//显示玩家
putimage(player1.x, player1.y, &player1.mask, SRCAND);
putimage(player1.x, player1.y, &player1.png, SRCINVERT);
putimage(player2.x, player2.y, &player2.mask, SRCAND);
putimage(player2.x, player2.y, &player2.png, SRCINVERT);
//显示鱼
for (i = 0; i < 19; i++) {
if (small_left[i].show == 1) {
putimage(small_left[i].x, small_left[i].y, &small_left[i].mask, SRCAND);
putimage(small_left[i].x, small_left[i].y, &small_left[i].png, SRCINVERT);
}
if (small_right[i].show == 1) {
putimage(small_right[i].x, small_right[i].y, &small_right[i].mask, SRCAND);
putimage(small_right[i].x, small_right[i].y, &small_right[i].png, SRCINVERT);
}
if (mid_left[i].show == 1) {
putimage(mid_left[i].x, mid_left[i].y, &mid_left[i].mask, SRCAND);
putimage(mid_left[i].x, mid_left[i].y, &mid_left[i].png, SRCINVERT);
}
if (mid_right[i].show == 1) {
putimage(mid_right[i].x, mid_right[i].y, &mid_right[i].mask, SRCAND);
putimage(mid_right[i].x, mid_right[i].y, &mid_right[i].png, SRCINVERT);
}
if (shark_left[i].show == 1) {
putimage(shark_left[i].x, shark_left[i].y, &shark_left[i].mask, SRCAND);
putimage(shark_left[i].x, shark_left[i].y, &shark_left[i].png, SRCINVERT);
}
if (shark_right[i].show == 1) {
putimage(shark_right[i].x, shark_right[i].y, &shark_right[i].mask, SRCAND);
putimage(shark_right[i].x, shark_right[i].y, &shark_right[i].png, SRCINVERT);
}
}
}
void double_versus_auto_update() {
if (start_vs == 0)start_vs = clock();
srand((unsigned)time(NULL));
int m;
//鱼按照一定速度游
for (i = 0; i < 19; i++) {
//计数器count累加到大于speed时,鱼移动,否则不然
//.show==1是为了只让出现在界面里的鱼游
if (small_left[i].count >= small_left[i].speed && small_left[i].show == 1) {
small_left[i].x--;
small_left[i].count = 0;
}
else if (small_left[i].count < small_left[i].speed && small_left[i].show == 1)small_left[i].count++;
if (small_right[i].count >= small_right[i].speed && small_right[i].show == 1) {
small_right[i].x++;
small_right[i].count = 0;
}
else if (small_right[i].count != small_right[i].speed && small_right[i].show == 1)small_right[i].count++;
if (mid_left[i].count >= mid_left[i].speed && mid_left[i].show == 1) {
mid_left[i].x--;
mid_left[i].count = 0;
}
else if (mid_left[i].count < mid_left[i].speed && mid_left[i].show == 1)mid_left[i].count++;
if (mid_right[i].count >= mid_right[i].speed && mid_right[i].show == 1) {
mid_right[i].x++;
mid_right[i].count = 0;
}
else if (mid_right[i].count < mid_right[i].speed && mid_right[i].show == 1)mid_right[i].count++;
//鲨鱼速度最大,不需要计数器
if (sharkturn == sharkon) {
if (shark_left[i].show == 1)shark_left[i].x--;
if (shark_right[i].show == 1)shark_right[i].x++;
}
}
//判断是否出界
for (i = 0; i < 19; i++) {
/*出界后复原横坐标,重新随机纵坐标*/
if (small_left[i].x <= -50 && small_left[i].show == 1)small_left[i].x = WIDTH, small_left[i].y = 25 + rand() % (HIGH / 10) * 9, small_left[i].speed = 1 + (rand() % 16) / 2;
if (small_right[i].x >= WIDTH && small_right[i].show == 1)small_right[i].x = -50, small_right[i].y = 25 + rand() % (HIGH / 10) * 9, small_right[i].speed = 1 + rand() % 8;
if (mid_left[i].x <= -100 && mid_left[i].show == 1)mid_left[i].x = WIDTH, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9, mid_left[i].speed = 1 + (rand() % 4) * 2;
if (mid_right[i].x >= WIDTH && mid_right[i].show == 1)mid_right[i].x = -100, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9, mid_right[i].speed = 1 + (rand() % 2) * 4;
if (shark_left[i].x <= -200 && shark_left[i].show == 1)shark_left[i].x = WIDTH, shark_left[i].y = (rand() % 10) * 64;
if (shark_right[i].x >= WIDTH && shark_right[i].show == 1)shark_right[i].x = -200, shark_right[i].y = (rand() % 10) * 64;
}
/*判断小鱼是否被吃(玩家一)*/
for (i = 0; i < 19; i++) {
if ((small_left[i].x >= player1.x && small_left[i].x <= player1.x + 94 && small_left[i].y >= player1.y && small_left[i].y <= player1.y + 57) ||
(small_left[i].x + small_left[i].length >= player1.x && small_left[i].x + small_left[i].length <= player1.x + 94 && small_left[i].y >= player1.y && small_left[i].y <= player1.y + 57) ||
(small_left[i].x >= player1.x && small_left[i].x <= player1.x + 94 && small_left[i].y + small_left[i].broad >= player1.y && small_left[i].y + small_left[i].broad <= player1.y + 94) ||
(small_left[i].x + small_left[i].length >= player1.x && small_left[i].x + small_left[i].length <= player1.x + 94 && small_left[i].y + small_left[i].broad >= player1.y && small_left[i].y + small_left[i].broad <= player1.y + 94) ||
(small_left[i].x + small_left[i].length / 2 >= player1.x && small_left[i].x + small_left[i].length / 2 <= player1.x + 94 && small_left[i].y + small_left[i].broad / 2 >= player1.y && small_left[i].y + small_left[i].broad / 2 <= player1.y + 57)) {
small_left[i].x = WIDTH + 50, small_left[i].y = 25 + rand() % (HIGH / 10) * 9;//被吃后更新纵坐标,复原横坐标
small_left[i].show = 0;//被吃后更新一条新的鱼图片
m = rand() % 19;//被吃后更新一条新的鱼图片
while (small_left[m].show == 1)m = rand() % 19;//被吃后更新一条新的鱼图片
small_left[m].show = 1;//被吃后更新一条新的鱼图片
score_player1 += small_left[i].length * small_left[i].broad / 500;//分数与鱼的大小有关系
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((small_right[i].x >= player1.x && small_right[i].x <= player1.x + 94 && small_right[i].y >= player1.y && small_right[i].y <= player1.y + 57) ||
(small_right[i].x + small_right[i].length >= player1.x && small_right[i].x + small_right[i].length <= player1.x + 94 && small_right[i].y >= player1.y && small_right[i].y <= player1.y + 57) ||
(small_right[i].x >= player1.x && small_right[i].x <= player1.x + 94 && small_right[i].y + small_right[i].broad >= player1.y && small_right[i].y + small_right[i].broad <= player1.y + 94) ||
(small_right[i].x + small_right[i].length >= player1.x && small_right[i].x + small_right[i].length <= player1.x + 94 && small_right[i].y + small_right[i].broad >= player1.y && small_right[i].y + small_right[i].broad <= player1.y + 94) ||
(small_right[i].x + small_right[i].length / 2 >= player1.x && small_right[i].x + small_right[i].length / 2 <= player1.x + 94 && small_right[i].y + small_right[i].broad / 2 >= player1.y && small_right[i].y + small_right[i].broad / 2 <= player1.y + 57)) {
small_right[i].x = -70, small_right[i].y = 25 + rand() % (HIGH / 10) * 9;
small_right[i].show = 0;
m = rand() % 19;
while (small_right[m].show == 1)m = rand() % 19;
small_right[m].show = 1;
score_player1 += small_right[i].length * small_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
/*判断中鱼是否被吃(玩家一)*/
for (i = 0; i < 19; i++) {
if ((mid_left[i].x >= player1.x && mid_left[i].x <= player1.x + 94 && mid_left[i].y >= player1.y && mid_left[i].y <= player1.y + 57) ||
(mid_left[i].x + mid_left[i].length >= player1.x && mid_left[i].x + mid_left[i].length <= player1.x + 94 && mid_left[i].y >= player1.y && mid_left[i].y <= player1.y + 57) ||
(mid_left[i].x >= player1.x && mid_left[i].x <= player1.x + 94 && mid_left[i].y + mid_left[i].broad >= player1.y && mid_left[i].y + mid_left[i].broad <= player1.y + 94) ||
(mid_left[i].x + mid_left[i].length >= player1.x && mid_left[i].x + mid_left[i].length <= player1.x + 94 && mid_left[i].y + mid_left[i].broad >= player1.y && mid_left[i].y + mid_left[i].broad <= player1.y + 94) ||
(mid_left[i].x + mid_left[i].length / 2 >= player1.x && mid_left[i].x + mid_left[i].length / 2 <= player1.x + 94 && mid_left[i].y + mid_left[i].broad / 2 >= player1.y && mid_left[i].y + mid_left[i].broad / 2 <= player1.y + 57)) {
mid_left[i].x = WIDTH + 100, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_left[i].show = 0;
m = rand() % 19;
while (mid_left[m].show == 1)m = rand() % 19;
mid_left[m].show = 1;
score_player1 += mid_left[i].length * mid_left[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((mid_right[i].x >= player1.x && mid_right[i].x <= player1.x + 94 && mid_right[i].y >= player1.y && mid_right[i].y <= player1.y + 57) ||
(mid_right[i].x + mid_right[i].length >= player1.x && mid_right[i].x + mid_right[i].length <= player1.x + 94 && mid_right[i].y >= player1.y && mid_right[i].y <= player1.y + 57) ||
(mid_right[i].x >= player1.x && mid_right[i].x <= player1.x + 94 && mid_right[i].y + mid_right[i].broad >= player1.y && mid_right[i].y + mid_right[i].broad <= player1.y + 94) ||
(mid_right[i].x + mid_right[i].length >= player1.x && mid_right[i].x + mid_right[i].length <= player1.x + 94 && mid_right[i].y + mid_right[i].broad >= player1.y && mid_right[i].y + mid_right[i].broad <= player1.y + 94) ||
(mid_right[i].x + mid_right[i].length / 2 >= player1.x && mid_right[i].x + mid_right[i].length / 2 <= player1.x + 94 && mid_right[i].y + mid_right[i].broad / 2 >= player1.y && mid_right[i].y + mid_right[i].broad / 2 <= player1.y + 57)) {
mid_right[i].x = -150, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_right[i].show = 0;
m = rand() % 19;
while (mid_right[m].show == 1)m = rand() % 19;
mid_right[m].show = 1;
score_player1 += mid_right[i].length * mid_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
/*判断小鱼是否被吃(玩家2)*/
for (i = 0; i < 19; i++) {
if ((small_left[i].x >= player2.x && small_left[i].x <= player2.x + 94 && small_left[i].y >= player2.y && small_left[i].y <= player2.y + 57) ||
(small_left[i].x + small_left[i].length >= player2.x && small_left[i].x + small_left[i].length <= player2.x + 94 && small_left[i].y >= player2.y && small_left[i].y <= player2.y + 57) ||
(small_left[i].x >= player2.x && small_left[i].x <= player2.x + 94 && small_left[i].y + small_left[i].broad >= player2.y && small_left[i].y + small_left[i].broad <= player2.y + 94) ||
(small_left[i].x + small_left[i].length >= player2.x && small_left[i].x + small_left[i].length <= player2.x + 94 && small_left[i].y + small_left[i].broad >= player2.y && small_left[i].y + small_left[i].broad <= player2.y + 94) ||
(small_left[i].x + small_left[i].length / 2 >= player2.x && small_left[i].x + small_left[i].length / 2 <= player2.x + 94 && small_left[i].y + small_left[i].broad / 2 >= player2.y && small_left[i].y + small_left[i].broad / 2 <= player2.y + 57)) {
small_left[i].x = WIDTH + 50, small_left[i].y = 25 + rand() % (HIGH / 10) * 9;//被吃后更新纵坐标,复原横坐标
small_left[i].show = 0;//被吃后更新一条新的鱼图片
m = rand() % 19;//被吃后更新一条新的鱼图片
while (small_left[m].show == 1)m = rand() % 19;//被吃后更新一条新的鱼图片
small_left[m].show = 1;//被吃后更新一条新的鱼图片
score_player2 += small_left[i].length * small_left[i].broad / 500;//分数与鱼的大小有关系
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((small_right[i].x >= player2.x && small_right[i].x <= player2.x + 94 && small_right[i].y >= player2.y && small_right[i].y <= player2.y + 57) ||
(small_right[i].x + small_right[i].length >= player2.x && small_right[i].x + small_right[i].length <= player2.x + 94 && small_right[i].y >= player2.y && small_right[i].y <= player2.y + 57) ||
(small_right[i].x >= player2.x && small_right[i].x <= player2.x + 94 && small_right[i].y + small_right[i].broad >= player2.y && small_right[i].y + small_right[i].broad <= player2.y + 94) ||
(small_right[i].x + small_right[i].length >= player2.x && small_right[i].x + small_right[i].length <= player2.x + 94 && small_right[i].y + small_right[i].broad >= player2.y && small_right[i].y + small_right[i].broad <= player2.y + 94) ||
(small_right[i].x + small_right[i].length / 2 >= player2.x && small_right[i].x + small_right[i].length / 2 <= player2.x + 94 && small_right[i].y + small_right[i].broad / 2 >= player2.y && small_right[i].y + small_right[i].broad / 2 <= player2.y + 57)) {
small_right[i].x = -70, small_right[i].y = 25 + rand() % (HIGH / 10) * 9;
small_right[i].show = 0;
m = rand() % 19;
while (small_right[m].show == 1)m = rand() % 19;
small_right[m].show = 1;
score_player2 += small_right[i].length * small_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
/*判断中鱼是否被吃(玩家2)*/
for (i = 0; i < 19; i++) {
if ((mid_left[i].x >= player2.x && mid_left[i].x <= player2.x + 94 && mid_left[i].y >= player2.y && mid_left[i].y <= player2.y + 57) ||
(mid_left[i].x + mid_left[i].length >= player2.x && mid_left[i].x + mid_left[i].length <= player2.x + 94 && mid_left[i].y >= player2.y && mid_left[i].y <= player2.y + 57) ||
(mid_left[i].x >= player2.x && mid_left[i].x <= player2.x + 94 && mid_left[i].y + mid_left[i].broad >= player2.y && mid_left[i].y + mid_left[i].broad <= player2.y + 94) ||
(mid_left[i].x + mid_left[i].length >= player2.x && mid_left[i].x + mid_left[i].length <= player2.x + 94 && mid_left[i].y + mid_left[i].broad >= player2.y && mid_left[i].y + mid_left[i].broad <= player2.y + 94) ||
(mid_left[i].x + mid_left[i].length / 2 >= player2.x && mid_left[i].x + mid_left[i].length / 2 <= player2.x + 94 && mid_left[i].y + mid_left[i].broad / 2 >= player2.y && mid_left[i].y + mid_left[i].broad / 2 <= player2.y + 57)) {
mid_left[i].x = WIDTH + 100, mid_left[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_left[i].show = 0;
m = rand() % 19;
while (mid_left[m].show == 1)m = rand() % 19;
mid_left[m].show = 1;
score_player2 += mid_left[i].length * mid_left[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
if ((mid_right[i].x >= player2.x && mid_right[i].x <= player2.x + 94 && mid_right[i].y >= player2.y && mid_right[i].y <= player2.y + 57) ||
(mid_right[i].x + mid_right[i].length >= player2.x && mid_right[i].x + mid_right[i].length <= player2.x + 94 && mid_right[i].y >= player2.y && mid_right[i].y <= player2.y + 57) ||
(mid_right[i].x >= player2.x && mid_right[i].x <= player2.x + 94 && mid_right[i].y + mid_right[i].broad >= player2.y && mid_right[i].y + mid_right[i].broad <= player2.y + 94) ||
(mid_right[i].x + mid_right[i].length >= player2.x && mid_right[i].x + mid_right[i].length <= player2.x + 94 && mid_right[i].y + mid_right[i].broad >= player2.y && mid_right[i].y + mid_right[i].broad <= player2.y + 94) ||
(mid_right[i].x + mid_right[i].length / 2 >= player2.x && mid_right[i].x + mid_right[i].length / 2 <= player2.x + 94 && mid_right[i].y + mid_right[i].broad / 2 >= player2.y && mid_right[i].y + mid_right[i].broad / 2 <= player2.y + 57)) {
mid_right[i].x = -150, mid_right[i].y = 25 + rand() % (HIGH / 10) * 9;
mid_right[i].show = 0;
m = rand() % 19;
while (mid_right[m].show == 1)m = rand() % 19;
mid_right[m].show = 1;
score_player2 += mid_right[i].length * mid_right[i].broad / 500;
//播放音乐
if (musicturn == musicon) {
mciSendString("close jpmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\eatfish.mp3 alias jpmusic", NULL, 0, NULL);
mciSendString("play jpmusic", NULL, 0, NULL);
}
}
}
//判断玩家是否被鲨鱼吃
if (sharkturn == sharkon){ //鲨鱼开启才执行这命令
for (i = 0; i < 19; i++) {
//使用了多个点进行判断
if (player1.show == 1) {
if (shark_left[i].show == 1) //只有出现的鲨鱼才能吃玩家1(左游)
if ((player1.x + 32 >= shark_left[i].x && player1.x + 32 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 33 >= shark_left[i].x && player1.x + 33 <= shark_left[i].x + shark_left[i].length && player1.y + 22 >= shark_left[i].y + 19 && player1.y + 22 <= shark_left[i].y + 49) ||
(player1.x + 20 >= shark_left[i].x && player1.x + 20 <= shark_left[i].x + shark_left[i].length && player1.y + 30 >= shark_left[i].y + 19 && player1.y + 30 <= shark_left[i].y + 49) ||
(player1.x + 32 >= shark_left[i].x && player1.x + 32 <= shark_left[i].x + shark_left[i].length && player1.y + 36 >= shark_left[i].y + 19 && player1.y + 36 <= shark_left[i].y + 49) ||
(player1.x + 43 >= shark_left[i].x && player1.x + 43 <= shark_left[i].x + shark_left[i].length && player1.y + 46 >= shark_left[i].y + 19 && player1.y + 46 <= shark_left[i].y + 49) ||
(player1.x + 53 >= shark_left[i].x && player1.x + 53 <= shark_left[i].x + shark_left[i].length && player1.y + 48 >= shark_left[i].y + 19 && player1.y + 48 <= shark_left[i].y + 49) ||
(player1.x + 77 >= shark_left[i].x && player1.x + 77 <= shark_left[i].x + shark_left[i].length && player1.y + 29 >= shark_left[i].y + 19 && player1.y + 29 <= shark_left[i].y + 49) ||
(player1.x + 54 >= shark_left[i].x && player1.x + 54 <= shark_left[i].x + shark_left[i].length && player1.y + 14 >= shark_left[i].y + 19 && player1.y + 14 <= shark_left[i].y + 49) ||
(player1.x + 67 >= shark_left[i].x && player1.x + 67 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 31 >= shark_left[i].x && player1.x + 31 <= shark_left[i].x + shark_left[i].length && player1.y + 8 >= shark_left[i].y + 19 && player1.y + 8 <= shark_left[i].y + 49) ||
(player1.x + 17 >= shark_left[i].x && player1.x + 17 <= shark_left[i].x + shark_left[i].length && player1.y + 29 >= shark_left[i].y + 19 && player1.y + 29 <= shark_left[i].y + 49) ||
(player1.x + 39 >= shark_left[i].x && player1.x + 39 <= shark_left[i].x + shark_left[i].length && player1.y + 47 >= shark_left[i].y + 19 && player1.y + 47 <= shark_left[i].y + 49)) {
player1.show = 0;
}
if (shark_right[i].show == 1) //只有出现的鲨鱼才能吃玩家1(右游)
if ((player1.x + 32 >= shark_right[i].x && player1.x + 32 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 33 >= shark_right[i].x && player1.x + 33 <= shark_right[i].x + shark_right[i].length && player1.y + 22 >= shark_right[i].y + 19 && player1.y + 22 <= shark_right[i].y + 49) ||
(player1.x + 20 >= shark_right[i].x && player1.x + 20 <= shark_right[i].x + shark_right[i].length && player1.y + 30 >= shark_right[i].y + 19 && player1.y + 30 <= shark_right[i].y + 49) ||
(player1.x + 32 >= shark_right[i].x && player1.x + 32 <= shark_right[i].x + shark_right[i].length && player1.y + 36 >= shark_right[i].y + 19 && player1.y + 36 <= shark_right[i].y + 49) ||
(player1.x + 43 >= shark_right[i].x && player1.x + 43 <= shark_right[i].x + shark_right[i].length && player1.y + 46 >= shark_right[i].y + 19 && player1.y + 46 <= shark_right[i].y + 49) ||
(player1.x + 53 >= shark_right[i].x && player1.x + 53 <= shark_right[i].x + shark_right[i].length && player1.y + 48 >= shark_right[i].y + 19 && player1.y + 48 <= shark_right[i].y + 49) ||
(player1.x + 77 >= shark_right[i].x && player1.x + 77 <= shark_right[i].x + shark_right[i].length && player1.y + 29 >= shark_right[i].y + 19 && player1.y + 29 <= shark_right[i].y + 49) ||
(player1.x + 54 >= shark_right[i].x && player1.x + 54 <= shark_right[i].x + shark_right[i].length && player1.y + 14 >= shark_right[i].y + 19 && player1.y + 14 <= shark_right[i].y + 49) ||
(player1.x + 67 >= shark_right[i].x && player1.x + 67 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 31 >= shark_right[i].x && player1.x + 31 <= shark_right[i].x + shark_right[i].length && player1.y + 8 >= shark_right[i].y + 19 && player1.y + 8 <= shark_right[i].y + 49) ||
(player1.x + 17 >= shark_right[i].x && player1.x + 17 <= shark_right[i].x + shark_right[i].length && player1.y + 29 >= shark_right[i].y + 19 && player1.y + 29 <= shark_right[i].y + 49) ||
(player1.x + 39 >= shark_right[i].x && player1.x + 39 <= shark_right[i].x + shark_right[i].length && player1.y + 47 >= shark_right[i].y + 19 && player1.y + 47 <= shark_right[i].y + 49)) {
player1.show = 0;
}
}
if (player2.show == 1) {
if (shark_left[i].show == 1) //只有出现的鲨鱼才能吃玩家2(左游)
if ((player2.x + 32 >= shark_left[i].x && player2.x + 32 <= shark_left[i].x + shark_left[i].length && player2.y + 8 >= shark_left[i].y + 19 && player2.y + 8 <= shark_left[i].y + 49) ||
(player2.x + 33 >= shark_left[i].x && player2.x + 33 <= shark_left[i].x + shark_left[i].length && player2.y + 22 >= shark_left[i].y + 19 && player2.y + 22 <= shark_left[i].y + 49) ||
(player2.x + 20 >= shark_left[i].x && player2.x + 20 <= shark_left[i].x + shark_left[i].length && player2.y + 30 >= shark_left[i].y + 19 && player2.y + 30 <= shark_left[i].y + 49) ||
(player2.x + 32 >= shark_left[i].x && player2.x + 32 <= shark_left[i].x + shark_left[i].length && player2.y + 36 >= shark_left[i].y + 19 && player2.y + 36 <= shark_left[i].y + 49) ||
(player2.x + 43 >= shark_left[i].x && player2.x + 43 <= shark_left[i].x + shark_left[i].length && player2.y + 46 >= shark_left[i].y + 19 && player2.y + 46 <= shark_left[i].y + 49) ||
(player2.x + 53 >= shark_left[i].x && player2.x + 53 <= shark_left[i].x + shark_left[i].length && player2.y + 48 >= shark_left[i].y + 19 && player2.y + 48 <= shark_left[i].y + 49) ||
(player2.x + 77 >= shark_left[i].x && player2.x + 77 <= shark_left[i].x + shark_left[i].length && player2.y + 29 >= shark_left[i].y + 19 && player2.y + 29 <= shark_left[i].y + 49) ||
(player2.x + 54 >= shark_left[i].x && player2.x + 54 <= shark_left[i].x + shark_left[i].length && player2.y + 14 >= shark_left[i].y + 19 && player2.y + 14 <= shark_left[i].y + 49) ||
(player2.x + 67 >= shark_left[i].x && player2.x + 67 <= shark_left[i].x + shark_left[i].length && player2.y + 8 >= shark_left[i].y + 19 && player2.y + 8 <= shark_left[i].y + 49) ||
(player2.x + 31 >= shark_left[i].x && player2.x + 31 <= shark_left[i].x + shark_left[i].length && player2.y + 8 >= shark_left[i].y + 19 && player2.y + 8 <= shark_left[i].y + 49) ||
(player2.x + 17 >= shark_left[i].x && player2.x + 17 <= shark_left[i].x + shark_left[i].length && player2.y + 29 >= shark_left[i].y + 19 && player2.y + 29 <= shark_left[i].y + 49) ||
(player2.x + 39 >= shark_left[i].x && player2.x + 39 <= shark_left[i].x + shark_left[i].length && player2.y + 47 >= shark_left[i].y + 19 && player2.y + 47 <= shark_left[i].y + 49)) {
player2.show = 0;
}
if (shark_right[i].show == 1) //只有出现的鲨鱼才能吃玩家2(右游)
if ((player2.x + 32 >= shark_right[i].x && player2.x + 32 <= shark_right[i].x + shark_right[i].length && player2.y + 8 >= shark_right[i].y + 19 && player2.y + 8 <= shark_right[i].y + 49) ||
(player2.x + 33 >= shark_right[i].x && player2.x + 33 <= shark_right[i].x + shark_right[i].length && player2.y + 22 >= shark_right[i].y + 19 && player2.y + 22 <= shark_right[i].y + 49) ||
(player2.x + 20 >= shark_right[i].x && player2.x + 20 <= shark_right[i].x + shark_right[i].length && player2.y + 30 >= shark_right[i].y + 19 && player2.y + 30 <= shark_right[i].y + 49) ||
(player2.x + 32 >= shark_right[i].x && player2.x + 32 <= shark_right[i].x + shark_right[i].length && player2.y + 36 >= shark_right[i].y + 19 && player2.y + 36 <= shark_right[i].y + 49) ||
(player2.x + 43 >= shark_right[i].x && player2.x + 43 <= shark_right[i].x + shark_right[i].length && player2.y + 46 >= shark_right[i].y + 19 && player2.y + 46 <= shark_right[i].y + 49) ||
(player2.x + 53 >= shark_right[i].x && player2.x + 53 <= shark_right[i].x + shark_right[i].length && player2.y + 48 >= shark_right[i].y + 19 && player2.y + 48 <= shark_right[i].y + 49) ||
(player2.x + 77 >= shark_right[i].x && player2.x + 77 <= shark_right[i].x + shark_right[i].length && player2.y + 29 >= shark_right[i].y + 19 && player2.y + 29 <= shark_right[i].y + 49) ||
(player2.x + 54 >= shark_right[i].x && player2.x + 54 <= shark_right[i].x + shark_right[i].length && player2.y + 14 >= shark_right[i].y + 19 && player2.y + 14 <= shark_right[i].y + 49) ||
(player2.x + 67 >= shark_right[i].x && player2.x + 67 <= shark_right[i].x + shark_right[i].length && player2.y + 8 >= shark_right[i].y + 19 && player2.y + 8 <= shark_right[i].y + 49) ||
(player2.x + 31 >= shark_right[i].x && player2.x + 31 <= shark_right[i].x + shark_right[i].length && player2.y + 8 >= shark_right[i].y + 19 && player2.y + 8 <= shark_right[i].y + 49) ||
(player2.x + 17 >= shark_right[i].x && player2.x + 17 <= shark_right[i].x + shark_right[i].length && player2.y + 29 >= shark_right[i].y + 19 && player2.y + 29 <= shark_right[i].y + 49) ||
(player2.x + 39 >= shark_right[i].x && player2.x + 39 <= shark_right[i].x + shark_right[i].length && player2.y + 47 >= shark_right[i].y + 19 && player2.y + 47 <= shark_right[i].y + 49)) {
player2.show = 0;
}
}
}
}
end_vs = clock();
if (15 - ((double)end_vs - (double)start_vs) / CLOCKS_PER_SEC < 0) {
//玩家一分数大于玩家二
if (score_player1 > score_player2) {
if ((player2.x + 32 >= player1.x + 10 && player2.x + 32 <= player1.x + 70 && player2.y + 8 >= player1.y + 5 && player2.y + 8 <= player1.y + 51) ||
(player2.x + 33 >= player1.x + 10 && player2.x + 33 <= player1.x + 70 && player2.y + 22 >= player1.y + 5 && player2.y + 22 <= player1.y + 51) ||
(player2.x + 20 >= player1.x + 10 && player2.x + 20 <= player1.x + 70 && player2.y + 30 >= player1.y + 5 && player2.y + 30 <= player1.y + 51) ||
(player2.x + 32 >= player1.x + 10 && player2.x + 32 <= player1.x + 70 && player2.y + 36 >= player1.y + 5 && player2.y + 36 <= player1.y + 51) ||
(player2.x + 43 >= player1.x + 10 && player2.x + 43 <= player1.x + 70 && player2.y + 46 >= player1.y + 5 && player2.y + 46 <= player1.y + 51) ||
(player2.x + 53 >= player1.x + 10 && player2.x + 53 <= player1.x + 70 && player2.y + 48 >= player1.y + 5 && player2.y + 48 <= player1.y + 51) ||
(player2.x + 77 >= player1.x + 10 && player2.x + 77 <= player1.x + 70 && player2.y + 29 >= player1.y + 5 && player2.y + 29 <= player1.y + 51) ||
(player2.x + 54 >= player1.x + 10 && player2.x + 54 <= player1.x + 70 && player2.y + 14 >= player1.y + 5 && player2.y + 14 <= player1.y + 51) ||
(player2.x + 67 >= player1.x + 10 && player2.x + 67 <= player1.x + 70 && player2.y + 8 >= player1.y + 5 && player2.y + 8 <= player1.y + 51) ||
(player2.x + 31 >= player1.x + 10 && player2.x + 31 <= player1.x + 70 && player2.y + 8 >= player1.y + 5 && player2.y + 8 <= player1.y + 51) ||
(player2.x + 17 >= player1.x + 10 && player2.x + 17 <= player1.x + 70 && player2.y + 29 >= player1.y + 5 && player2.y + 29 <= player1.y + 51) ||
(player2.x + 39 >= player1.x + 10 && player2.x + 39 <= player1.x + 70 && player2.y + 47 >= player1.y + 5 && player2.y + 47 <= player1.y + 51))
player2.show = 0;
}
//玩家二分数大于玩家一
if (score_player2 > score_player1) {
if ((player1.x + 32 >= player2.x + 10 && player1.x + 32 <= player2.x + 70 && player1.y + 8 >= player2.y + 5 && player1.y + 8 <= player2.y + 51) ||
(player1.x + 33 >= player2.x + 10 && player1.x + 33 <= player2.x + 70 && player1.y + 22 >= player2.y + 5 && player1.y + 22 <= player2.y + 51) ||
(player1.x + 20 >= player2.x + 10 && player1.x + 20 <= player2.x + 70 && player1.y + 30 >= player2.y + 5 && player1.y + 30 <= player2.y + 51) ||
(player1.x + 32 >= player2.x + 10 && player1.x + 32 <= player2.x + 70 && player1.y + 36 >= player2.y + 5 && player1.y + 36 <= player2.y + 51) ||
(player1.x + 43 >= player2.x + 10 && player1.x + 43 <= player2.x + 70 && player1.y + 46 >= player2.y + 5 && player1.y + 46 <= player2.y + 51) ||
(player1.x + 53 >= player2.x + 10 && player1.x + 53 <= player2.x + 70 && player1.y + 48 >= player2.y + 5 && player1.y + 48 <= player2.y + 51) ||
(player1.x + 77 >= player2.x + 10 && player1.x + 77 <= player2.x + 70 && player1.y + 29 >= player2.y + 5 && player1.y + 29 <= player2.y + 51) ||
(player1.x + 54 >= player2.x + 10 && player1.x + 54 <= player2.x + 70 && player1.y + 14 >= player2.y + 5 && player1.y + 14 <= player2.y + 51) ||
(player1.x + 67 >= player2.x + 10 && player1.x + 67 <= player2.x + 70 && player1.y + 8 >= player2.y + 5 && player1.y + 8 <= player2.y + 51) ||
(player1.x + 31 >= player2.x + 10 && player1.x + 31 <= player2.x + 70 && player1.y + 8 >= player2.y + 5 && player1.y + 8 <= player2.y + 51) ||
(player1.x + 17 >= player2.x + 10 && player1.x + 17 <= player2.x + 70 && player1.y + 29 >= player2.y + 5 && player1.y + 29 <= player2.y + 51) ||
(player1.x + 39 >= player2.x + 10 && player1.x + 39 <= player2.x + 70 && player1.y + 47 >= player2.y + 5 && player1.y + 47 <= player2.y + 51))
player1.show = 0;
}
}
if (15 - ((double)end_vs - (double)start_vs) / CLOCKS_PER_SEC >= 0) {
setbkmode(TRANSPARENT);
settextcolor(BLACK);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(WIDTH / 2 - 160, HIGH / 100, "剩余发育时间:");
_stprintf_s(vstime, _T("%lf"), 15 - ((double)end_vs - (double)start_vs) / CLOCKS_PER_SEC);
outtextxy(WIDTH / 2, HIGH / 100, vstime);
}
else {
setbkmode(TRANSPARENT);
settextcolor(RED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 24; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(WIDTH / 2 - 100, HIGH / 100, "VS模式已开启 !");
}
FlushBatchDraw();
if (player1.show == 1 && player2.show == 0) {
//删除存档
fopen_s(&fp_double_versus, "D:\\GAME\\双人竞技.txt", "w+");
fclose(fp_double_versus);
//判断是否最高分
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
if (max_double_versus < score_player1 + score_player2) {
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "w+");
fprintf(fp_score_history, "%d %d %d", max_single_survive, max_double_survive, score_player1 + score_player2);
fclose(fp_score_history);
}
//关闭背景音乐
if (musicturn == musicon) {
mciSendString("close bkmusic", NULL, 0, NULL);
//播放音乐
mciSendString("close overmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\pkover.mp3 alias overmusic", NULL, 0, NULL);
mciSendString("play overmusic", NULL, 0, NULL);
}
putimage(0, 0, &gameover);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, HIGH / 2, "玩家一获胜!");
f.lfHeight = 24; // 设置字体高度
settextcolor(WHITE);
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, 4 * HIGH / 5, "左键任意区域以重玩......");
outtextxy(2 * WIDTH / 5, 6 * HIGH / 7, "右键任意区域以退出......");
EndBatchDraw();
MOUSEMSG m;
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
rollback_gamerestart = 1;
break;
}
if (m.uMsg == WM_RBUTTONDOWN)exit(0);
}
}
else if (player1.show == 0 && player2.show == 1) {
//删除存档
fopen_s(&fp_double_versus, "D:\\GAME\\双人竞技.txt", "w+");
fclose(fp_double_versus);
//判断是否最高分
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
if (max_double_versus < score_player1 + score_player2) {
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "w+");
fprintf(fp_score_history, "%d %d %d", max_single_survive, max_double_survive, score_player1 + score_player2);
fclose(fp_score_history);
}
//关闭背景音乐
if (musicturn == musicon) {
mciSendString("close bkmusic", NULL, 0, NULL);
//播放音乐
mciSendString("close overmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\pkover.mp3 alias overmusic", NULL, 0, NULL);
mciSendString("play overmusic", NULL, 0, NULL);
}
putimage(0, 0, &gameover);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, HIGH / 2, "玩家二获胜!");
f.lfHeight = 24; // 设置字体高度
settextcolor(WHITE);
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, 4 * HIGH / 5, "左键任意区域以重玩......");
outtextxy(2 * WIDTH / 5, 6 * HIGH / 7, "右键任意区域以退出......");
EndBatchDraw();
MOUSEMSG m;
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
rollback_gamerestart = 1;
break;
}
if (m.uMsg == WM_RBUTTONDOWN)exit(0);
}
}
else if (player1.show == 0 && player2.show == 0) {
//删除存档
fopen_s(&fp_double_versus, "D:\\GAME\\双人竞技.txt", "w+");
fclose(fp_double_versus);
//判断是否最高分
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
if (max_double_versus < score_player1 + score_player2) {
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "w+");
fprintf(fp_score_history, "%d %d %d", max_single_survive, max_double_survive, score_player1 + score_player2);
fclose(fp_score_history);
}
//关闭背景音乐
if (musicturn == musicon) {
mciSendString("close bkmusic", NULL, 0, NULL);
//播放音乐
mciSendString("close overmusic", NULL, 0, NULL);
mciSendString("open D:\\GAME\\pkover.mp3 alias overmusic", NULL, 0, NULL);
mciSendString("play overmusic", NULL, 0, NULL);
}
putimage(0, 0, &gameover);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
outtextxy(WIDTH / 2, HIGH / 2, "平局!");
f.lfHeight = 24; // 设置字体高度
settextcolor(WHITE);
settextstyle(&f); // 设置字体样式
outtextxy(2 * WIDTH / 5, 4 * HIGH / 5, "左键任意区域以重玩......");
outtextxy(2 * WIDTH / 5, 6 * HIGH / 7, "右键任意区域以退出......");
EndBatchDraw();
MOUSEMSG m;
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) {
rollback_gamerestart = 1;
break;
}
if (m.uMsg == WM_RBUTTONDOWN)exit(0);
}
}
}
void double_input_update_key() { //双人键盘移动
//玩家一
if ((GetAsyncKeyState(0x41) & 0x8000)) {
loadimage(&player1.png, _T("D:\\GAME\\初始鱼左1.bmp"));
loadimage(&player1.mask, _T("D:\\GAME\\初始鱼左_mask.bmp"));
if (player1.x > -10 && player1.show == 1)player1.x--;
}
if ((GetAsyncKeyState(0x44) & 0x8000)) {
loadimage(&player1.png, _T("D:\\GAME\\初始鱼右1.bmp"));
loadimage(&player1.mask, _T("D:\\GAME\\初始鱼右_mask.bmp"));
if (player1.x < WIDTH - player1.length + 10 && player1.show == 1)player1.x++;
}
if ((GetAsyncKeyState(0x57) & 0x8000))if (player1.y > -5 && player1.show == 1)player1.y--;
if ((GetAsyncKeyState(0x53) & 0x8000))if (player1.y < HIGH - player1.broad + 5 && player1.show == 1)player1.y++;
//玩家2
if ((GetAsyncKeyState(0x25) & 0x8000)) {
loadimage(&player2.png, _T("D:\\GAME\\初始鱼左2.bmp"));
loadimage(&player2.mask, _T("D:\\GAME\\初始鱼左_mask.bmp"));
if (player2.x > -10 && player2.show == 1)player2.x--;
}
if ((GetAsyncKeyState(0x27) & 0x8000)) {
loadimage(&player2.png, _T("D:\\GAME\\初始鱼右2.bmp"));
loadimage(&player2.mask, _T("D:\\GAME\\初始鱼右_mask.bmp"));
if (player2.x < WIDTH - player2.length + 10 && player2.show == 1)player2.x++;
}
if ((GetAsyncKeyState(0x26) & 0x8000))if (player2.y > -5 && player2.show == 1)player2.y--;
if ((GetAsyncKeyState(0x28) & 0x8000))if (player2.y < HIGH - player2.broad + 5 && player2.show == 1)player2.y++;
if ((GetAsyncKeyState(0x1B) & 0x8000)) {
putimage(0, 0, &gamingset);
EndBatchDraw();
MOUSEMSG n, m;
while (1) {
n = GetMouseMsg();
if (n.uMsg == WM_LBUTTONDOWN && n.x >= 470 && n.x <= 706) {
//点击设置
if (n.y >= 364 && n.y <= 432) {
putimage(0, 0, &setsurface);
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) { //按下鼠标左键
//开启音乐
if (m.x >= 30 && m.x <= 180 && m.y >= 21 && m.y <= 193) {
musicturn = musicon;
mciSendString("open D:\\GAME\\bkmusic.mp3 alias bkmusic", NULL, 0, NULL);
mciSendString("play bkmusic repeat", NULL, 0, NULL);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "音乐已开启!");
}
//关闭音乐
if (m.x >= 330 && m.x <= 480 && m.y >= 24 && m.y <= 193) {
musicturn = musicoff;
mciSendString("close bkmusic", NULL, 0, NULL);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "音乐已关闭!");
}
//显示游戏说明
if (m.x >= 35 && m.x <= 181 && m.y >= 319 && m.y <= 494) {
putimage(0, 0, &gamehelp);
while (1) {
m = GetMouseMsg();
if (m.x >= 1114 && m.x <= 1166 && m.y >= 10 && m.y <= 62 && m.uMsg == WM_LBUTTONDOWN) {
break;
}
}
putimage(0, 0, &setsurface);
}
//开启鲨鱼
if (m.x >= 637 && m.x <= 786 && m.y >= 20 && m.y <= 193) {
sharkturn = sharkon;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "鲨鱼已开启!");
}
//关闭鲨鱼
if (m.x >= 932 && m.x <= 1080 && m.y >= 26 && m.y <= 196) {
sharkturn = sharkoff;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "鲨鱼已关闭!");
for (i = 0; i <= 19; i++) {
shark_left[i].show = shark_right[i].show = 0;
}
}
//返回
if (m.x >= 923 && m.x <= 1153 && m.y >= 549 && m.y <= 618) {
putimage(0, 0, &gamingset);
break;
}
}
}
}
//点击返回
if (n.y >= 217 && n.y <= 287)break;
//点击存档返回
if (n.y >= 507 && n.y <= 578) {
if (mode == double_survive) {
fopen_s(&fp_double_survive, "D:\\GAME\\双人生存.txt", "r+");
if (fp_double_survive == NULL)exit(-21);
fprintf(fp_double_survive, "%d %d %d %d %d ", score, player1.x, player1.y, player2.x, player2.y);
for (i = 0; i < 19; i++) {
// 储存速度
fprintf(fp_double_survive, "%d %d %d %d %d %d ", small_left[i].speed, small_right[i].speed, mid_left[i].speed, mid_right[i].speed, shark_left[i].speed, shark_right[i].speed);
//储存坐标
fprintf(fp_double_survive, "%d %d %d %d %d %d ", small_left[i].x, small_right[i].x, mid_left[i].x, mid_right[i].x, shark_left[i].x, shark_right[i].x);
fprintf(fp_double_survive, "%d %d %d %d %d %d ", small_left[i].y, small_right[i].y, mid_left[i].y, mid_right[i].y, shark_left[i].y, shark_right[i].y);
//储存是否出现
fprintf(fp_double_survive, "%d %d %d %d %d %d ", small_left[i].show, small_right[i].show, mid_left[i].show, mid_right[i].show, shark_left[i].show, shark_right[i].show);
}
fclose(fp_double_survive);
rollback_quitgamingplay = 1;
break;
}
if (mode == double_versus) {
fopen_s(&fp_double_versus, "D:\\GAME\\双人竞技.txt", "r+");
if (fp_double_versus == NULL)exit(-25);
fprintf(fp_double_versus, "%d %d %d %d %d %d ", score_player1, score_player2, player1.x, player1.y, player2.x, player2.y);
for (i = 0; i < 19; i++) {
// 储存速度
fprintf(fp_double_versus, "%d %d %d %d %d %d ", small_left[i].speed, small_right[i].speed, mid_left[i].speed, mid_right[i].speed, shark_left[i].speed, shark_right[i].speed);
//储存坐标
fprintf(fp_double_versus, "%d %d %d %d %d %d ", small_left[i].x, small_right[i].x, mid_left[i].x, mid_right[i].x, shark_left[i].x, shark_right[i].x);
fprintf(fp_double_versus, "%d %d %d %d %d %d ", small_left[i].y, small_right[i].y, mid_left[i].y, mid_right[i].y, shark_left[i].y, shark_right[i].y);
//储存是否出现
fprintf(fp_double_versus, "%d %d %d %d %d %d ", small_left[i].show, small_right[i].show, mid_left[i].show, mid_right[i].show, shark_left[i].show, shark_right[i].show);
//储存时间
fprintf(fp_double_versus, "%ld %ld ", start_vs, end_vs);
}
fclose(fp_double_versus);
rollback_quitgamingplay = 1;
break;
}
}
}
}
}
}
void png_updata() { //图片更新
if (mode != double_versus) {
if (score >= 250 && png_flag == 1) {
loadimage(&gamingbk, _T("D:\\GAME\\bk2.png"));
png_flag = 2;
}
if (score >= 500 && png_flag == 2) {
loadimage(&gamingbk, _T("D:\\GAME\\bk3.png"));
png_flag = 3;
}
}
else {
if (score_player1 + score_player2 >= 250 && png_flag == 1) {
loadimage(&gamingbk, _T("D:\\GAME\\bk2.png"));
png_flag = 2;
}
if (score_player1 + score_player2 >= 500 && png_flag == 2) {
loadimage(&gamingbk, _T("D:\\GAME\\bk3.png"));
png_flag = 3;
}
}
}
int main() {
initgraph(WIDTH, HIGH);
top:load_all_picture();
start_surface();
initialize();
if (rollback_quitstartplay == 1) { rollback_quitstartplay = 0; goto top; }
if (choice == play) {
if (musicturn == musicon) {
mciSendString("open D:\\GAME\\bkmusic.mp3 alias bkmusic", NULL, 0, NULL);
mciSendString("play bkmusic repeat", NULL, 0, NULL);
}
//开始游戏
if (mode == single_survive) {
if (continueturn == continueold)read_file();
while (1) {
single_gaming_survive_surface(); //单人生存
single_auto_update(); //单人生存自动更新
single_input_update_key(); //单人键盘移动
png_updata(); //图片更新
if (rollback_gamerestart == 1) {
rollback_gamerestart = 0;
goto top;
}
if (rollback_quitgamingplay == 1) {
rollback_quitgamingplay = 0;
goto top;
}
}
}
if (mode == double_survive) {
if (continueturn == continueold)read_file();
while (1) {
double_gaming_survive_surface(); //双人生存板块
double_survive_auto_update(); //双人生存自动更新
double_input_update_key(); //双人键盘移动
png_updata(); //图片更新
if (rollback_gamerestart == 1) {
rollback_gamerestart = 0;
goto top;
}
if (rollback_quitgamingplay == 1) {
rollback_quitgamingplay = 0;
goto top;
}
}
}
if (mode == double_versus) {
if (continueturn == continueold)read_file();
while (1) {
double_gaming_versus_surface(); //双人竞技板块
double_versus_auto_update(); //双人竞技自动更新
double_input_update_key(); //双人键盘移动
png_updata(); //图片更新
if (rollback_gamerestart == 1) {
rollback_gamerestart = 0;
goto top;
}
if (rollback_quitgamingplay == 1) {
rollback_quitgamingplay = 0;
goto top;
}
}
}
}
//设置界面
if (choice == set) {
MOUSEMSG m;
putimage(0, 0, &setsurface);
while (1) {
m = GetMouseMsg(); //获取鼠标消息
if (m.uMsg == WM_LBUTTONDOWN) { //按下鼠标左键
//开启音乐
if (m.x >= 30 && m.x <= 180 && m.y >= 21 && m.y <= 193) {
musicturn = musicon;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "音乐已开启!");
}
//关闭音乐
if (m.x >= 330 && m.x <= 480 && m.y >= 24 && m.y <= 193) {
musicturn = musicoff;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "音乐已关闭!");
}
//显示游戏说明
if (m.x >= 35 && m.x <= 181 && m.y >= 319 && m.y <= 494) {
putimage(0, 0, &gamehelp);
while (1) {
m = GetMouseMsg();
if (m.x >= 1114 && m.x <= 1166 && m.y >= 10 && m.y <= 62 && m.uMsg == WM_LBUTTONDOWN) {
break;
}
}
putimage(0, 0, &setsurface);
}
//开启鲨鱼
if (m.x >= 637 && m.x <= 786 && m.y >= 20 && m.y <= 193) {
sharkturn = sharkon;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "鲨鱼已开启!");
}
//关闭鲨鱼
if (m.x >= 932 && m.x <= 1080 && m.y >= 26 && m.y <= 196) {
sharkturn = sharkoff;
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "鲨鱼已关闭!");
}
//删除存档
if (m.x >= 345 && m.x <= 491 && m.y >= 305 && m.y <= 494) {
fopen_s(&fp_single_survive, "D:\\GAME\\单人生存.txt", "w+");
fclose(fp_single_survive);
fopen_s(&fp_double_survive, "D:\\GAME\\双人生存.txt", "w+");
fclose(fp_double_survive);
fopen_s(&fp_double_versus, "D:\\GAME\\双人竞技.txt", "w+");
fclose(fp_double_versus);
setbkmode(TRANSPARENT);
settextcolor(LIGHTRED);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
putimage(0, 0, &setsurface);
outtextxy(WIDTH / 3 + 50, 5 * HIGH / 6, "存档已删除!");
}
//历史分数
if (m.x >= 645 && m.x <= 796 && m.y >= 316 && m.y <= 495) {
putimage(0, 0, &score_history);
fopen_s(&fp_score_history, "D:\\GAME\\分数记录.txt", "r+");
fscanf_s(fp_score_history, "%d %d %d", &max_single_survive, &max_double_survive, &max_double_versus);
fclose(fp_score_history);
setbkmode(TRANSPARENT);
settextcolor(WHITE);
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度
_tcscpy_s(f.lfFaceName, _T("MAC_CHARSET")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
_stprintf_s(scoremax, _T("%d"), max_single_survive);
outtextxy(879, 52, scoremax);
_stprintf_s(scoremax, _T("%d"), max_double_survive);
outtextxy(879, 270, scoremax);
_stprintf_s(scoremax, _T("%d"), max_double_versus);
outtextxy(879, 486, scoremax);
MOUSEMSG q;
while (1) {
q = GetMouseMsg();
if (q.x >= 540 && q.x <= 657 && q.y >= 587 && q.y <= 626 && q.uMsg == WM_LBUTTONDOWN) {
break;
}
}
putimage(0, 0, &setsurface);
}
//制作人
if (m.x >= 945 && m.x <= 1072 && m.y >= 309 && m.y <= 495) {
putimage(0, 0, &conductor);
MOUSEMSG q;
while (1) {
q = GetMouseMsg();
if (q.x >= 1115 && q.x <= 1171 && q.y >= 2 && q.y <= 53 && q.uMsg == WM_LBUTTONDOWN) {
break;
}
}
putimage(0, 0, &setsurface);
}
//返回主界面
if (m.x >= 923 && m.x <= 1153 && m.y >= 549 && m.y <= 618) {
rollback_quitset = 1;
break;
}
}
}
}
if (choice == quit)exit(0);
if (rollback_quitset == 1) goto top;
return 0;
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史
huge c语言,C语言大项目 · GrandPaLee/C语言大项目 - Gitee.com相关推荐
- Java语言开发在线购物推荐网 购物商城推荐系统 基于用户、物品的协同过滤推荐算法 SSM(Spring+SpringMVC+Mybatis)开发框架 大数据、人工智能、机器学习项目开发
Java语言开发在线购物推荐网 购物商城推荐系统 基于用户.物品的协同过滤推荐算法 SSM(Spring+SpringMVC+Mybatis)开发框架 大数据.人工智能.机器学习项目开发ShopRec ...
- Java语言开发在线音乐推荐网 音乐推荐系统 网易云音乐爬虫 基于用户、物品的协同过滤推荐算法 SSM(Spring+SpringMVC+Mybatis)框架 大数据、人工智能、机器学习项目开发
Java语言开发在线音乐推荐网 音乐推荐系统 网易云音乐爬虫 基于用户.物品的协同过滤推荐算法 SSM(Spring+SpringMVC+Mybatis)框架 大数据.人工智能.机器学习项目开发Mus ...
- Atitit 项目中的俩大孤岛问题 项目孤岛 编程语言孤岛 项目管理 目录 1. 孤岛效应 1 1.1. 功能重复建设 不同项目组,不同语言的功能重复建设 1 1.2. 人员互相支援不利,项目
Atitit 项目中的俩大孤岛问题 项目孤岛 编程语言孤岛 项目管理 目录 1. 孤岛效应 1 1.1. 功能重复建设 不同项目组,不同语言的功能重复建设 1 1.2. 人员互相支援不利,项目组 ...
- 大数据开发基础入门与项目实战(一)Java SE之1.初识计算机和Java语言
文章目录 前言 1.计算机的体系结构 (1)计算机的基本概念 (2)常见的主要硬件 (3)主要硬件的详解 Ⅰ CPU Ⅱ 内存 Ⅲ 硬盘 Ⅳ 输入输出设备 (4)常见的主要软件 (5)计算机的体系结构 ...
- Scala为什么是大数据第一高薪语言
为什么是Scala 虽然在大数据领域Java的使用更普及,Python也有后来居上的势头,但Scala一直有着不可动摇的地位.我们熟悉的Spark,Kafka,Flink都是由Scala完成了其核心代 ...
- 大数据场景中语言虚拟机的应用和挑战
点击上方蓝字关注我们 大数据场景中语言虚拟机的应用和挑战 吴明瑜1,2, 陈海波1,2, 臧斌宇1,2 1 领域操作系统教育部工程研究中心,上海 200240 2 上海交通大学软件学院并行与分布式系统 ...
- 学习大数据需要什么语言基础
Python易学,人人都可以掌握,如果零基础入门数据开发行业的小伙伴,可以从Python语言入手. Python语言简单易懂,适合零基础入门,在编程语言排名上升最快,能完成数据挖掘.机器学习.实时计算 ...
- 解读|TARS开源项目发布Go语言版本 1
解读|TARS开源项目发布Go语言版本 文章转自开源中国 导语:近日,Tars 开源项目在上海发布并开源了 Go 语言版本,其性能与 C++ 版本相当,比 gRPC 的性能高 5 倍. --编者 Ta ...
- python和r语言做大数据_R和python大数据
数据科学界华山论剑:R与Python巅峰对决 如果你是数据分析领域的新兵,那么你一定很难抉择--在进行数据分析时,到底应该使用哪个语言,R还是Python?在网络上,也经常出现诸如"我想学习 ...
最新文章
- Laravel 5.5 使用 Passport 实现 Auth 认证
- 你用什么态度去看待世界,你就会得到什么样的世界
- java内存图解_图解JAVA内存模型(JMM:JAVA Memory Model)
- 什么是 Silverlight?
- 译 | Azure 应用服务中的程序崩溃监控
- 前端学习(2887):如何短时间内实现v-for createApp解决方案
- 如何在MaxCompute中利用bitmap进行数据处理?
- binder-swagger-java v0.5.0,Swagger API 框架
- PostgreSQL学习的九层宝塔
- python优先级排序_Python Numpy重新排列双向排序
- 牛客SQL题解 - 查找employees表
- 字符的ASCII码值
- 修改华为 Echolife HG8010h 的超级用户密码
- 点击开始十秒倒计时html,十秒倒计时案例.html
- SQL Server 2016 Always Encrypted(始终加密)
- 数算(Python)——牛顿迭代法(巴比伦算法)求解平方根
- 前端开发规范V2023.5
- Tomcat部署到idea
- 美国顶级在线教育平台泄露22TB数据
- 歌名:江湖笑 演唱:周华健
热门文章
- Control-模型预测控制(Model Predict Control,MPC)
- Android面试题:Handler
- Android 进阶——Framework 核心之dumpsys命令浅析
- latex文献怎么弄_科学网—Latex 中如何制作参考文献 (以ApJ为例) - 刘禾阳的博文...
- 【电商开发手册】订单-下单
- 【C语言】C语言零碎知识点
- 用Python实现一个简单课堂点名器V4
- android 格式化USB 和移除USB(U盘)
- 大岩量化小白科普:什么是过度拟合?
- R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间