-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperDataTypes.h
157 lines (135 loc) · 4.49 KB
/
HelperDataTypes.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// Created by JOHN CHRISTIAN CASTILLO on 7/18/2021.
//
#ifndef TURBOHIKER_HELPERDATATYPES_H
#define TURBOHIKER_HELPERDATATYPES_H
#include <utility>
#include <memory>
namespace TH {
/**
* Possible game inputs
*/
enum Input
{
UP,
DOWN,
LEFT,
RIGHT,
HONKING,
SCARING,
ZERO,
ENTER,
SPAWNENEMY
};
/**
* The different entities in the Turbo hiker game
*/
enum EntityTypes
{
mainCharacter,
staticHiker,
leftToRightHiker,
background,
finishLine,
speedUp,
invincibilityStar,
summonEnemy,
nukePowerUp,
laserBeamPowerUp
};
/**
* structure used to specify the coordinates of a given entity
*/
struct Position
{
float x;
float y;
/**
* Instantiates a Position object at coordinates (xCor, yCor)
* @param xCor: the x coordinate we want to instantiate Position in
* @param yCor: the y coordinate we want to instantiate Position in
*/
Position(float xCor, float yCor) : x(xCor), y(yCor) {}
/**
* A copy constructor of Position
* @param pos
*/
Position(const Position& pos) = default;
};
struct Dimensions
{
float width;
float height;
/**
* Instantiate Dimensions with width = _width and height = _height
* @param _width: The width we want our dimension to have
* @param _height: Th height we want our dimension to have
*/
Dimensions(float _width, float _height) : width(_width), height(_height){};
/**
* A copy constructor of Dimension
* @param dim
*/
Dimensions(const Dimensions& dim) = default;
};
struct Move
{
float x;
float y;
/**
* Instantiate Move with x = _x and y = _y
* @param _x: Offset we want to use for the x coordinate
* @param _y: Offset we want to use for the y cooridnate
*/
Move(const float& _x, const float& _y) : x(_x), y(_y){};
Move() = default;
Move operator*(const float& movementSpeed)
{
x *= movementSpeed;
y *= movementSpeed;
}
};
struct GlobalBounds
{
Position position;
Dimensions dimensions;
/**
* Instantiates GlobalBounds at position = pos and dimension = dim
* @param pos: Position we want to instantiate the GlobalBounds position
* @param dim: Dimension we want to instantiate the GlobalBounds dimension
*/
GlobalBounds(const Position& pos, const Dimensions& dim) : position(pos), dimensions(dim){};
/**
* Keep in mind that we are working with rectangle objects
* @param nextPosition: The GlobalBounds of another entity
* @return True if this instance of GlobalBounds intersects with the nextPosition
*/
template <typename type>
bool intersects(const std::shared_ptr<GlobalBounds>& nextPosition) const
{
// calculate leftX and topY of current
type left = position.x - dimensions.width / 2;
type top = position.y - dimensions.height / 2;
// calculate leftX and topY of other object
type nextLeft = nextPosition->position.x - nextPosition->dimensions.width / 2;
type nextTop = nextPosition->position.y - nextPosition->dimensions.height / 2;
// Compute the min and max x and y of the the entity we're in
type thisMinX = left;
type thisMaxX = static_cast<type>(left + dimensions.width);
type thisMinY = top;
type thisMaxY = static_cast<type>(top + dimensions.height);
// Compute the min and max x and y of the the next position we're in
type r2MinX = nextLeft;
type r2MaxX = static_cast<type>(nextLeft + dimensions.width);
type r2MinY = nextTop;
type r2MaxY = static_cast<type>(nextTop + dimensions.height);
// Compute the intersection boundaries
type interLeft = std::max(thisMinX, r2MinX);
type interTop = std::max(thisMinY, r2MinY);
type interRight = std::min(thisMaxX, r2MaxX);
type interBottom = std::min(thisMaxY, r2MaxY);
return (interLeft < interRight) && (interTop < interBottom);
}
};
} // namespace TH
#endif // TURBOHIKER_HELPERDATATYPES_H