CEnemy.cpp 1.3 KB
Newer Older
CjhGm's avatar
CjhGm 已提交
1
2
3
4
5
6
7
#include "stdafx.h"
#include "CEnemy.h"
#include "resource.h"

//静态图像列表
CImageList CEnemy::enemyImages;

CjhGm's avatar
CjhGm 已提交
8
CEnemy::CEnemy(int window_width, int window_height) : CPlane(ENEMY_HP, ENEMY_DAMAGE, ENEMY_SPEED) {
CjhGm's avatar
CjhGm 已提交
9
10
11
12
13
	mPoint.x = rand() % window_width;
	mPoint.y = 0;
}

//绘制当前敌机位置
CjhGm's avatar
CjhGm 已提交
14
BOOL CEnemy::Draw(CDC* pDC, int passNum, BOOL bPause) {
CjhGm's avatar
CjhGm 已提交
15
16
17
18
19
20
21
22
23
24
25
	if (bPause == 0) {
		int index = passNum % 5;
		//敌机位置随机变化,只改变纵坐标,随机数为了让敌机不匀速飞行
		//+ rand() % 10
		mPoint.y += speed;
		enemyImages.Draw(pDC, index, mPoint, ILD_TRANSPARENT);
		return TRUE;
	}
	else return FALSE;
}

CjhGm's avatar
CjhGm 已提交
26
BOOL CEnemy::Draw(CDC* pDC, BOOL bPause) {
CjhGm's avatar
CjhGm 已提交
27
28
29
30
31
32
33
34
35
36
37
	if (bPause == 0) {
		//敌机位置随机变化,只改变纵坐标,随机数为了让敌机不匀速飞行
		//+ rand() % 10
		mPoint.y += speed;
		enemyImages.Draw(pDC, 0, mPoint, ILD_TRANSPARENT);
		return TRUE;
	}
	else return FALSE;
}

//加载图像
CjhGm's avatar
CjhGm 已提交
38
BOOL CEnemy::LoadImage() {
CjhGm's avatar
CjhGm 已提交
39
40
41
42
43
44
45
46
47
48
49
50
51
	//加载游戏对象的图标对象
	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 图片的宽度
	//图像链表中加入对象对应的图标对象,之后直接通过该链表访问图标对象
	enemyImages.Add(&enemyBmp, RGB(0, 0, 0));

	return TRUE;
}

CjhGm's avatar
CjhGm 已提交
52
CRect CEnemy::GetRect() {
CjhGm's avatar
CjhGm 已提交
53
	return CRect(mPoint, CPoint(mPoint.x + ENEMY_WIDTH, mPoint.y + ENEMY_HEIGHT));
CjhGm's avatar
CjhGm 已提交
54
}