forked from WenlinMao/SleepWalking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionBox.cpp
More file actions
70 lines (59 loc) · 2.2 KB
/
Copy pathCollisionBox.cpp
File metadata and controls
70 lines (59 loc) · 2.2 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
#include "Mode.hpp"
#include "EndMode.hpp"
#include "CollisionBox.hpp"
#include "AudioSystem.hpp"
void CollisionBox::UpdateBoxCoord()
{
box_coord[0] = pos.x - size.x * 0.5f;
box_coord[1] = pos.y - size.y * 0.5f;
box_coord[2] = pos.x + size.x * 0.5f;
box_coord[3] = pos.y + size.y * 0.5f;
}
void ThornCollisionBox::OnTriggerEnter(std::shared_ptr<CollisionBox> cb)
{
//std::cout << "Somebody hits the thorn" << std::endl;
PlayerStats::Instance().health -= 100.f;
}
void CollectableCollisionBox::OnTriggerEnter(std::shared_ptr<CollisionBox> cb)
{
//std::cout << "Somebody hits the collectable" << cb->name << std::endl;
if (cb->name == "player1") {
PlayerStats::Instance().player1Light += 1.0f;
AudioSystem::Instance().PlayShortAudio(AudioSourceList::Collect);
}
else if (cb->name == "player2") {
PlayerStats::Instance().player2Light += 1.0f;
AudioSystem::Instance().PlayShortAudio(AudioSourceList::Collect);
}
else {
std::cerr << "Non-player object is triggering collectables" << std::endl;
}
//PlayerStats::Instance().lightNum++;
if (owner != nullptr) {
owner->setLife(-1.f);
}
}
void SavePointCollisionBox::OnTriggerEnter(std::shared_ptr<CollisionBox> cb)
{
if (name.find("SavePoint6") != std::string::npos) {
Mode::set_current(std::make_shared< EndMode >());
}
if (owner->getLife() > 0) {
AudioSystem::Instance().PlayShortAudio(AudioSourceList::CheckPoint);
owner->setLife(-1.f);
}
if (PlayerStats::Instance().player1SavedPos.x != owner->getPos().x ||
PlayerStats::Instance().player1SavedPos.y != owner->getPos().y)
{
std::cout << "Save point hit: " << name << std::endl;
PlayerStats::Instance().player1SavedPos.x = owner->getPos().x;
PlayerStats::Instance().player1SavedPos.y = owner->getPos().y;
PlayerStats::Instance().player2SavedPos.x = owner->getPos().x - 5.0f;
PlayerStats::Instance().player2SavedPos.y = owner->getPos().y + 5.f;
PlayerStats::Instance().player1SavedLight = PlayerStats::Instance().player1Light;
PlayerStats::Instance().player2SavedLight = PlayerStats::Instance().player2Light;
}
//std::cout << "Save point hit: " << name << ", x: " << owner->getPos().x
// << ", y: " << owner->getPos().y
// << ", z: " << owner->getPos().z << std::endl;
}