Commit ca62fce8 authored by CjhGm's avatar CjhGm
Browse files

Add bullet

parent 2d2b66b1
#include "stdafx.h"
#include "CBullet.h"
#include "resource.h"
CImageList CBullet::bulletImages; // 子弹图像
CBullet::CBullet(int x, int y, int _speed) {
mPoint.x = x;
mPoint.y = y;
speed = _speed;
}
int CBullet::getSpeed() const {
return speed;
}
CRect CBullet::GetRect() {
return CRect(mPoint, CPoint(mPoint.x + BULLET_WIDTH, mPoint.y + BULLET_HEIGHT));
}
//绘制
BOOL CBullet::Draw(CDC* pDC, BOOL bPause) {
if (bPause == 0) {
mPoint.y -= speed;
//int index = rand() % 15;
return bulletImages.Draw(pDC, 2, mPoint, ILD_TRANSPARENT);
}
else {
return FALSE;
}
}
//加载敌机图像
BOOL CBullet::LoadImage() {
CGameObject::LoadImage(bulletImages, IDB_BMP_BOMB1, RGB(0, 0, 0), BULLET_WIDTH, BULLET_WIDTH, 15);
return TRUE;
}
#pragma once
#include "GameObject.h"
//战机子弹高都为20
#define BULLET_HEIGHT 60
//战机子弹宽
#define BULLET_WIDTH 30
//子弹飞行速度
#define BULLET_SPEED 30
class CBullet : public CGameObject
{
private:
int speed;
protected:
static CImageList bulletImages; // 子弹图像
public:
CBullet(int x = 0, int y = 0, int _speed = BULLET_SPEED);
int getSpeed() const;
CRect GetRect();
//绘制
BOOL Draw(CDC* pDC, BOOL bPause);
//加载敌机图像
static BOOL LoadImage();
};
......@@ -77,5 +77,5 @@ BOOL CEnemy::LoadImage()
CRect CEnemy::GetRect()
{
return CRect(mPoint, CPoint(mPoint.x + ENEMY_HEIGHT, mPoint.y + ENEMY_HEIGHT));
return CRect(mPoint, CPoint(mPoint.x + ENEMY_WIDTH, mPoint.y + ENEMY_HEIGHT));
}
\ No newline at end of file
#pragma once
#include "GameObject.h"
class CEnemy : public CGameObject
{
private:
......
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