-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHitboxComponent.cpp
More file actions
68 lines (58 loc) · 1.87 KB
/
Copy pathHitboxComponent.cpp
File metadata and controls
68 lines (58 loc) · 1.87 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
#include "HitboxComponent.h"
HitboxComponent::HitboxComponent(sf::Sprite& sprite,
float offset_x, float offset_y,
float width, float height)
: sprite(sprite), offsetX(offset_x), offsetY(offset_y), width(width), height(height), moveX(0), moveY(0), sizeX(0), sizeY(0)
{
this->hitbox.setPosition(this->sprite.getPosition().x + offset_x, this->sprite.getPosition().y + offset_y);
this->hitbox.setSize(sf::Vector2f(width, height));
this->hitbox.setFillColor(sf::Color::Transparent);
this->hitbox.setOutlineThickness(1.f);
this->hitbox.setOutlineColor(sf::Color::Green);
}
HitboxComponent::~HitboxComponent()
{
}
sf::RectangleShape* HitboxComponent::getHitbox()
{
return &this->hitbox;
}
bool HitboxComponent::checkIntersect(const sf::FloatRect& frect)
{
return this->hitbox.getGlobalBounds().intersects(frect);
}
void HitboxComponent::movepos(float x, float y,float sizeX,float sizeY)
{
this->moveX = x;
this->moveY = y;
this->sizeX = sizeX;
this->sizeY = sizeY;
}
void HitboxComponent::setpos(float x, float y)
{
this->hitbox.setPosition(x, y);
}
void HitboxComponent::Render(sf::RenderTarget& target)
{
target.draw(this->hitbox);
}
void HitboxComponent::setcenter()
{
this->floor = false;
this->hitbox.setOrigin(this->width / 2.f, this->height / 2.f);
}
void HitboxComponent::Update()
{
//bug fix if my entity struck on floor
if (this->hitbox.getPosition().y + this->hitbox.getGlobalBounds().height > 710.f && this->floor) {
this->sprite.setPosition(this->sprite.getPosition().x,705.f - height - offsetX - moveX);
}
//========================
this->hitbox.setPosition(this->sprite.getPosition().x + offsetX + moveX, this->sprite.getPosition().y + offsetY + moveY);
this->hitbox.setSize(sf::Vector2f(this->width + sizeX, this->height + sizeY));
this->moveX = this->moveY = this->sizeX = this->sizeY = 0;
}
void HitboxComponent::rotate(float degree)
{
this->hitbox.rotate(degree);
}