Skip to content

Commit b242d67

Browse files
Владимир СеверовВладимир Северов
authored andcommitted
17.05.12 21:20 - Graphics updated and logic added
1 parent a7825d5 commit b242d67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+401
-102
lines changed

HW-2/Classes/AppDelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// #define USE_AUDIO_ENGINE 1
55
// #define USE_SIMPLE_AUDIO_ENGINE 1
6-
#define FULL_SCREEN_MODE 0
6+
#define FULL_SCREEN_MODE 1
77
#if (!FULL_SCREEN_MODE)
88
#define FRAME_SIZE_NAME resolutionSizeNo4
99
#endif
@@ -85,7 +85,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
8585
}
8686

8787
// turn on display FPS
88-
director->setDisplayStats(true);
88+
//director->setDisplayStats(true);
8989

9090
// set FPS. the default value is 1.0/60 if you don't call this
9191
director->setAnimationInterval(1.0f / 60);

HW-2/Classes/AttackerObject.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ void AttackerObject::Update(Game* const scene)
2525
{
2626
DynamicObject::Update(scene);
2727

28-
bool isAttackOther = false;
29-
3028
std::vector<std::shared_ptr<AttackerObject>> attackers;
3129
if (IsRightAlignment()) {
3230
attackers = scene->leftAttackers_;
@@ -35,10 +33,37 @@ void AttackerObject::Update(Game* const scene)
3533
attackers = scene->rightAttackers_;
3634
}
3735
for (std::shared_ptr<AttackerObject>& attacker : attackers) {
38-
float attackerBorderX = scene->getContentSize().width - (attacker->GetX() + attacker->GetW() + MARGIN_SIZE) - GetW();
36+
float attackerBorderX = scene->getContentSize().width - (attacker->GetX() + attacker->GetW()) - GetW();
3937
if (GetX() > attackerBorderX) {
4038
SetX(attackerBorderX);
4139
}
40+
}
41+
42+
float maxDistance = 0;
43+
if (IsRightAlignment()) {
44+
maxDistance = scene->getContentSize().width - (scene->leftCastle_->GetW() + 2 * MARGIN_SIZE + GetW());
45+
}
46+
else {
47+
maxDistance = scene->getContentSize().width - (scene->rightCastle_->GetW() + 2 * MARGIN_SIZE + GetW());
48+
}
49+
if (GetX() > maxDistance) {
50+
SetX(maxDistance);
51+
}
52+
}
53+
54+
void AttackAndDefend::AttackerObject::Attack(Game * const scene)
55+
{
56+
bool isAttackOther = false;
57+
58+
std::vector<std::shared_ptr<AttackerObject>> attackers;
59+
if (IsRightAlignment()) {
60+
attackers = scene->leftAttackers_;
61+
}
62+
else {
63+
attackers = scene->rightAttackers_;
64+
}
65+
for (std::shared_ptr<AttackerObject>& attacker : attackers) {
66+
float attackerBorderX = scene->getContentSize().width - (attacker->GetX() + attacker->GetW()) - GetW();
4267
if (GetX() == attackerBorderX) {
4368
attacker->Damage(GetPower());
4469
isAttackOther = true;
@@ -54,9 +79,6 @@ void AttackerObject::Update(Game* const scene)
5479
else {
5580
maxDistance = scene->getContentSize().width - (scene->rightCastle_->GetW() + 2 * MARGIN_SIZE + GetW());
5681
}
57-
if (GetX() > maxDistance) {
58-
SetX(maxDistance);
59-
}
6082
if (GetX() == maxDistance) {
6183
if (IsRightAlignment()) {
6284
scene->leftCastle_->Damage(GetPower());
@@ -84,26 +106,31 @@ void AttackerObject::SetHealth(float health)
84106
label_->setString(buf);
85107
}
86108

87-
float AttackerObject::GetHealth()
109+
float AttackerObject::GetHealth() const
88110
{
89111
return health_;
90112
}
91113

92-
float AttackerObject::GetMaxHealth()
114+
float AttackerObject::GetMaxHealth() const
93115
{
94116
return maxHealth_;
95117
}
96118

97-
float AttackerObject::GetPower()
119+
float AttackerObject::GetPower() const
98120
{
99121
return power_;
100122
}
101123

102-
cocos2d::CCLabelTTF * AttackAndDefend::AttackerObject::GetLabel()
124+
cocos2d::CCLabelTTF * AttackAndDefend::AttackerObject::GetLabel() const
103125
{
104126
return label_;
105127
}
106128

129+
size_t AttackAndDefend::AttackerObject::GetCost() const
130+
{
131+
return 0;
132+
}
133+
107134
void AttackAndDefend::AttackerObject::onPositionUpdate_()
108135
{
109136
GameObject::onPositionUpdate_();

HW-2/Classes/AttackerObject.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ namespace AttackAndDefend {
1515
virtual ~AttackerObject() = default;
1616

1717
virtual void Update(Game* const scene) override;
18+
void Attack(Game* const scene);
1819

1920
void Damage(float power);
2021

2122
void SetHealth(float health);
2223

23-
float GetHealth();
24-
float GetMaxHealth();
25-
float GetPower();
26-
cocos2d::CCLabelTTF * GetLabel();
24+
float GetHealth() const;
25+
float GetMaxHealth() const;
26+
float GetPower() const;
27+
cocos2d::CCLabelTTF * GetLabel() const;
28+
29+
virtual size_t GetCost() const;
2730

2831
protected:
2932
float health_;

HW-2/Classes/CastleObject.cpp

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ using namespace AttackAndDefend;
66
CastleObject::CastleObject()
77
: StaticObject()
88
, maxHealth_(0.f)
9-
, armor_(0.f)
109
, maxArmor_(0.f)
1110
{
12-
InitLabel_();
11+
InitLabels_();
1312
SetHealth(maxHealth_);
13+
SetArmor(0.f);
1414
}
1515

1616
CastleObject::CastleObject(float maxHealth, std::string const& fileName)
1717
: StaticObject(MARGIN_SIZE, GROUND_HEIGHT, fileName)
1818
, maxHealth_(maxHealth)
19-
, armor_(0.f)
2019
, maxArmor_(2.f * maxHealth)
2120
{
22-
InitLabel_();
21+
InitLabels_();
2322
SetHealth(maxHealth_);
23+
SetArmor(0.f);
2424
}
2525

2626
void CastleObject::Update(Game* const scene)
@@ -47,59 +47,77 @@ void CastleObject::SetHealth(float health)
4747
health_ = health;
4848
char buf[10];
4949
_itoa_s(int(health_), buf, 10);
50-
label_->setString(buf);
50+
healthLabel_->setString(buf);
5151
}
5252

5353
void CastleObject::SetArmor(float armor)
5454
{
5555
armor_ = armor;
56+
char buf[10];
57+
_itoa_s(int(armor_), buf, 10);
58+
armorLabel_->setString(buf);
5659
}
5760

58-
float CastleObject::GetHealth()
61+
float CastleObject::GetHealth() const
5962
{
6063
return health_;
6164
}
6265

63-
float CastleObject::GetMaxHealth()
66+
float CastleObject::GetMaxHealth() const
6467
{
6568
return maxHealth_;
6669
}
6770

68-
float CastleObject::GetArmor()
71+
float CastleObject::GetArmor() const
6972
{
7073
return armor_;
7174
}
7275

73-
float CastleObject::GetMaxArmor()
76+
float CastleObject::GetMaxArmor() const
7477
{
7578
return maxArmor_;
7679
}
7780

78-
cocos2d::CCLabelTTF * AttackAndDefend::CastleObject::GetLabel()
81+
cocos2d::CCLabelTTF * AttackAndDefend::CastleObject::GetHealthLabel() const
82+
{
83+
return healthLabel_;
84+
}
85+
86+
cocos2d::CCLabelTTF * AttackAndDefend::CastleObject::GetArmorLabel() const
87+
{
88+
return armorLabel_;
89+
}
90+
91+
size_t AttackAndDefend::CastleObject::GetCost() const
7992
{
80-
return label_;
93+
return 0;
8194
}
8295

8396
void AttackAndDefend::CastleObject::onPositionUpdate_()
8497
{
8598
GameObject::onPositionUpdate_();
86-
UpdateLabelPosition();
99+
UpdateLabelsPosition();
87100
}
88101

89-
void AttackAndDefend::CastleObject::InitLabel_()
102+
void AttackAndDefend::CastleObject::InitLabels_()
90103
{
91-
label_ = cocos2d::CCLabelTTF::create("", "Helvetica", 30, cocos2d::Size(GetW(), 60));
92-
UpdateLabelPosition();
104+
healthLabel_ = cocos2d::CCLabelTTF::create("", "Helvetica", 30, cocos2d::Size(GetW(), 30));
105+
armorLabel_ = cocos2d::CCLabelTTF::create("", "Helvetica", 30, cocos2d::Size(GetW(), 30));
106+
UpdateLabelsPosition();
93107
}
94108

95-
void AttackAndDefend::CastleObject::UpdateLabelPosition()
109+
void AttackAndDefend::CastleObject::UpdateLabelsPosition()
96110
{
97111
if (isRightAlignment_) {
98-
label_->setPosition(frameWidth_ - MARGIN_SIZE, GROUND_HEIGHT + GetH() + MARGIN_SIZE);
99-
label_->setAnchorPoint(cocos2d::Vec2(1, 0));
112+
healthLabel_->setPosition(frameWidth_ - MARGIN_SIZE, GROUND_HEIGHT + GetH() + MARGIN_SIZE);
113+
healthLabel_->setAnchorPoint(cocos2d::Vec2(1, 0));
114+
armorLabel_->setPosition(frameWidth_ - MARGIN_SIZE, GROUND_HEIGHT + GetH() + MARGIN_SIZE + 40);
115+
armorLabel_->setAnchorPoint(cocos2d::Vec2(1, 0));
100116
}
101117
else {
102-
label_->setPosition(MARGIN_SIZE, GROUND_HEIGHT + GetH() + MARGIN_SIZE);
103-
label_->setAnchorPoint(cocos2d::Vec2(0, 0));
118+
healthLabel_->setPosition(MARGIN_SIZE, GROUND_HEIGHT + GetH() + MARGIN_SIZE);
119+
healthLabel_->setAnchorPoint(cocos2d::Vec2(0, 0));
120+
armorLabel_->setPosition(MARGIN_SIZE, GROUND_HEIGHT + GetH() + MARGIN_SIZE + 40);
121+
armorLabel_->setAnchorPoint(cocos2d::Vec2(0, 0));
104122
}
105123
}

HW-2/Classes/CastleObject.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,27 @@ namespace AttackAndDefend {
2121
void SetHealth(float health);
2222
void SetArmor(float armor);
2323

24-
float GetHealth();
25-
float GetMaxHealth();
26-
float GetArmor();
27-
float GetMaxArmor();
28-
cocos2d::CCLabelTTF * GetLabel();
24+
float GetHealth() const;
25+
float GetMaxHealth() const;
26+
float GetArmor() const;
27+
float GetMaxArmor() const;
28+
cocos2d::CCLabelTTF * GetHealthLabel() const;
29+
cocos2d::CCLabelTTF * GetArmorLabel() const;
30+
31+
virtual size_t GetCost() const;
2932

3033
protected:
3134
float health_;
3235
float maxHealth_;
3336
float armor_;
3437
float maxArmor_;
35-
cocos2d::CCLabelTTF * label_;
38+
cocos2d::CCLabelTTF * healthLabel_;
39+
cocos2d::CCLabelTTF * armorLabel_;
3640

3741
virtual void onPositionUpdate_() override;
3842

39-
void InitLabel_();
40-
void UpdateLabelPosition();
43+
void InitLabels_();
44+
void UpdateLabelsPosition();
4145
};
4246

4347
}

HW-2/Classes/DynamicObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ void DynamicObject::Update(Game* const scene)
2727
SetX(GetX() + hSpeed_);
2828
}
2929

30-
float DynamicObject::GetHSpeed()
30+
float DynamicObject::GetHSpeed() const
3131
{
3232
return hSpeed_;
3333
}
3434

35-
float DynamicObject::GetVSpeed()
35+
float DynamicObject::GetVSpeed() const
3636
{
3737
return vSpeed_;
3838
}

HW-2/Classes/DynamicObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace AttackAndDefend {
1717

1818
virtual void Update(Game* const scene) override;
1919

20-
float GetHSpeed();
21-
float GetVSpeed();
20+
float GetHSpeed() const;
21+
float GetVSpeed() const;
2222

2323
void SetHSpeed(float speed);
2424
void SetVSpeed(float speed);

HW-2/Classes/GameObject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,32 @@ GameObject::GameObject(float x, float y, std::string const& fileName)
3636
void GameObject::Update(Game* const scene)
3737
{}
3838

39-
cocos2d::Sprite * GameObject::GetSprite()
39+
cocos2d::Sprite * GameObject::GetSprite() const
4040
{
4141
return sprite_;
4242
}
4343

44-
float GameObject::GetX()
44+
float GameObject::GetX() const
4545
{
4646
return x_;
4747
}
4848

49-
float GameObject::GetY()
49+
float GameObject::GetY() const
5050
{
5151
return y_;
5252
}
5353

54-
float GameObject::GetW()
54+
float GameObject::GetW() const
5555
{
5656
return w_;
5757
}
5858

59-
float GameObject::GetH()
59+
float GameObject::GetH() const
6060
{
6161
return h_;
6262
}
6363

64-
bool GameObject::IsRightAlignment()
64+
bool GameObject::IsRightAlignment() const
6565
{
6666
return isRightAlignment_;
6767
}

HW-2/Classes/GameObject.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Game;
99
namespace AttackAndDefend {
1010

1111
const float MARGIN_SIZE = 20.f;
12-
const float GROUND_HEIGHT = 192.f;
12+
const float GROUND_HEIGHT = 80.f;
1313

1414
class GameObject abstract
1515
{
@@ -22,12 +22,12 @@ namespace AttackAndDefend {
2222

2323
virtual void Update(Game* const scene);
2424

25-
cocos2d::Sprite* GetSprite();
26-
float GetX();
27-
float GetY();
28-
float GetW();
29-
float GetH();
30-
bool IsRightAlignment();
25+
cocos2d::Sprite* GetSprite() const;
26+
float GetX() const;
27+
float GetY() const;
28+
float GetW() const;
29+
float GetH() const;
30+
bool IsRightAlignment() const;
3131

3232
void SetSprite(cocos2d::Sprite* pointer);
3333
void SetX(float x);

0 commit comments

Comments
 (0)