-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerUp.hpp
44 lines (37 loc) · 1.36 KB
/
PowerUp.hpp
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
#include "Ball.hpp"
#include <raymath.h>
class PowerUp {
private:
Screen screen;
float width = (screen.w + screen.h) / 50;
float height = ((float)sqrt(3) / 2) * width;
public:
bool visible = false;
// receives the triangle coordenate and create the three vector
Vector2 position = {(float)GetScreenWidth() / 2 + width, (float)GetScreenHeight() / 2};
Vector2 v1 = {position.x, position.y - height};
Vector2 v2 = {position.x - width/2, position.y};
Vector2 v3 = {position.x + width/2, position.y};
void Collide(Ball ball);
void Respawn();
};
inline void PowerUp::Collide (Ball ball) {
if (CheckCollisionPointCircle(v1, ball.position, ball.radius) || CheckCollisionPointCircle(v2, ball.position, ball.radius) || CheckCollisionPointCircle(v3, ball.position, ball.radius)) {
// Make itself invisible and turn off collision
v1 = Vector2Zero();
v2 = Vector2Zero();
v3 = Vector2Zero();
visible = false;
// Start powerup effect
}
// Start timer to spawn again
}
inline void PowerUp::Respawn() {
// Set position and vectors
visible = true;
position = {(float)GetRandomValue(screen.w/6, screen.w/6*5), (float)GetRandomValue(0, screen.h)};
v1 = {position.x, position.y - height};
v2 = {position.x - width/2, position.y};
v3 = {position.x + width/2, position.y};
// Turn on collision
}