Commit a9486dba authored by CjhGm's avatar CjhGm
Browse files

Add different bullet

parent 23d8f9b7
......@@ -402,7 +402,26 @@ void CAircraftBattleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
else if (!isOver) {
if (myplane != NULL && GetKeyState(VK_SPACE) < 0) {
// 按空格键发射子弹
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage());
CBullet* bullet1, *bullet2, *bullet3;
bullet1 = bullet2 = bullet3 = nullptr;
switch (myScore / 100) {
case 0: bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet1);
break;
case 1: bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 10, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 10, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet1);
bulletList.AddTail(bullet2);
break;
default:bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 5, myplane->GetPoint().y, myplane->getDamage(), 10, 30, true);
bullet3 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 5, myplane->GetPoint().y, myplane->getDamage(), -10, 30, true);
bulletList.AddTail(bullet1);
bulletList.AddTail(bullet2);
bulletList.AddTail(bullet3);
break;
}
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet);
}
}
......@@ -442,7 +461,7 @@ void CAircraftBattleView::OnLButtonDown(UINT nFlags, CPoint point)
}
else if (myplane != NULL) {
// 按鼠标左键发射子弹
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage());
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet);
}
......
......@@ -4,15 +4,21 @@
CImageList CBullet::bulletImages; // 子弹图像
CBullet::CBullet(int x, int y, int _damage, int _speed) {
CBullet::CBullet(int x, int y, int _damage, int _speedX, int _speedY, bool _fromMe) {
mPoint.x = x;
mPoint.y = y;
speed = _speed;
speedX = _speedX;
speedY = _speedY;
damage = _damage;
fromMe = _fromMe;
}
int CBullet::getSpeed() const {
return speed;
int CBullet::getSpeedX() const {
return speedX;
}
int CBullet::getSpeedY() const {
return speedY;
}
int CBullet::getDamage() const {
......@@ -26,7 +32,8 @@ CRect CBullet::GetRect() {
//绘制
BOOL CBullet::Draw(CDC* pDC, BOOL bPause) {
if (bPause == 0) {
mPoint.y -= speed;
mPoint.y -= speedY;
mPoint.x -= speedX;
//int index = rand() % 15;
return bulletImages.Draw(pDC, 2, mPoint, ILD_TRANSPARENT);
}
......
......@@ -8,15 +8,18 @@
class CBullet : public CGameObject
{
private:
int speed;
bool fromMe;
int speedX;
int speedY;
int damage;
protected:
static CImageList bulletImages; // 子弹图像
public:
CBullet(int x, int y, int _damage, int _speed = BULLET_SPEED);
int getSpeed() const;
CBullet(int x, int y, int _damage, int _speed, int _speedY, bool _fromMe);
int getSpeedX() const;
int getSpeedY() const;
int getDamage() const;
CRect GetRect();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment