-
Notifications
You must be signed in to change notification settings - Fork 0
/
Donut.cpp
51 lines (41 loc) · 1.23 KB
/
Donut.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
#include "Donut.hpp"
#include <iostream>
using namespace std;
Donut::Donut(GameObject* gameObject)
{
this->gameObject = gameObject;
renderer = Renderer::getInstance();
physics = Physics::getInstance();
sceneMan = SceneManager::getInstance();
// create detection box
detectionBox = new RectangleShape(detectionSize);
detectionBox->setOrigin(Vector2f(detectionSize.x / 2, detectionSize.y / 2));
detectionBox->setPosition(gameObject->transform->position);
// add the detection box to gizmos
detectionBox->setFillColor(Color::Transparent);
detectionBox->setOutlineThickness(1);
detectionBox->setOutlineColor(Color::Blue);
renderer->addGizmo(detectionBox);
}
Donut::~Donut()
{
renderer->removeGizmo(detectionBox);
delete(detectionBox);
}
void Donut::update()
{
// check to see if the player has reached the donut
detectionBox->setSize(detectionSize);
detectionBox->setOrigin(Vector2f(detectionSize.x / 2, detectionSize.y / 2));
detectionBox->setPosition(gameObject->transform->position);
ColliderComp* collision = physics->overlapBox(detectionBox, playerLayer);
if (collision != NULL)
{
// player has reached the end
cout << "player has won!" << endl;
sceneMan->loadScene("victory scene");
}
}
void Donut::lateUpdate()
{
}