[Added] Gun angling

This commit is contained in:
Ninjaws
2024-12-13 00:24:51 +01:00
parent dbeb15ee60
commit 88e0b7cb05
8 changed files with 333 additions and 228 deletions
+27 -17
View File
@@ -12,6 +12,7 @@ class TextureWrapper {
this->texture = texture;
this->size = size;
this->position = position;
this->sourceRect = sourceRect;
}
~TextureWrapper() {
@@ -33,6 +34,10 @@ class TextureWrapper {
return this->position;
}
float getRotation() {
return this->rotation;
}
void setSourceRect(Rectangle rect) {
this->sourceRect = rect;
}
@@ -41,35 +46,40 @@ class TextureWrapper {
this->position = position;
}
void setRotation(float rot) {
this->rotation = rot;
}
void move(Vector2 deltaPos) {
this->position = {this->position.x + deltaPos.x, this->position.y + deltaPos.y};
}
/** Returns the 4 corners of the texture */
std::unordered_map<ECorner, Vector2> getCorners() {
std::unordered_map<ECorner, Vector2> corners;
float top = this->position.y;
float right = this->position.x+this->size.x;
float bottom = this->position.y + this->size.y;
float left = this->position.x;
float margin = 8; // Space to the corner
corners[ECorner::TOP_LEFT] = {left+margin, top};
corners[ECorner::TOP_RIGHT] = {right-margin, top};
corners[ECorner::RIGHT_TOP] = {right, top+margin};
corners[ECorner::RIGHT_BOTTOM] = {right, bottom-margin};
corners[ECorner::BOTTOM_RIGHT] = {right-margin, bottom};
corners[ECorner::BOTTOM_LEFT] = {left+margin, bottom};
corners[ECorner::LEFT_BOTTOM] = {left, bottom-margin};
corners[ECorner::LEFT_TOP] = {left, top+margin};
// std::unordered_map<ECorner, Vector2> getCorners() {
// std::unordered_map<ECorner, Vector2> corners;
// float top = this->position.y;
// float right = this->position.x+this->size.x;
// float bottom = this->position.y + this->size.y;
// float left = this->position.x;
// float margin = 8; // Space to the corner
// corners[ECorner::TOP_LEFT] = {left+margin, top};
// corners[ECorner::TOP_RIGHT] = {right-margin, top};
// corners[ECorner::RIGHT_TOP] = {right, top+margin};
// corners[ECorner::RIGHT_BOTTOM] = {right, bottom-margin};
// corners[ECorner::BOTTOM_RIGHT] = {right-margin, bottom};
// corners[ECorner::BOTTOM_LEFT] = {left+margin, bottom};
// corners[ECorner::LEFT_BOTTOM] = {left, bottom-margin};
// corners[ECorner::LEFT_TOP] = {left, top+margin};
return corners;
}
// return corners;
// }
private:
Texture2D texture;
Rectangle sourceRect;
Vector2 size;
Vector2 position;
float rotation;
};
#endif