#include <easyx.h>
#include <time.h>
#include <conio.h>
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);
setlinecolor(0);
rectangle(x - 20, y - 40, x + 20, y + 40);
fillrectangle(x - 20, y - 40, x + 20, y + 40);
return pos{ x, y };
}
void fire(E_Bullet& but) { // 攻击
but.on = true; // 放置一个子弹
but.x = x - 20;
but.y = y;
but.d = clock();
}
void move() { // 上上下下得移动
if (angle == true)
y -= 5;
if (angle == false)
y += 5;
if (y >= 440)
angle = true;
if (y <= 40)
angle = false;
}
void hurt() { // 受伤
hp -= 4;
d_hurt = clock();
setfillcolor(0);
setlinecolor(WHITE);
fillrectangle(160, 485, 560, 510); // 更新血条
rectangle(160, 485, 160 + hp * 4, 510);
setfillcolor(RGB(230, 0, 1));
setlinecolor(RGB(255, 255, 255));
fillrectangle(160, 485, 160 + hp * 4, 510);
rectangle(160, 485, 160 + hp * 4, 510);
hurting = true;
if (hp <= 0) // 死亡
wined = true;
}
};
class Tank { // 玩家类,同上
public:
bool hurting = false;
int hp = 100;
int x;
COLORREF clr = RGB(150, 180, 210);
int y;
clock_t d_hurt;