-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreSystem.cpp
140 lines (118 loc) · 3.76 KB
/
ScoreSystem.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
#include "pch.h"
#include "ScoreSystem.h"
#include "EventManager.h"
#include "VisPredComponents.h"
ScoreSystem::ScoreSystem(std::shared_ptr<SceneManager> scenemanager) :System(scenemanager)
{
EventManager::GetInstance().Subscribe("OnEnemyKilled", CreateSubscriber(&ScoreSystem::OnEnemyKilled));
EventManager::GetInstance().Subscribe("OnHideScore", CreateSubscriber(&ScoreSystem::OnHideScore));
EventManager::GetInstance().Subscribe("OnScoreToMiddle", CreateSubscriber(&ScoreSystem::OnScoreToMiddle));
EventManager::GetInstance().Subscribe("OnEndingBestScore", CreateSubscriber(&ScoreSystem::OnEndingBestScore));
}
void ScoreSystem::OnEnemyKilled(std::any)
{
if (!m_Score.lock())
return;
auto scorecomp = m_Score.lock()->GetComponent<ScoreComponent>();
scorecomp->PlayerPoint++;
if (scorecomp->HasComponent<TextComponent>())
scorecomp->GetComponent<TextComponent>()->Text = scorecomp->Ment + std::to_wstring(scorecomp->PlayerPoint);
if (scorecomp->HasComponent<TextBounceComponent>())
scorecomp->GetComponent<TextBounceComponent>()->AddedBounce = true;
}
void ScoreSystem::OnHideScore(std::any)
{
if (!m_Score.lock())
return;
auto scorecomp = m_Score.lock()->GetComponent<ScoreComponent>();
if (scorecomp->HasComponent<TextComponent>())
scorecomp->GetComponent<TextComponent>()->Color.w=0 ;
}
void ScoreSystem::OnScoreToMiddle(std::any)
{
if (!m_Score.lock())
return;
auto scorecomp = m_Score.lock()->GetComponent<ScoreComponent>();
if (!scorecomp->HasComponent<TextComponent>())
return;
scorecomp->GetComponent<TextComponent>()->Text = scorecomp->EndMent + std::to_wstring(scorecomp->PlayerPoint);
auto text = scorecomp->GetComponent<TextComponent>();
text->PosXPercent = scorecomp->MiddlePose.x;
text->PosYPercent = scorecomp->MiddlePose.y;
text->Scale = scorecomp->MiddleScale;
text->Color = scorecomp->EndFontColor;
}
void ScoreSystem::OnEndingBestScore(std::any)
{
if (!m_BestScore.lock())
return;
if (!m_Score.lock())
return;
auto score = m_Score.lock()->GetComponent<ScoreComponent>();
auto best = m_BestScore.lock()->GetComponent<BestScoreComponent>();
if (best->Score < score->PlayerPoint)
{
best->Score = score->PlayerPoint;
GetSceneManager()->SerializePrefab(best->GetEntityID(),true);
auto text = best->GetComponent<TextComponent>();
text->Text = best->NewBestScoreMent + std::to_wstring(best->Score);
text->Color = best->NewColor;
}
else
{
auto text = best->GetComponent<TextComponent>();
text->Text = best->BestScoreMent + std::to_wstring(best->Score);
text->Color = best->BasicColor;
}
}
void ScoreSystem::Initialize()
{
COMPLOOP(ScoreComponent, comp)
{
if (m_Score.lock())
break;
Start(comp.GetEntityID());
}
COMPLOOP(BestScoreComponent, comp)
{
if (m_BestScore.lock())
break;
Start(comp.GetEntityID());
}
}
void ScoreSystem::Start(uint32_t gameObjectId)
{
if (GetSceneManager()->HasComponent<ScoreComponent>(gameObjectId))
{
if (!m_Score.lock())
{
auto entity = GetSceneManager()->GetEntity(gameObjectId);
if (entity->HasComponent<TextComponent>())
{
auto scorecomp = entity->GetComponent<ScoreComponent>();
entity->GetComponent<TextComponent>()->Color = scorecomp->FontColor;
scorecomp->GetComponent<TextComponent>()->Text = scorecomp->Ment + std::to_wstring(scorecomp->PlayerPoint);
m_Score = entity;
}
}
}
if (GetSceneManager()->HasComponent<BestScoreComponent>(gameObjectId))
{
if (!m_BestScore.lock())
{
auto entity = GetSceneManager()->GetEntity(gameObjectId);
if (entity->HasComponent<TextComponent>())
{
auto scorecomp = entity->GetComponent<BestScoreComponent>();
entity->GetComponent<TextComponent>()->Color = {0,0,0,0};
m_BestScore = entity;
}
}
}
}
void ScoreSystem::Finish(uint32_t gameObjectId)
{
}
void ScoreSystem::Finalize()
{
}