forked from DUCKSOO/ToonHeroes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject_Alliance.cpp
150 lines (118 loc) · 3.16 KB
/
Object_Alliance.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
#include "Object_Alliance.h"
#include "Core.h"
bool Object_Alliance::init(int _tag)
{
if (!Sprite::init()) return false;
m_iState = WALK;
m_iPrevState = WALK;
m_fMoveSpeed = 100.0f;
m_pTargetTower = NULL;
m_iTag = _tag;
m_iObjTag = PLAYER;
m_iHP = 0; // LiveFlag를 true로 바꿔줄 때 tag를 이용해서 해보자.
m_iFrame = 0;
m_fFrameDelay = 0.0f;
m_bLiveFlag = false;
isAttack = false;
if (m_iTag == SWORD)
{
allianceSprite = Sprite::create("sword_walk_0.png");
allianceSprite->setScale(0.2f);
}
else if (m_iTag == M_NINJA)
{
allianceSprite = Sprite::create("m_ninja_walk_0.png");
allianceSprite->setScale(0.28f);
}
else if (m_iTag == F_NINJA)
{
allianceSprite = Sprite::create("f_ninja_walk_0.png");
allianceSprite->setScale(0.25f);
}
allianceSprite->setPosition(Point(3000, 3000)); //화면 밖에 미리 만들어 놓기.
allianceSprite->setAnchorPoint(Point(0, 0));
this->addChild(allianceSprite);
return true;
}
void Object_Alliance::action(float _dt)
{
Point pos = allianceSprite->getPosition();
m_iState = WALK;
m_pTargetTower = Core::sharedManager()->TM.CollisionCheckAboutTower(this);
if (m_iState == WALK)
{
pos.x += m_fMoveSpeed * _dt;
}
animation(_dt);
allianceSprite->setPosition(pos);
}
void Object_Alliance::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:
if (m_iTag == SWORD) //칼든 동료가 걸을 때 애니메이션
sprintf_s(szString, "%s%d.png", "sword_walk_", m_iFrame);
else if (m_iTag == M_NINJA)
sprintf_s(szString, "%s%d.png", "m_ninja_walk_", m_iFrame);
else if (m_iTag == F_NINJA)
sprintf_s(szString, "%s%d.png", "f_ninja_walk_", m_iFrame);
allianceSprite->initWithFile(szString);
m_fFrameDelay += _dt;
if (m_fFrameDelay > 0.1f)
{
m_fFrameDelay = 0.f;
m_iFrame++;
}
if (m_iTag == SWORD || m_iTag == M_NINJA || m_iTag == F_NINJA)
{
if (m_iFrame > 9)
m_iFrame = 0;
}
break;
case ATTACK:
if (m_iTag == SWORD)
sprintf_s(szString, "%s%d.png", "sword_attack_", m_iFrame);
else if (m_iTag == M_NINJA)
sprintf_s(szString, "%s%d.png", "m_ninja_attack_", m_iFrame);
else if (m_iTag == F_NINJA)
sprintf_s(szString, "%s%d.png", "f_ninja_attack_", m_iFrame);
allianceSprite->initWithFile(szString);
m_fFrameDelay += _dt;
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(PLAYER); // 인터페이스에서 체력을 깍자
isAttack = true;
if (m_pTargetTower->m_iHp == 0)
{
m_pTargetTower->setLiveFlag(false);
Core::sharedManager()->TM.getEnemyTower()->m_pTowerImage->setPosition(Point(3000, 3000)); // 라이브플래그가 False일 경우(죽었을 경우) 안보이는 위치로 사진을 보내버림.
}
}
}
if (m_iFrame == 7)
isAttack = false;
if (m_iTag == SWORD || m_iTag == M_NINJA || m_iTag == F_NINJA)
{
if (m_iFrame > 9)
m_iFrame = 0;
}
break;
}
}