R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Collision.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** CollisionComponent.hpp
6*/
7
13#pragma once
14
15#include <cstdint>
16#include <utility>
17#include <SFML/Graphics/Rect.hpp>
18#include <SFML/Graphics/Vertex.hpp>
19
20#include "Log.hpp"
21#include "LogMacros.hpp"
22#include "Utilities.hpp"
23#include "Recoded/Rect.hpp"
24#include "CustomExceptions.hpp"
27
28namespace GUI
29{
30 namespace ECS
31 {
32 namespace Systems
33 {
39 class Collision : public EntityNode {
40 public:
41 Collision(const std::uint32_t entityId = 0, const float width = 0, const float height = 0, const float positionX = 0, const float positionY = 0);
42 ~Collision();
43
44 void setWidth(const float &width);
45 void setHeight(const float &height);
46
47 void setPositionX(const float &posX);
48 void setPositionY(const float &posY);
49
50 void setPosition(const std::pair<float, float> &position);
51
52 void setDimension(const std::pair<float, float> &dimension);
53
54 void setGeometry(const Recoded::FloatRect &rect);
55
56 void setMousePosition(const std::pair<int, int> &position);
57
58 void update(const std::pair<int, int> &mousePosition);
59 void update(const GUI::ECS::Systems::MouseInfo &mouse);
60 void update(const GUI::ECS::Systems::Collision &copy);
61
63
64 const bool isClicked() const;
65 const bool isHovered() const;
66 const bool isColliding(const Collision &itemTwo) const;
67
68 const float getWidth() const;
69 const float getHeight() const;
70
71 const float getPositionX() const;
72 const float getPositionY() const;
73
74 const Recoded::FloatRect getGeometry() const;
75
76 const std::pair<float, float> getPosition() const;
77
78 const std::pair<float, float> getDimension() const;
79
89 const std::string getInfo(const unsigned int indent = 0) const;
90
92
93 protected:
95 bool _isHovered = false;
96 bool _isClicked = false;
97 Recoded::FloatRect _rect = { {0,0}, {0,0} };
99 };
100
107 std::ostream &operator<<(std::ostream &os, const Collision &item);
108
115 [[nodiscard]] const bool operator==(Collision left, Collision right);
116
123 [[nodiscard]] const bool operator!=(Collision left, Collision right);
124
131 [[nodiscard]] const Collision operator+(Collision left, Collision right);
132
139 [[nodiscard]] const Collision operator-(Collision left, Collision right);
140
147 [[nodiscard]] const Collision operator*(Collision left, Collision right);
148
155 const Collision &operator+=(Collision &left, Collision right);
156
163 const Collision &operator-=(Collision &left, Collision right);
164
171 const Collision &operator*=(Collision &left, Collision right);
172
173 }
174 }
175}
176
File in charge of containing the custom errors that are going to be used for custom description error...
This is the file that links the EntityNode children.
Macro definitions for logging messages with varying levels of detail and formatting.
This is the file in charge of containing the Log class (the one in charge of outputing info only when...
This is the header file containing the class for the mouse information.
Defines a rectangle class (Rect) mimicking sf::Rect without relying on SFML.
Represents a rectangular component that can detect collisions and mouse interactions,...
Definition Collision.hpp:39
void setPositionY(const float &posY)
Sets the Y-coordinate of the component's position and updates collision data.
Definition Collision.cpp:73
Recoded::FloatRect _rect
Definition Collision.hpp:97
const std::pair< float, float > getDimension() const
Get the dimension of the item in the form of an sf::Vector2i.
void setHeight(const float &height)
Sets the height of the component and updates collision data.
Definition Collision.cpp:51
const bool isClicked() const
Checks if the component is clicked by the mouse.
void updateMouseInfo(const GUI::ECS::Systems::MouseInfo &mouse)
Updates the mouse info object used for collision checks.
void setWidth(const float &width)
Sets the width of the component and updates collision data.
Definition Collision.cpp:40
void _updateMouseCollisionData()
Updates the mouse collision data, setting hover and click states.
const float getWidth() const
Gets the width of the component.
void setDimension(const std::pair< float, float > &dimension)
Set the dimension of the object.
Definition Collision.cpp:95
void update(const std::pair< int, int > &mousePosition)
Update the mouse info object used for mouse tracking.
const float getHeight() const
Gets the height of the component.
~Collision()
Default destructor.
Definition Collision.cpp:33
const bool isColliding(const Collision &itemTwo) const
Checks if this component is colliding with another Collision.
void setPositionX(const float &posX)
Sets the X-coordinate of the component's position and updates collision data.
Definition Collision.cpp:62
const Recoded::FloatRect getGeometry() const
This is the function in charge of returning the coordinates in the form of an sf::FloatRect.
const std::string getInfo(const unsigned int indent=0) const
This is a function meant for debugging purposes It will dump the current state of the variables upon ...
const std::pair< float, float > getPosition() const
Get the position of the item in the form of an sf::Vector2i.
const float getPositionY() const
Gets the Y-coordinate of the component's position.
void setMousePosition(const std::pair< int, int > &position)
Updates the mouse position for collision checks.
const GUI::ECS::Systems::MouseInfo getMouseInfo() const
This is the function in charge of returning the MouseInfo class instance.
void setGeometry(const Recoded::FloatRect &rect)
Set the dimensions of the object using the FloatRect recode.
Collision(const std::uint32_t entityId=0, const float width=0, const float height=0, const float positionX=0, const float positionY=0)
Constructs a Collision with the specified dimensions and position.
Definition Collision.cpp:24
GUI::ECS::Systems::MouseInfo _mouse
Definition Collision.hpp:98
void setPosition(const std::pair< float, float > &position)
Set the position of the object.
Definition Collision.cpp:84
const float getPositionX() const
Gets the X-coordinate of the component's position.
const bool isHovered() const
Checks if the component is currently hovered by the mouse.
Collision & operator=(const GUI::ECS::Systems::Collision &copy)
This is the overload in charge of allowing the user to update their variables using the = sign.
A generic 2D rectangle class that holds position and size as pairs.
Definition Rect.hpp:38
const Collision operator+(Collision left, Collision right)
Adds two collision components component-wise.
const Collision & operator+=(Collision &left, Collision right)
Adds another collision component to the current collision component component-wise.
const Collision operator-(Collision left, Collision right)
Subtracts two collision components component-wise.
const Collision operator*(Collision left, Collision right)
Multiplies two collision components component-wise.
const bool operator==(Collision left, Collision right)
Compares two collision components for equality.
const bool operator!=(Collision left, Collision right)
Compares two collision components for inequality.
std::ostream & operator<<(std::ostream &os, const Clock &item)
Outputs the clock's info to a stream.
Definition Clock.cpp:73
const Collision & operator*=(Collision &left, Collision right)
Multiplies another collision component with the current collision component component-wise.
const Collision & operator-=(Collision &left, Collision right)
Subtracts another collision component from the current collision component component-wise.