-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbullets.cpp
More file actions
80 lines (67 loc) · 1.85 KB
/
bullets.cpp
File metadata and controls
80 lines (67 loc) · 1.85 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "stdafx.h"
#include "bullets.h"
HRESULT bullets::init()
{
_range = WINSIZEX;
return S_OK;
}
void bullets::release()
{
}
void bullets::update()
{
move();
}
void bullets::render()
{
for (int i = 0; i < _vBullet.size(); i++)
{
D2DRENDERER->DrawRectangle(CAMERA->getRelativeRect(_vBullet[i].rc));
_vBullet[i].image->frameRender(CAMERA->getRelativeVector2(_vBullet[i].rc.getCenter()), _vBullet[i].currentFrameX, _vBullet[i].currentFrameY);
_vBullet[i].count++;
if (_vBullet[i].count % 5 == 0)
{
_vBullet[i].currentFrameX++;
if (_vBullet[i].currentFrameX >= _vBullet[i].image->getMaxFrameX())
{
_vBullet[i].currentFrameX = 0;
}
_vBullet[i].count = 0;
}
}
}
void bullets::fire(float x, float y, float angle, float speed)
{
tagBullet bullet;
ZeroMemory(&bullet, sizeof(tagBullet));
bullet.image = IMAGEMANAGER->addFrameImage("enemyBullet", L"images/enemy/meerkatBall.png", 4, 1);
bullet.speed = speed;
bullet.angle = angle;
bullet.position.x = bullet.firePosition.x = x;
bullet.position.y = bullet.firePosition.y = y;
bullet.count = 0;
bullet.currentFrameX = 0;
bullet.currentFrameY = 0;
bullet.rc.update(Vector2(bullet.position.x, bullet.position.y), Vector2(50, 50), pivot::CENTER);
bullet.rc.set(bullet.position, pivot::CENTER);
_vBullet.push_back(bullet);
}
void bullets::move()
{
for (_viBullet = _vBullet.begin(); _viBullet != _vBullet.end(); )
{
_viBullet->position.x += cosf(_viBullet->angle) * _viBullet->speed;
_viBullet->position.y += -sinf(_viBullet->angle) * _viBullet->speed;
_viBullet->rc.set(_viBullet->position, pivot::CENTER);
if (_range < getDistance(_viBullet->position.x, _viBullet->position.y,
_viBullet->firePosition.x, _viBullet->firePosition.y))
{
_viBullet = _vBullet.erase(_viBullet);
}
else ++_viBullet;
}
}
void bullets::remove(int num)
{
_vBullet.erase(_vBullet.begin() + num);
}