-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.cpp
43 lines (33 loc) · 881 Bytes
/
Enemy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "Enemy.h"
#include "RectangleUtil.h"
Enemy::Enemy(const BackBuffer * pBackBuffer, const Vec2 & aPosition)
:mSprite(new Sprite("data/enemy.bmp", "data/enemyMask.bmp"))
,mBackBuffer(pBackBuffer)
{
mSprite->mPosition = aPosition;
mSprite->setBackBuffer(pBackBuffer);
}
void Enemy::Update(float aTimeElapsed)
{
mSprite->update(aTimeElapsed);
}
void Enemy::Draw() const
{
mSprite->draw();
}
RECT Enemy::GetRectangle() const
{
return mSprite->GetRectangle();
}
bool Enemy::IsShot(const Bullet & aBullet)
{
RECT bulletRect = aBullet.GetRectangle();
RECT enemyRect = GetRectangle();
if (RectangleUtil::AreIntersecting(bulletRect, enemyRect))
return mSprite->AreMasksOverlapping(*aBullet.GetSpritePtr());
return false;
}
std::unique_ptr<EnemyBullet> Enemy::Shoot()
{
return std::make_unique<EnemyBullet>(mBackBuffer, mSprite->mPosition);
}