• 周五. 4 月 24th, 2026

物嫩软件资讯网

软件资讯来物嫩

射击小游戏c语言实验报告,C++实现简单射击小游戏

admin@wunen

4 月 23, 2025

使用c++制作简单的横板射击小游戏,供大家参考,具体内容如下

#include

#include

#include

class Bullet;

class Tank;

class E_Bullet;

class Boss;

bool dead = false;

bool wined = false;

struct pos//坐标类

{

int a;

int b;

};

class E_Bullet//敌人打出的子弹

{

public:

clock_t d;

int x;

int y;

bool on = false;

pos show()//画出新的位置

{

setfillcolor(RGB(255, 180, 20));

fillrectangle(x – 5, y – 5, x + 5, y + 5);

return pos{ x,y };

}

pos del()//覆盖原来的位置

{

setfillcolor(0);

setlinecolor(0);

fillrectangle(x – 5, y – 5, x + 5, y + 5);

rectangle(x – 5, y – 5, x + 5, y + 5);

return pos{ x,y };

}

pos move()//左移

{

x -= 3;

return pos{ x,y };

}

};

class Bullet//玩家打出的子弹,同上

{

public:

clock_t d;

int x;

int y;

bool on = false;

pos show()

{

setfillcolor(RGB(150, 180, 210));

fillrectangle(x – 5, y – 5, x + 5, y + 5);

return pos{ x,y };

}

pos del()

{

setfillcolor(0);

setlinecolor(0);

fillrectangle(x – 5, y – 5, x + 5, y + 5);

rectangle(x – 5, y – 5, x + 5, y + 5);

return pos{ x,y };

}

pos move()//右移

{

x += 3;

return pos{ x,y };

}

};

class Boss//敌人

{

public:

bool hurting = false;

clock_t d_hurt;

COLORREF clr = RGB(0, 130, 125);

int x;

int y;

int hp = 100;//生命

clock_t d;//判断举例上一次执行某一函数过了多久

clock_t att_d;

bool angle = false;//方向

pos show()

{

setfillcolor(clr);

fillrectangle(x – 20, y – 40, x + 20, y + 40);

return pos{ x,y };

}

pos del()

{

setfillcolor(0);

<

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注