-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.hpp
More file actions
63 lines (48 loc) · 1.64 KB
/
Tile.hpp
File metadata and controls
63 lines (48 loc) · 1.64 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
#ifndef __TILE_HPP__
#define __TILE_HPP__
#include <iostream>
#include <SFML/Graphics.hpp>
class Tile : public sf::Drawable {
public:
// Konstruktor
Tile(std::string textureFileName) {
this->x = 0;
this->y = 0;
this->hitbox = sf::RectangleShape(sf::Vector2f(32 * 2, 32 * 2));
this->hitbox.setFillColor(sf::Color::Green);
this->hitbox.setPosition(this->x, this->y);
this->texture.loadFromFile(textureFileName);
this->sprite.setTexture(this->texture);
this->sprite.setScale(2.0, 2.0);
}
// Kirajzolás
void draw(sf::RenderTarget& target, sf::RenderStates states) const override {
target.draw(sprite, states);
}
// Pozíció beállítása a felhasználónak
void setPosition(int x, int y) {
this->x = x;
this->y = y;
hitbox.setPosition(this->x, this->y);
sprite.setPosition(this->x, this->y);
}
// Méret megkapása a felhasználónak
sf::Vector2f getSize() {
return hitbox.getSize();
}
// Érintkezés érzékelésének a megkönnyebbítése a felhasználónak
sf::FloatRect getGlobalBounds() {
return hitbox.getGlobalBounds();
}
// Pozíció lekérése a felhasználónak
sf::Vector2f getPosition() {
return sf::Vector2f(this->x, this->y);
}
private:
// Változók
int x, y;
sf::RectangleShape hitbox;
sf::Texture texture;
sf::Sprite sprite;
};
#endif // __TILE_HPP__