forked from DUCKSOO/ToonHeroes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.cpp
176 lines (140 loc) · 3.69 KB
/
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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#define _CRT_SECURE_NO_DEPRECATE
#include "Enemy.h"
#include "content.h"
#include "Core.h"
CEnemy::CEnemy()
{
}
CEnemy::~CEnemy()
{
}
bool CEnemy::init(int _tag)
{
if (!Sprite::init()) return false;
m_pEnemySprite = NULL;
//m_pEnemyHPImagefront = NULL;
//m_pEnemyHPImageback = NULL;
m_iState = WALK;
m_iPrevState = WALK;
//m_iDirection = 0;
//m_pos = 0, 0;
m_fMoveSpeed = 100.0f;
m_iTag = _tag;
m_iObjTag = ENEMY;
m_iHP = 0; // LiveFlag를 true로 바꿔줄 때 tag를 이용해서 해보자.
m_iFrame = 0;
m_fFrameDelay = 0.0f;
m_bLiveFlag = false;
isAttack = false;
if (m_iTag == ENEMY_ZOMBIE_FE)
{
m_pEnemySprite = Sprite::create("Zombie_Fe Idle 1.png");
m_pEnemySprite->setAnchorPoint(Point(0.f, 0.f));
}
if (m_iTag == ENEMY_ZOMBIE_MALE)
{
m_pEnemySprite = Sprite::create("Zombie_Male Idle 1.png");
m_pEnemySprite->setAnchorPoint(Point(0.f, 0.f));
}
m_pEnemySprite->setFlipX(true);
m_pEnemySprite->setPosition(Point(3000, 3000)); //화면 밖에 미리 만들어 놓기.
m_pEnemySprite->setScale(0.2f);
m_pEnemySprite->setAnchorPoint(Point(0, 0));
//m_pEnemyHPImagefront = Sprite::create("Hp_front.png");
//m_pEnemyHPImagefront->setAnchorPoint(Point(0, 0));
//m_pEnemyHPImagefront->setPosition(3000, 3000);
//m_pEnemyHPImageback = Sprite::create("Hp_back.png");
//m_pEnemyHPImageback->setAnchorPoint(Point(0, 0));
//m_pEnemyHPImageback->setPosition(3000, 3000);
this->addChild(m_pEnemySprite);
//this->addChild(m_pEnemyHPImagefront);
//this->addChild(m_pEnemyHPImageback);
return true;
}
void CEnemy::action(float _dt)
{
Point pos = m_pEnemySprite->getPosition();
m_iState = WALK;
m_pTargetTower = Core::sharedManager()->TM.CollisionCheckAboutTower_Enemy(this);
if (m_iState == WALK)
{
pos.x -= m_fMoveSpeed * _dt;
}
animation(_dt);
m_pEnemySprite->setPosition(pos);
}
void CEnemy::animation(float _dt)
{
if (m_iPrevState != m_iState)
{
m_iPrevState = m_iState;
m_iFrame = 0;
m_fFrameDelay = 0.0f;
isAttack = false;
}
char szString[128] = { 0 };
switch (m_iState)
{
case WALK:
{
/*auto animation = Animation::create();
animation->setDelayPerUnit(m_fFrameDelay);
*/
if (m_iTag == ENEMY_ZOMBIE_FE)
sprintf_s(szString, "%s%d.png", "Zombie_Fe Walk ", m_iFrame);
else if (m_iTag == ENEMY_ZOMBIE_MALE)
sprintf_s(szString, "%s%d.png", "Zombie_Male Walk ", m_iFrame);
m_pEnemySprite->initWithFile(szString);
m_pEnemySprite->setFlipX(true);
m_fFrameDelay += _dt;
if (m_fFrameDelay > 0.1f)
{
m_fFrameDelay = 0.f;
m_iFrame++;
}
if (m_iTag == ENEMY_ZOMBIE_FE || m_iTag == ENEMY_ZOMBIE_MALE)
{
if (m_iFrame > 9)
m_iFrame = 0;
}
}
break;
case ATTACK:
{
if (m_iTag == ENEMY_ZOMBIE_FE)
sprintf_s(szString, "%s%d.png", "Zombie_Fe Attack ", m_iFrame);
else if (m_iTag == ENEMY_ZOMBIE_MALE)
sprintf_s(szString, "%s%d.png", "Zombie_Male Attack ", m_iFrame);
m_pEnemySprite->initWithFile(szString);
m_fFrameDelay += _dt;
m_pEnemySprite->setFlipX(true);
if (m_fFrameDelay > 0.1f)
{
m_fFrameDelay = 0.f;
m_iFrame++;
}
if (m_iFrame == 6 && isAttack == false)
{
if (m_pTargetTower != NULL)
{
m_pTargetTower->m_iHp--;
Core::sharedManager()->IM->subTowerHp(ENEMY);
isAttack = true;
if (m_pTargetTower->m_iHp == 0)
{
m_pTargetTower->setLiveFlag(false);
Core::sharedManager()->TM.getPlayerTower()->m_pTowerImage->setPosition(Point(3000, 3000));
}
}
}
if (m_iFrame == 7)
isAttack = false;
if (m_iTag == ENEMY_ZOMBIE_FE || m_iTag == ENEMY_ZOMBIE_MALE)
{
if (m_iFrame > 9)
m_iFrame = 0;
}
}
break;
}
}