效果展示
游戏准备
1.素材
https://pan.baidu.com/s/1Ww72D1EPmX15SAkAOzuIQQ
提取码:0q84
2.easyx图形库:实现游戏的界面需要用到
用到的头文件
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#include <windows.h>
#include <mmsystem.h>
#include<math.h>
#pragma comment(lib,"winmm.lib")
目前还需改进的问题
1.玩家飞机与地方相撞时的判断不够仔细
我的方法:直接判断图片矩形是否相交,用两矩形中心点间的横纵坐标差与两矩形长宽和的一半比较,若小于则相交
弊端:飞机并没有占据整个图片,直接用矩形相交判断,会导致判定的相撞范围变大
改进方向:尽可能的将图片中飞机的各个地方的具体大小测出,在做精确判断,不过过于麻烦,说不定会有什么更好的办法呢!(微笑.jpg)
2.缺少特效
敌机死亡后,就直接没了,也许可以添加一些别的特效,例如,弹孔???或者大面积破损?或者???
3.贫瘠的音效
音效基本都在素材包里,除了,手雷使用的那个fire in the hole(穿越火线yyds),虽然不是原声(遗憾.jpg)
提几个我想(刚)强(想)调(到)的点吧
1.定时器
不知道你会不会认真扫读我的代码,不过这个点我还是要叨叨两句的,因为本游戏中所用的clock()函数不是用来读出一个具体时间的,仅仅只是用来起到一个间隔的作用,从而让函数在被重复调用的时候,能有一个间隔
在本游戏的子弹发射,敌机生成,游戏暂停等需要从键盘读入的地方都用到了定时器。这里就又要叨叨一下_getch()和GetAsyncKeyState()函数的区别了,(流汗.jpg)
这两函数最主要的区别有二,一是堵塞性,二是异步性。堵塞会影响流畅,让你的动作不丝滑,但我们的定时器要解决的正好是它的异步性,由于GetAsyncKeyState()函数的异步性,你很难控制自己按的次数,众所皆知你按住不放,或停留时间过长,鬼知道你的电脑给你记了多少次,这里就需要定时器来隔开了。
关于定时器的原理,额,其实可以自己搜一下,因为我们只是用clock()来模拟了一下定时器的功能,关于clock()函数…
t1=t2=0
t2=clock()
if(t2-t1>???间隔ms)
t1=t2
每次调用clock()时,t2计时(从程序开始到调用)
||||||
t1 t2
||||||
t1 t2
其它补充
1.其它函数例如mciSendString(),loadimage(),putimage(),就自己搜吧,用法都挺详细的,因为,我是在是有点懒,而且我解释的话,不一定能解释的全面,你甚至可以直接在编译器里看,python中的help()不正是如此(吃瓜.jgp)
***2.道具我画的有点丑,所以你不可能在素材里找到的,自己画吧 ***
##代码(双人,(死了一个不就是单人了吗…))
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#include <windows.h>
#include <mmsystem.h>
#include<math.h>
#pragma comment(lib,"winmm.lib")
#pragma warning(disable :4996)
// 分数 暂停 手雷 游戏退出
int score = 0, P = 1, grenade = 0, gg = 0,NO=0;
//图片指针
//bk->背景 img_play->玩家(掩码图,原图)利用颜色的二进制操作去掉白边
IMAGE bk, img_play[2], img_bull[2], img_empty[2][2], use;
enum MyEnum
{
width = 591,
heighth = 864,
bullet_num = 15,//子弹数量
empty_num = 10,//敌机数量
Big,
Small
};
//飞机
struct play {
double x, y; //位置移动
bool alive; //判断是否存活
int usage1;//判断是否拾到道具一
//敌机数据
int width,
heighth,
hp, //敌机血量
type;//敌机类型
}Player,Player2,Bull[bullet_num], Empty[empty_num], Use, Bull1[bullet_num], Bull2[bullet_num],Bull3[bullet_num],Bull4[bullet_num],Bull5[bullet_num],Use2;
//敌机HP
void Createmptyhp(int i) {
if (rand() % 10 <= 1) {
Empty[i].type = Big;
Empty[i].hp = 3;
Empty[i].width = 104;
Empty[i].heighth = 148;
}
else {
Empty[i].type = Small;
Empty[i].hp = 1;
Empty[i].heighth = 39;
Empty[i].width = 52;
}
}
//开始界面和操作介绍
void Start() {
initgraph(591, 864);
putimage(0, 0, &bk);
setbkmode(TRANSPARENT);
char intro[100] = "";
char intro1[100] = "";
char intro2[100] = "";
char intro3[100] = "";
sprintf(intro, "玩法介绍");
sprintf(intro1, "W-A-S-D移动,空格射击,P暂停,E退出(暂停后),J手雷");
sprintf(intro3, "↑↓←→");
sprintf(intro2, "内置道具,一切随缘,回车继续");
outtextxy(260, 200, intro);
outtextxy(110, 280, intro1);
outtextxy(260, 360, intro3);
outtextxy(200, 440, intro2);
}
//初始化
void Gamestart() {
srand((int)time(NULL));//获取随机数种子
mciSendString("open ./images/game_music.mp3 alias BGM", 0, 0, 0);
mciSendString("play BGM repeat", 0, 0, 0);
Player.x = width / 2-200;
Player.y = heighth - 120;
Player.usage1 = 0;//玩家未获得道具1
Player.alive = true;
Player2.x = width / 2 + 100;
Player2.y = heighth - 120;
Player2.usage1 = 0;//玩家2未获得道具1
Player2.alive = true;
//初始化子弹
for (int i = 0; i < bullet_num; i++) {
Bull[i].alive = false;
Bull[i].x = 0;
Bull[i].y = 0;
Bull3[i].alive = 0;
Bull3[i].x = 0;
Bull3[i].y = 0;
}
//初始化敌机
for (int i = 0; i < empty_num; i++) {
Empty[i].alive = false;
Createmptyhp(i);
}
Use.alive = false;//道具1状态
Use2.alive = false;
}
//产生敌机
void Creatempty() {
for (int i = 0; i < empty_num; i++) {
if (!Empty[i].alive) {
Empty[i].alive = true;
Empty[i].y = 0;
Empty[i].x = rand() % (width - 60);
Createmptyhp(i);
break;
}
}
}
//加载图片
void load_image() {
//背景图
loadimage(&bk, "./images/background.jpg");
//飞机
loadimage(&img_play[0], "./images/planeNormal_1.jpg");
loadimage(&img_play[1], "./images/planeNormal_2.jpg");
//子弹
loadimage(&img_bull[0], "./images/bullet1.jpg");
loadimage(&img_bull[1], "./images/bullet2.jpg");
//小型敌机
loadimage(&img_empty[0][0], "./images/enemy_1.jpg");
loadimage(&img_empty[0][1], "./images/enemy_2.jpg");
//大型敌机
loadimage(&img_empty[1][0], "./images/enemyPlane1.jpg");
loadimage(&img_empty[1][1], "./images/enemyPlane2.jpg");
//道具
loadimage(&use, "./images/l.jpg");
}
//输出图片
void put_image() {
//把图片贴到窗口上
putimage(0, 0, &bk);
if (Player.alive) {
putimage(Player.x, Player.y, &img_play[0], NOTSRCERASE);//掩码图
putimage(Player.x, Player.y, &img_play[1], SRCINVERT);//源码图
}
//玩家2
if (Player2.alive) {
putimage(Player2.x, Player2.y, &img_play[0], NOTSRCERASE);//掩码图
putimage(Player2.x, Player2.y, &img_play[1], SRCINVERT);//源码图
}
//绘制子弹(普通模式)
if (Player.usage1 == 0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull[i].alive) {
putimage(Bull[i].x, Bull[i].y, &img_bull[0], NOTSRCERASE);
putimage(Bull[i].x, Bull[i].y, &img_bull[1], SRCINVERT);
}
}
}
else {
for (int i = 0; i < bullet_num; i++) {
if (Bull1[i].alive) {
putimage(Bull1[i].x, Bull1[i].y, &img_bull[0], NOTSRCERASE);
putimage(Bull1[i].x, Bull1[i].y, &img_bull[1], SRCINVERT);
}
if (Bull2[i].alive) {
putimage(Bull2[i].x, Bull2[i].y, &img_bull[0], NOTSRCERASE);
putimage(Bull2[i].x, Bull2[i].y, &img_bull[1], SRCINVERT);
}
}
}
//
if (Player2.usage1 == 0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull3[i].alive) {
putimage(Bull3[i].x, Bull3[i].y, &img_bull[0], NOTSRCERASE);
putimage(Bull3[i].x, Bull3[i].y, &img_bull[1], SRCINVERT);
}
}
}
else {
for (int i = 0; i < bullet_num; i++) {
if (Bull4[i].alive) {
putimage(Bull4[i].x, Bull4[i].y, &img_bull[0], NOTSRCERASE);
putimage(Bull4[i].x, Bull4[i].y, &img_bull[1], SRCINVERT);
}
if (Bull5[i].alive) {
putimage(Bull5[i].x, Bull5[i].y, &img_bull[0], NOTSRCERASE);
putimage(Bull5[i].x, Bull5[i].y, &img_bull[1], SRCINVERT);
}
}
}
//绘制敌机
for (int i = 0; i < empty_num; i++) {
if (Empty[i].alive) {
if (Empty[i].type == Big) {
putimage(Empty[i].x, Empty[i].y, &img_empty[1][0], NOTSRCERASE);
putimage(Empty[i].x, Empty[i].y, &img_empty[1][1], SRCINVERT);
}
else {
putimage(Empty[i].x, Empty[i].y, &img_empty[0][0], NOTSRCERASE);
putimage(Empty[i].x, Empty[i].y, &img_empty[0][1], SRCINVERT);
}
}
}
//绘制道具
if (Use.alive) {
putimage(Use.x, Use.y, &use);
}
if (Use2.alive) {
putimage(Use2.x, Use2.y, &use);
}
//打印分数
char scores[100] = "";
sprintf(scores, "当前分数:%d ", score);
outtextxy(0, 20, scores);
setbkmode(TRANSPARENT);
char tip[100] = "";
sprintf(tip, "已获得双弹道加成");
if (Player.usage1) {
outtextxy(0, 80, tip);
}
char a[100] = "";
sprintf(a, "玩家一");
char b[100] = "";
sprintf(b, "玩家二");
if (Player.alive) {
outtextxy(Player.x + 35, Player.y - 20, a);
}
if (Player2.alive) {
outtextxy(Player2.x + 35, Player2.y - 20, b);
}
char tip2[100] = "";
sprintf(tip2, "当前手雷数量: %d", grenade);
outtextxy(0, 50, tip2);
char tips[100] = "";
if (P % 2 == 0) {
sprintf(tips, "游戏已暂停");
outtextxy(260, 400, tips);
}
}
//敌机移动
void emptymove(double speed) {
for (int i = 0; i < empty_num; i++) {
if (Empty[i].alive) {
Empty[i].y += speed;
if (Empty[i].y >= heighth) {
Empty[i].alive = false;
}
}
}
}
//生成子弹
void Creatbullet1() {
//普通模式
if (Player.usage1 == 0) {
for (int i = 0; i < bullet_num; i++) {
if (!Bull[i].alive) {
Bull[i].alive = true;
Bull[i].x = Player.x + 43;
Bull[i].y = Player.y;
break;
}
}
}
//双弹模式
else {
for (int i = 0; i < bullet_num; i++) {
if (!Bull1[i].alive) {
Bull1[i].alive = true;
Bull1[i].x = Player.x + 37;
Bull1[i].y = Player.y;
break;
}
}
for (int i = 0; i < bullet_num; i++) {
if (!Bull2[i].alive) {
Bull2[i].alive = true;
Bull2[i].x = Player.x + 49;
Bull2[i].y = Player.y;
break;
}
}
}
}
void Creatbullet2() {
if (Player2.usage1 == 0) {
for (int i = 0; i < bullet_num; i++) {
if (!Bull3[i].alive) {
Bull3[i].alive = true;
Bull3[i].x = Player2.x + 43;
Bull3[i].y = Player2.y;
break;
}
}
}
//双弹模式
else {
for (int i = 0; i < bullet_num; i++) {
if (!Bull4[i].alive) {
Bull4[i].alive = true;
Bull4[i].x = Player2.x + 37;
Bull4[i].y = Player2.y;
break;
}
}
for (int i = 0; i < bullet_num; i++) {
if (!Bull5[i].alive) {
Bull5[i].alive = true;
Bull5[i].x = Player2.x + 49;
Bull5[i].y = Player2.y;
break;
}
}
}
}
//子弹移动
void bullet_move() {
//普通模式
if (Player.usage1 == 0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull[i].alive) {
Bull[i].y -= 1;
if (Bull[i].y <= 0) {
Bull[i].alive = false;
}
}
}
}
//双弹模式
else {
for (int i = 0; i < bullet_num; i++) {
if (Bull1[i].alive) {
Bull1[i].y -= 1;
if (Bull1[i].y <= 0) {
Bull1[i].alive = false;
}
}
}
for (int i = 0; i < bullet_num; i++) {
if (Bull2[i].alive) {
Bull2[i].y -= 1;
if (Bull2[i].y <= 0) {
Bull2[i].alive = false;
}
}
}
}
//
if (Player2.usage1 == 0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull3[i].alive) {
Bull3[i].y -= 1;
if (Bull3[i].y <= 0) {
Bull3[i].alive = false;
}
}
}
}
//双弹模式
else {
for (int i = 0; i < bullet_num; i++) {
if (Bull4[i].alive) {
Bull4[i].y -= 1;
if (Bull4[i].y <= 0) {
Bull4[i].alive = false;
}
}
}
for (int i = 0; i < bullet_num; i++) {
if (Bull5[i].alive) {
Bull5[i].y -= 1;
if (Bull5[i].y <= 0) {
Bull5[i].alive = false;
}
}
}
}
}
//飞机的移动
void Playermove(double speed) {
//不用_kihib()防止阻塞,导致移动的不顺畅
if (GetAsyncKeyState('W')) {
if (Player.y > 0)
Player.y -= speed;
}
if (GetAsyncKeyState('S')) {
if (Player.y + 120 < heighth)
Player.y += speed;
}
if (GetAsyncKeyState('A')) {
if (Player.x + 50 > 0)
Player.x -= speed;
}
if (GetAsyncKeyState('D')) {
if (Player.x + 60 < width)
Player.x += speed;
}
///
if (GetAsyncKeyState(VK_UP)) {
if (Player2.y > 0)
Player2.y -= speed;
}
if (GetAsyncKeyState(VK_DOWN)) {
if (Player2.y + 120 < heighth)
Player2.y += speed;
}
if (GetAsyncKeyState(VK_LEFT)) {
if (Player2.x + 50 > 0)
Player2.x -= speed;
}
if (GetAsyncKeyState(VK_RIGHT)) {
if (Player2.x + 60 < width)
Player2.x += speed;
}
//发射子弹
static DWORD t1 = 0, t2 = 0;
//间隔350ms执行
if (Player.alive) {
if (GetAsyncKeyState(VK_SPACE) && t2 - t1 > 350) {
mciSendString("close gun", 0, 0, 0);
mciSendString("open ./images/f_gun.mp3 alias gun", 0, 0, 0);
mciSendString("play gun", 0, 0, 0);
Creatbullet1();
t1 = t2;
}
t2 = clock();
}
//
if (Player2.alive) {
static int t5 = 0, t6 = 0;
//间隔350ms执
if (GetAsyncKeyState('L') && t6 - t5 > 350) {
mciSendString("close gun", 0, 0, 0);
mciSendString("open ./images/f_gun.mp3 alias gun", 0, 0, 0);
mciSendString("play gun", 0, 0, 0);
Creatbullet2();
t5 = t6;
}
t6 = clock();
}
//使用手雷
static DWORD t3 = 0, t4 = 0;
if (GetAsyncKeyState('J') && t4 - t3 > 350) {
if (grenade > 0) {
grenade--;
mciSendString("close w", 0, 0, 0);
mciSendString("open ./images/fire.mp3 alias w", 0, 0, 0);
mciSendString("play w", 0, 0, 0);
for (int i = 0; i < empty_num; i++) {
if (Empty[i].alive) {
Empty[i].hp--;
}
}
}
t3 = t4;
}
t4 = clock();
}
//射击飞机
void play() {
for (int i = 0; i < empty_num; i++) {
if (!Empty[i].alive)
continue;
for (int j = 0; j < bullet_num; j++) {
if (Player.usage1 == 0) {
if (!Bull[j].alive)
continue;
if (Bull[j].x > Empty[i].x - 10 && Bull[j].x<Empty[i].x + Empty[i].width && Bull[j].y>Empty[i].y && Bull[j].y < Empty[i].y + Empty[i].heighth) {
Bull[j].alive = false;
Empty[i].hp--;
}
}
else {
if (!Bull1[j].alive)
continue;
if (Bull1[j].x > Empty[i].x - 10 && Bull1[j].x<Empty[i].x + Empty[i].width && Bull1[j].y>Empty[i].y && Bull1[j].y < Empty[i].y + Empty[i].heighth) {
Bull1[j].alive = false;
Empty[i].hp--;
}
if (!Bull2[j].alive)
continue;
if (Bull2[j].x > Empty[i].x - 10 && Bull2[j].x<Empty[i].x + Empty[i].width && Bull2[j].y>Empty[i].y && Bull2[j].y < Empty[i].y + Empty[i].heighth) {
Bull2[j].alive = false;
Empty[i].hp--;
}
}
}
for (int j = 0; j < bullet_num; j++) {
if (Player2.usage1 == 0) {
if (!Bull3[j].alive)
continue;
if (Bull3[j].x > Empty[i].x - 10 && Bull3[j].x<Empty[i].x + Empty[i].width && Bull3[j].y>Empty[i].y && Bull3[j].y < Empty[i].y + Empty[i].heighth) {
Bull3[j].alive = false;
Empty[i].hp--;
}
}
else {
if (!Bull4[j].alive)
continue;
if (Bull4[j].x > Empty[i].x - 10 && Bull4[j].x<Empty[i].x + Empty[i].width && Bull4[j].y>Empty[i].y && Bull4[j].y < Empty[i].y + Empty[i].heighth) {
Bull4[j].alive = false;
Empty[i].hp--;
}
if (!Bull5[j].alive)
continue;
if (Bull5[j].x > Empty[i].x - 10 && Bull5[j].x<Empty[i].x + Empty[i].width && Bull5[j].y>Empty[i].y && Bull5[j].y < Empty[i].y + Empty[i].heighth) {
Bull5[j].alive = false;
Empty[i].hp--;
}
}
}
if (Empty[i].hp <= 0) {
if (Empty[i].type == Big)
score += 50;
else
score += 10;
//产生道具(双弹道)
if ((Player.usage1 == 0&&Player.alive==true)||(Player2.usage1==0&&Player2.alive==true)) {
if (rand() % 21 <= 1 && score >= 100) {
if (!Use.alive) {
Use.x = Empty[i].x;
Use.y = Empty[i].y;
Use.alive = true;
}
}
if (rand() % 21 <= 1 && score >= 100 && Use.alive==false) {
if (!Use2.alive) {
Use2.x = Empty[i].x;
Use2.y = Empty[i].y;
Use2.alive = true;
}
}
}
Empty[i].alive = false;
mciSendString("close YI", 0, 0, 0);
mciSendString("open ./images/explode.mp3 alias YI", 0, 0, 0);
mciSendString("play YI", 0, 0, 0);
//产生道具(手雷)
if (!Use.alive &&!Use2.alive) {
if (rand() % 13 <= 1) {
grenade++;
mciSendString("close E", 0, 0, 0);
mciSendString("open ./images/gotEnemy.mp3 alias E", 0, 0, 0);
mciSendString("play E", 0, 0, 0);
}
}
}
}
}
//双弹道
void Usage() {
if (Use.alive==true&&Player.usage1==0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull[i].x > Use.x - 50 && Bull[i].x<Use.x + 50 && Bull[i].y>Use.y && Bull[i].y < Use.y + 50&&Bull[i].alive==true) {
Bull[i].alive = false;
Player.usage1 = 1;
Use.alive = false;
mciSendString("close cc", 0, 0, 0);
mciSendString("open ./images/10.mp3 alias cc", 0, 0, 0);
mciSendString("play cc", 0, 0, 0);
}
}
}
if (Use.alive==true&&Player2.usage1==0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull3[i].x > Use.x - 50 && Bull3[i].x<Use.x + 50 && Bull3[i].y>Use.y && Bull3[i].y < Use.y + 50 &&Bull3[i].alive==true) {
Bull3[i].alive = false;
Player2.usage1 = 1;
Use.alive = false;
mciSendString("close cc", 0, 0, 0);
mciSendString("open ./images/10.mp3 alias cc", 0, 0, 0);
mciSendString("play cc", 0, 0, 0);
}
}
}
if (Use2.alive==true&&Player2.usage1==0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull3[i].x > Use2.x - 50 && Bull3[i].x<Use2.x + 50 && Bull3[i].y>Use2.y && Bull3[i].y < Use2.y + 50&&Bull3[i].alive==true) {
Bull3[i].alive = false;
Player2.usage1 = 1;
Use2.alive = false;
mciSendString("close cc", 0, 0, 0);
mciSendString("open ./images/10.mp3 alias cc", 0, 0, 0);
mciSendString("play cc", 0, 0, 0);
}
}
}
if (Use2.alive==true&&Player.usage1==0) {
for (int i = 0; i < bullet_num; i++) {
if (Bull[i].x > Use2.x - 50 && Bull[i].x<Use2.x + 50 && Bull[i].y>Use2.y && Bull[i].y < Use2.y + 50&&Bull[i].alive==true) {
Bull[i].alive = false;
Player.usage1 = 1;
Use2.alive = false;
mciSendString("close cc", 0, 0, 0);
mciSendString("open ./images/10.mp3 alias cc", 0, 0, 0);
mciSendString("play cc", 0, 0, 0);
}
}
}
}
//游戏结束
int Gameover1() {
for (int i = 0; i < empty_num; i++) {
if (!Empty[i].alive)
continue;
//if (Player.x +50> Empty[i].x && Player.x < Empty[i].x + Empty[i].width+50 && Player.y > Empty[i].y && Player.y < Empty[i].y + Empty[i].heighth) {
//return 1;
//}
if (((fabs(Player.x + 117 / 2 - Empty[i].x - Empty[i].width / 2) < (117 + Empty[i].width) / 2)) && ((fabs(Player.y + 60 - Empty[i].y - Empty[i].heighth / 2) < (120 + Empty[i].heighth) / 2))) {
return 1;
}
}
if (gg) {
return 1;
}
return 0;
}
int Gameover2() {
for (int i = 0; i < empty_num; i++) {
if (!Empty[i].alive)
continue;
//if (Player.x +50> Empty[i].x && Player.x < Empty[i].x + Empty[i].width+50 && Player.y > Empty[i].y && Player.y < Empty[i].y + Empty[i].heighth) {
//return 1;
//}
if (((fabs(Player2.x + 117 / 2 - Empty[i].x - Empty[i].width / 2) < (117 + Empty[i].width) / 2)) && ((fabs(Player2.y + 60 - Empty[i].y - Empty[i].heighth / 2) < (120 + Empty[i].heighth) / 2))) {
return 1;
}
}
if (gg) {
return 1;
}
return 0;
}
//结束界面
void the_end() {
initgraph(width, heighth);
putimage(0, 0, &bk);
char scores[100] = "";
char word[100] = "";
setbkmode(TRANSPARENT);
sprintf(word, "游戏结束");
outtextxy(260, 300, word);
sprintf(scores, "您的最终成绩:%d ", score);
outtextxy(230, 400, scores);
}
int main()
{
//窗口创建
load_image();
Start();
getchar();
initgraph(width, heighth);
Gamestart();
//双缓存绘图
BeginBatchDraw();//执行后,任何绘图操作都将暂时不输出到绘图窗口上,直到执行 FlushBatchDraw 或 EndBatchDraw 才将之前的绘图输出。
//getchar();
while (Player.alive||Player2.alive) {
if (Gameover1())
Player.alive = false;
if (Gameover2())
Player2.alive = false;
put_image();
FlushBatchDraw();
play();
static int t3 = 0, t4 = 0;//计时器
//无堵塞时,无法控制按P键的次数,于是使用计时器,达到一个堵塞作用
if (t4 - t3 > 200) {
if (GetAsyncKeyState('P'))
P++;
t3 = t4;
}
t4 = clock();
//游戏的退出(在暂停模式下)
if (P % 2 == 0) {
if (GetAsyncKeyState('E')) {
gg = 1;
}
}
if (P % 2 != 0) {
Playermove(1);
emptymove(0.3);
//间隔900ms让敌机挨个生成
static int t1 = 0, t2 = 0;//计时器
if (t2 - t1 > 900) {
Creatempty();
t1 = t2;
}
t2 = clock();
}
Usage();
bullet_move();
}
EndBatchDraw();
the_end();
getchar();
return 0;
}
项目下载链接
需要的话,可自行提取。之前完成项目时使用的vs2019,如果运行过程中缺少dll文件的,自行百度下载。
链接:https://pan.baidu.com/s/1Ww72D1EPmX15SAkAOzuIQQ
提取码:0q84