-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cpp
More file actions
131 lines (100 loc) · 2.26 KB
/
Enemy.cpp
File metadata and controls
131 lines (100 loc) · 2.26 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "Enemy.h"
#include "CommonFunction.h"
#include "Image.h"
#include "Player.h"
#include "MissileManager.h"
/*
STL (Standard Template Library) : Vector
동적배열을 제공하는 표준 템플릿 라이브러리 컨테이너
배열과 흡사하지만 크기가 자동으로 조절된다.
장점 : 임의 접근 : 인덱스를 사용해서 0(1) 시간 복잡도로 원소에 접근이 가능하다. (배열의 장점과 동일)
단점 : 중간에 원소를 삽입, 삭제할 때 비용(시간 복잡도 0(n))가 많이 든다.
vector를 써서 enemyManager 만들기
*/
void Enemy::Init(float posX, float posY)
{
pos = { posX, posY };
pos2 = { posX , posY };
dir = 1;
moveSpeed = 3;
missileSpeed = 10.0f;
angle = -90.0f;
isAlive = true;
size = 30;
animationFrame = 0;
elapsedFrame = 0;
e_timer = 0;
elapsedTime = 0.0f;
/*image = new Image();
image->Init(TEXT("Image/ufo.bmp"), 530, 32, 10, 1, true, RGB(255,0,255));*/
// < 해당 부분을 imageManager로 진행한다.
image = ImageManager::GetInstance()->AddImage("Normal_Enemy",
TEXT("Image/dragon.bmp"), 3555, 360, 9, 1, true, RGB(0, 0, 0));
e_missileManager = new MissileManager;
e_missileManager->Init();
}
void Enemy::Release()
{
if (e_missileManager)
{
delete e_missileManager;
e_missileManager = nullptr;
}
}
void Enemy::Update()
{
if (isAlive)
{
Move();
elapsedTime += TimeManager::GetInstance()->GetDeltaTime();
if (elapsedTime> 0.05f)
{
animationFrame++;
if (animationFrame >= image->GetMaxFrameX())
{
animationFrame = 0;
}
elapsedTime = 0;
}
e_missileManager->Update(); // 미사일을 이동시키는함수
e_timer++; // 미사일 발사 속도를 제한한다
if (e_timer > 50)
{
e_timer = 0;
e_missileManager->spawnMissile(pos,angle,missileSpeed); // 미사일 생성
}
}
}
void Enemy::MissileUpdate()
{
}
void Enemy::Render(HDC hdc)
{
if (isAlive)
{
RenderRectAtCenter(hdc, pos.x, pos.y, size, size);
image->FrameRender(hdc, pos.x, pos.y, animationFrame, 0);
e_missileManager->Render(hdc);
}
}
void Enemy::Move()
{
pos.x += moveSpeed * TimeManager::GetInstance()->GetDeltaTime() * dir;
float range = abs(pos2.x - pos.x);
if (range >100)
{
dir = dir * (-1);
}
//if (target)
//{
// angle = GetAngle(pos, target->GetPos());
// pos.x += cosf(angle) * moveSpeed;
// pos.y -= sinf(angle) * moveSpeed;
//}
}
Enemy::Enemy()
{
}
Enemy::~Enemy()
{
}