Commit 88f4b516 authored by CjhGm's avatar CjhGm
Browse files

update

parent cd457992
......@@ -238,8 +238,14 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
if (myplane != NULL && !isPause) {
// 敌机产生定时器触发
if (nIDEvent == 2) {
CEnemy* enemy = new CEnemy(rect.right, rect.bottom);
enemyList.AddTail(enemy); //随机产生敌机
// 随机产生普通敌机
CEnemy* enemy = new CEnemy(rect.right, rect.bottom, 1);
enemyList.AddTail(enemy);
}
if (nIDEvent == 5) {
// 随机产生高级敌机
CEnemy* enemy = new CEnemy(rect.right, rect.bottom, 2);
enemyList.AddTail(enemy);
}
}
......@@ -257,24 +263,24 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
}
else {
//没出界,绘制
enemy->Draw(&cdc, 1, FALSE);
enemy->Draw(&cdc, FALSE);
if (nIDEvent == 3) {
CBullet* bullet = new CBullet(enemy->GetPoint().x + ENEMY_WIDTH / 2 - BULLET_WIDTH / 2, enemy->GetPoint().y + ENEMY_HEIGHT, enemy->getDamage(), 0, -5, false);
bulletList.AddTail(bullet); //随机产生子弹
CBullet* bullet = new CBullet(enemy->GetPoint().x + ENEMY_WIDTH / 2 - BULLET_WIDTH / 2, enemy->GetPoint().y + ENEMY_HEIGHT, enemy->getDamage(), 0, -5, false, enemy->getIndex());
enemyBulletList.AddTail(bullet);
}
}
}
// 战机发射子弹,超出边界的子弹进行销毁
// 发射子弹,超出边界的子弹进行销毁
stPos = NULL, tPos = NULL;
stPos = bulletList.GetHeadPosition();
stPos = enemyBulletList.GetHeadPosition();
while (stPos != NULL) {
tPos = stPos;
CBullet* bullet = (CBullet*)bulletList.GetNext(stPos);
CBullet* bullet = (CBullet*)enemyBulletList.GetNext(stPos);
// 判断子弹是否出界
if (bullet->GetPoint().x < rect.left || bullet->GetPoint().x > rect.right
|| bullet->GetPoint().y < rect.top || bullet->GetPoint().y > rect.bottom) {
bulletList.RemoveAt(tPos);
enemyBulletList.RemoveAt(tPos);
delete bullet;
}
else {
......@@ -283,42 +289,87 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
}
}
stPos = NULL, tPos = NULL;
stPos = myBulletList.GetHeadPosition();
while (stPos != NULL) {
tPos = stPos;
CBullet* bullet = (CBullet*)myBulletList.GetNext(stPos);
// 判断子弹是否出界
if (bullet->GetPoint().x < rect.left || bullet->GetPoint().x > rect.right
|| bullet->GetPoint().y < rect.top || bullet->GetPoint().y > rect.bottom) {
myBulletList.RemoveAt(tPos);
delete bullet;
}
else {
// 没出界,绘制
bullet->Draw(&cdc, FALSE);
}
}
// 子弹打中
POSITION bulletPos = bulletList.GetHeadPosition(), tmpBulletPos = bulletPos;
// 战机子弹打中
POSITION bulletPos = myBulletList.GetHeadPosition(), tmpBulletPos = bulletPos;
while (bulletPos != NULL) {
tmpBulletPos = bulletPos;
CBullet* bullet = (CBullet*)bulletList.GetNext(bulletPos);
if (bullet->getFromMe()) {
POSITION enemyPos = enemyList.GetHeadPosition(), tmpEnemyPos = enemyPos;
while (enemyPos != NULL) {
tmpEnemyPos = enemyPos;
CEnemy* enemy = (CEnemy*)enemyList.GetNext(enemyPos);
CRect tmpRect;
if (tmpRect.IntersectRect(&(bullet->GetRect()), &(enemy->GetRect()))) {
// 战机子弹和敌机区域有重合,即战机子弹打中敌机
bulletList.RemoveAt(tmpBulletPos);
enemy->decreaseHp(bullet->getDamage());
delete bullet;
bullet = NULL;
if (!enemy->isAlive()) {
myScore += enemy->getScore();
enemyList.RemoveAt(tmpEnemyPos);
delete enemy;
enemy = NULL;
}
break;
CBullet* bullet = (CBullet*)myBulletList.GetNext(bulletPos);
ASSERT(bullet->getFromMe());
POSITION enemyPos = enemyList.GetHeadPosition(), tmpEnemyPos = enemyPos;
while (enemyPos != NULL) {
tmpEnemyPos = enemyPos;
CEnemy* enemy = (CEnemy*)enemyList.GetNext(enemyPos);
CRect tmpRect;
if (tmpRect.IntersectRect(&(bullet->GetRect()), &(enemy->GetRect()))) {
// 战机子弹和敌机区域有重合,即战机子弹打中敌机
myBulletList.RemoveAt(tmpBulletPos);
enemy->decreaseHp(bullet->getDamage());
delete bullet;
bullet = NULL;
if (!enemy->isAlive()) {
myScore += enemy->getScore();
enemyList.RemoveAt(tmpEnemyPos);
delete enemy;
enemy = NULL;
}
break;
}
}
else {
}
// 敌机子弹打中战机
bulletPos = enemyBulletList.GetHeadPosition(), tmpBulletPos = bulletPos;
while (bulletPos != NULL) {
tmpBulletPos = bulletPos;
CBullet* bullet = (CBullet*)enemyBulletList.GetNext(bulletPos);
ASSERT(!bullet->getFromMe());
CRect tmpRect;
if (tmpRect.IntersectRect(&(bullet->GetRect()), &(myplane->GetRect()))) {
// 敌机子弹和战机区域有重合,即敌机子弹打中战机
enemyBulletList.RemoveAt(tmpBulletPos);
myplane->decreaseHp(bullet->getDamage());
delete bullet;
bullet = NULL;
}
}
// 子弹打中子弹
bulletPos = myBulletList.GetHeadPosition(), tmpBulletPos = bulletPos;
while (bulletPos != NULL) {
tmpBulletPos = bulletPos;
CBullet* myBullet = (CBullet*)myBulletList.GetNext(bulletPos);
POSITION bulletPos1 = enemyBulletList.GetHeadPosition(), tmpBulletPos1 = bulletPos1;
while (bulletPos1 != NULL) {
tmpBulletPos1 = bulletPos1;
CBullet* enemyBullet = (CBullet*)enemyBulletList.GetNext(bulletPos1);
ASSERT(myBullet->getFromMe() != enemyBullet->getFromMe());
CRect tmpRect;
if (tmpRect.IntersectRect(&(bullet->GetRect()), &(myplane->GetRect()))) {
// 敌机子弹和战机区域有重合,即敌机子弹打中战机
bulletList.RemoveAt(tmpBulletPos);
myplane->decreaseHp(bullet->getDamage());
delete bullet;
bullet = NULL;
if (tmpRect.IntersectRect(&(myBullet->GetRect()), &(enemyBullet->GetRect()))) {
// 战机子弹和敌机子弹有重合,即战机子弹打中敌机子弹
myBulletList.RemoveAt(tmpBulletPos);
enemyBulletList.RemoveAt(tmpBulletPos1);
delete myBullet;
delete enemyBullet;
myBullet = enemyBullet = NULL;
break;
}
}
......@@ -342,8 +393,7 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
}
//游戏界面输出该游戏当前信息
if (myplane != NULL)
{
if (myplane != NULL) {
HFONT font;
font = CreateFont(20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 10, 0);
cdc.SelectObject(font);
......@@ -351,7 +401,6 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
cdc.SetTextColor(RGB(255, 0, 0));
//设置透明背景
cdc.SetBkMode(TRANSPARENT);
cdc.SelectObject(font);
cdc.SetTextColor(RGB(255, 0, 0));
cdc.TextOutW(rect.right - 12 * PLANE_HP - 60, 0, _T("血量:"));
......@@ -424,22 +473,22 @@ void CAircraftBattleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
CBullet* bullet1, * bullet2, * bullet3;
bullet1 = bullet2 = bullet3 = nullptr;
if (myScore < 100) {
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet1);
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
myBulletList.AddTail(bullet1);
}
else if (myScore < 300) {
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet1);
bulletList.AddTail(bullet2);
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
myBulletList.AddTail(bullet1);
myBulletList.AddTail(bullet2);
}
else {
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 - 10, myplane->GetPoint().y, myplane->getDamage(), 10, 30, true);
bullet3 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 10, myplane->GetPoint().y, myplane->getDamage(), -10, 30, true);
bulletList.AddTail(bullet1);
bulletList.AddTail(bullet2);
bulletList.AddTail(bullet3);
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 10, myplane->GetPoint().y, myplane->getDamage(), 10, 30, true, 2);
bullet3 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 10, myplane->GetPoint().y, myplane->getDamage(), -10, 30, true, 2);
myBulletList.AddTail(bullet1);
myBulletList.AddTail(bullet2);
myBulletList.AddTail(bullet3);
}
}
}
......@@ -482,22 +531,22 @@ void CAircraftBattleView::OnLButtonDown(UINT nFlags, CPoint point)
CBullet* bullet1, * bullet2, * bullet3;
bullet1 = bullet2 = bullet3 = nullptr;
if (myScore < 100) {
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet1);
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
myBulletList.AddTail(bullet1);
}
else if (myScore < 300) {
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true);
bulletList.AddTail(bullet1);
bulletList.AddTail(bullet2);
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 15, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
myBulletList.AddTail(bullet1);
myBulletList.AddTail(bullet2);
}
else {
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 - 10, myplane->GetPoint().y, myplane->getDamage(), 10, 30, true);
bullet3 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 10, myplane->GetPoint().y, myplane->getDamage(), -10, 30, true);
bulletList.AddTail(bullet1);
bulletList.AddTail(bullet2);
bulletList.AddTail(bullet3);
bullet1 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage(), 0, 30, true, 2);
bullet2 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 - 10, myplane->GetPoint().y, myplane->getDamage(), 10, 30, true, 2);
bullet3 = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2 + 10, myplane->GetPoint().y, myplane->getDamage(), -10, 30, true, 2);
myBulletList.AddTail(bullet1);
myBulletList.AddTail(bullet2);
myBulletList.AddTail(bullet3);
}
}
......@@ -532,15 +581,18 @@ void CAircraftBattleView::OnDestroy()
void CAircraftBattleView::Restart()
{
// TODO: 在此处添加游戏重新开始初始化参数
//战机重新加载
// 战机重新加载
myplane = new CMyPlane(FALSE);
//清空敌机链表
// 清空敌机链表
if (enemyList.GetCount() > 0)
enemyList.RemoveAll();
//清空战机子弹链表
if (bulletList.GetCount() > 0)
bulletList.RemoveAll();
// 清空战机子弹链表
if (myBulletList.GetCount() > 0)
myBulletList.RemoveAll();
// 清空敌机子弹列表
if (enemyBulletList.GetCount() > 0)
enemyBulletList.RemoveAll();
//参数重新初始化
isPause = false;
......@@ -566,7 +618,6 @@ void CAircraftBattleView::gameOver(CDC* pDC, CDC& cdc, CBitmap* cacheBitmap)
KillTimer(1);
KillTimer(2);
KillTimer(3);
//KillTimer(4);
KillTimer(5);
//播放游戏结束音乐
PlaySound((LPCTSTR)IDR_WAV_GAMEOVER, AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);
......@@ -583,21 +634,8 @@ void CAircraftBattleView::gameOver(CDC* pDC, CDC& cdc, CBitmap* cacheBitmap)
//设置计时器
void CAircraftBattleView::SetMyTimer()
{
SetTimer(1, 17, NULL);//刷新界面定时器
SetTimer(2, 400 - 1 * 30, NULL);//产生敌机定时器
SetTimer(3, 2000 - 2 * 100, NULL);//产生敌机炮弹频率
SetTimer(5, 2000, NULL);//控制魔法值变化频率
SetTimer(1, 17, NULL); //刷新界面定时器
SetTimer(2, 600, NULL); //产生敌机定时器
SetTimer(3, 2000, NULL); //产生敌机子弹定时器
SetTimer(5, 1200, NULL); //产生高级敌机定时器
}
//void CAircraftBattleView::OnClose()
//{
// isPause = TRUE;
// // TODO: 在此添加消息处理程序代码和/或调用默认值
// KillTimer(1);
// KillTimer(2);
// KillTimer(3);
// KillTimer(4);
// KillTimer(5 );
// CView::OnClose();
//}
......@@ -30,18 +30,19 @@ protected: //
CAircraftBattleView();
DECLARE_DYNCREATE(CAircraftBattleView)
// 特性
// 特性
public:
CAircraftBattleDoc* GetDocument() const;
CScene scene;//场景
//创建各游戏对象
CMyPlane *myplane;
CMyPlane* myplane;
//创建存储游戏对象的对象链表
CObList enemyList;
CObList bulletList;
CObList myBulletList;
CObList enemyBulletList;
CRect rect;//窗口屏幕矩形
......@@ -53,14 +54,14 @@ public:
CImageList startIMG;
// 操作
// 操作
public:
//游戏暂停
void Pause();
//游戏重新开始
void Restart();
// 重写
// 重写
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
......@@ -69,7 +70,7 @@ protected:
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
// 实现
// 实现
public:
virtual ~CAircraftBattleView();
#ifdef _DEBUG
......@@ -79,7 +80,7 @@ public:
protected:
// 生成的消息映射函数
// 生成的消息映射函数
protected:
afx_msg void OnFilePrintPreview();
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
......@@ -92,15 +93,14 @@ public:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnDestroy();
// 生命值归零,游戏结束
void gameOver(CDC* pDC, CDC& cdc, CBitmap* cacheBitmap);
//设置计时器
void gameOver(CDC* pDC, CDC& cdc, CBitmap* cacheBitmap);
void SetMyTimer();
//afx_msg void OnClose();
};
#ifndef _DEBUG // AircraftBattleView.cpp 中的调试版本
inline CAircraftBattleDoc* CAircraftBattleView::GetDocument() const
{ return reinterpret_cast<CAircraftBattleDoc*>(m_pDocument); }
{
return reinterpret_cast<CAircraftBattleDoc*>(m_pDocument);
}
#endif
......@@ -2,15 +2,17 @@
#include "CBullet.h"
#include "resource.h"
CImageList CBullet::bulletImages; // 子弹图像
CImageList CBullet::myBulletImages; // 战机子弹图像
CImageList CBullet::enemyBulletImages; // 敌机子弹图像
CBullet::CBullet(int x, int y, int _damage, int _speedX, int _speedY, bool _fromMe) {
CBullet::CBullet(int x, int y, int _damage, int _speedX, int _speedY, bool _fromMe, int _index) {
mPoint.x = x;
mPoint.y = y;
speedX = _speedX;
speedY = _speedY;
damage = _damage;
fromMe = _fromMe;
index = _index;
}
bool CBullet::getFromMe() const {
......@@ -38,8 +40,12 @@ BOOL CBullet::Draw(CDC* pDC, BOOL bPause) {
if (bPause == 0) {
mPoint.y -= speedY;
mPoint.x -= speedX;
//int index = rand() % 15;
return bulletImages.Draw(pDC, 2, mPoint, ILD_TRANSPARENT);
if (fromMe) {
return myBulletImages.Draw(pDC, index, mPoint, ILD_TRANSPARENT);
}
else {
return enemyBulletImages.Draw(pDC, index, mPoint, ILD_TRANSPARENT);
}
}
else {
return FALSE;
......@@ -48,6 +54,7 @@ BOOL CBullet::Draw(CDC* pDC, BOOL bPause) {
//加载敌机图像
BOOL CBullet::LoadImage() {
CGameObject::LoadImage(bulletImages, IDB_BMP_BOMB1, RGB(0, 0, 0), BULLET_WIDTH, BULLET_WIDTH, 15);
CGameObject::LoadImage(myBulletImages, IDB_BMP_BOMB1, RGB(0, 0, 0), BULLET_WIDTH, BULLET_WIDTH, 15);
CGameObject::LoadImage(enemyBulletImages, IDB_BMP_BALLDOWN, RGB(0, 0, 0), 15, 40, 5);
return TRUE;
}
......@@ -12,12 +12,14 @@ private:
int speedX;
int speedY;
int damage;
int index;
protected:
static CImageList bulletImages; // 子弹图像
static CImageList myBulletImages; // 战机子弹图像
static CImageList enemyBulletImages; // 敌机子弹图像
public:
CBullet(int x, int y, int _damage, int _speed, int _speedY, bool _fromMe);
CBullet(int x, int y, int _damage, int _speed, int _speedY, bool _fromMe, int _index);
int getSpeedX() const;
int getSpeedY() const;
int getDamage() const;
......
......@@ -5,35 +5,48 @@
//̬ͼб
CImageList CEnemy::enemyImages;
CEnemy::CEnemy(int window_width, int window_height) : CPlane(ENEMY_HP, ENEMY_DAMAGE, ENEMY_SPEED) {
CEnemy::CEnemy(int window_width, int window_height, int _idx) {
mPoint.x = rand() % window_width;
mPoint.y = 0;
score = ENEMY_SCORE;
index = _idx;
if (index == 1) {
hp = ENEMY_HP;
damage = ENEMY_DAMAGE;
speedX = rand() % 3;
if (rand() % 2 == 0) {
speedX = -speedX;
}
speedY = ENEMY_SPEED;
score = ENEMY_SCORE;
}
else if (index == 2) {
hp = ENEMY_HP + 1;
damage = ENEMY_DAMAGE + 1;
speedX = rand() % 3;
if (rand() % 2 == 0) {
speedX = -speedX;
}
speedY = ENEMY_SPEED;
score = ENEMY_SCORE + 10;
}
else {
ASSERT(0);
}
}
int CEnemy::getScore() const {
return score;
}
//绘制当前敌机位置
BOOL CEnemy::Draw(CDC* pDC, int passNum, BOOL bPause) {
if (bPause == 0) {
int index = passNum % 5;
//敌机位置随机变化,只改变纵坐标,随机数为了让敌机不匀速飞行
//+ rand() % 10
mPoint.y += speed;
enemyImages.Draw(pDC, index, mPoint, ILD_TRANSPARENT);
return TRUE;
}
else return FALSE;
int CEnemy::getIndex() const {
return index;
}
BOOL CEnemy::Draw(CDC* pDC, BOOL bPause) {
if (bPause == 0) {
//敌机位置随机变化,只改变纵坐标,随机数为了让敌机不匀速飞行
//+ rand() % 10
mPoint.y += speed;
enemyImages.Draw(pDC, 0, mPoint, ILD_TRANSPARENT);
mPoint.x += speedX;
mPoint.y += speedY;
enemyImages.Draw(pDC, index, mPoint, ILD_TRANSPARENT);
return TRUE;
}
else return FALSE;
......@@ -41,14 +54,11 @@ BOOL CEnemy::Draw(CDC* pDC, BOOL bPause) {
//ͼ
BOOL CEnemy::LoadImage() {
//加载游戏对象的图标对象
CBitmap enemyBmp;
if (!enemyBmp.LoadBitmapW(IDB_BMP_ENEMYDOWN))
return FALSE;
//创建CImageList对象
if (!enemyImages.Create(ENEMY_WIDTH, ENEMY_HEIGHT, ILC_COLOR24 | ILC_MASK, 5, 0))//nInitial初始个数
return FALSE;//cx,cy 图片的宽度
//图像链表中加入对象对应的图标对象,之后直接通过该链表访问图标对象
if (!enemyImages.Create(ENEMY_WIDTH, ENEMY_HEIGHT, ILC_COLOR24 | ILC_MASK, 5, 0))
return FALSE;
enemyImages.Add(&enemyBmp, RGB(0, 0, 0));
return TRUE;
......
......@@ -13,18 +13,20 @@ class CEnemy : public CPlane
{
private:
int score;
int index;
protected:
static CImageList enemyImages; //敌机图像
public:
CEnemy(int window_width, int window_heigh);
CEnemy(int window_width, int window_heigh, int _idx);
int getScore() const;
int getIndex() const;
CRect GetRect();
//绘制
BOOL Draw(CDC* pDC, BOOL bPause);
BOOL Draw(CDC* pDC, int passNum, BOOL bPause);
//BOOL Draw(CDC* pDC, int index, BOOL bPause);
//加载敌机图像
static BOOL LoadImage();
......
#include "stdafx.h"
#include "CPlane.h"
CPlane::CPlane(int _hp, int _damage, int _speed) : hp(_hp), damage(_damage), speed(_speed) {}
CPlane::CPlane() {}
CPlane::CPlane(int _hp, int _damage, int _speedX, int _speedY) : hp(_hp), damage(_damage), speedX(_speedX), speedY(_speedY) {}
int CPlane::getHp() const {
return hp;
......@@ -11,8 +14,12 @@ int CPlane::getDamage() const {
return damage;
}
int CPlane::getSpeed() const {
return speed;
int CPlane::getSpeedX() const {
return speedX;
}
int CPlane::getSpeedY() const {
return speedY;
}