-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.cpp
More file actions
72 lines (65 loc) · 2.16 KB
/
Object.cpp
File metadata and controls
72 lines (65 loc) · 2.16 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
71
72
#include "Object.hpp"
#include "Player.hpp"
#include "Scene.hpp"
Object::Object(objectType oType, sf::Vector2f centerPosition, Scene* scene) : Collisionable(centerPosition), _scene(scene), _type(oType) {
_dead = false;
_sprite.setTexture(Resources::linkSet);
_sprite.setTextureRect(Resources::descriptions[objectsDescription][oType][0]);
switch (oType) {
case halfHeal:
case fullHeal:
_bounds = sf::IntRect(0,0,7,8);
_timer = 10;
break;
case life:
_bounds = sf::IntRect(0,0,13,13);
_timer = INT_MAX;
break;
case rupee:
case rupee5:
case key:
_bounds = sf::IntRect(0,0,8,16);
_timer = INT_MAX;
break;
case bomb:
_bounds = sf::IntRect(0,0,8,14);
_timer = 20;
break;
case triforce:
case triblue:
_bounds = sf::IntRect(0,0,10,10);
_timer = INT_MAX;
break;
default:
std::cout << "Wrong objectType at position " << centerPosition.x << " " << centerPosition.y << std::endl;
exit(EXIT_FAILURE);
break; // huehu
}
_sprite.setPosition(centerPosition.x-_bounds.left-_bounds.width/2,centerPosition.y-_bounds.top-_bounds.height/2);
}
Object::~Object() {}
void Object::update(float deltaTime) {
_timer -= deltaTime;
if (_timer < 0) _dead = true;
}
void Object::draw(sf::RenderTarget* target) {
if (_timer > 2 || int(_timer*10) % 2 == 0) target->draw(_sprite);
}
objectType Object::getType() {
return _type;
}
bool Object::isAlive() {
return !_dead;
}
void Object::intersectsWith(Collisionable* c) {
Player* player = dynamic_cast<Player*>(c);
if (player != nullptr) {
_dead = true;
float x,y;
x = _posOriginal.x;
y = _posOriginal.y;
if (DataManager::getBool(_scene->getSceneName()+std::to_string('-')+std::to_string(x)+std::to_string(',')+std::to_string(y), false)) {
DataManager::setBool(_scene->getSceneName()+std::to_string('-')+std::to_string(x)+std::to_string(',')+std::to_string(y), false);
}
}
}