-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerUp.cpp
More file actions
118 lines (95 loc) · 3.19 KB
/
Copy pathpowerUp.cpp
File metadata and controls
118 lines (95 loc) · 3.19 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
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
#include "raylib.h"
#include "powerUp.h"
PowerUp::PowerUp(){
this->timer = 0;
SetSoundVolume(this->lessCatsSound, 0.75f);
}
void PowerUp::draw(float deltaTime, GameState& gameState, Vector2 crossHairPosition){
if (this->visible) {
DrawTextureEx(this->powerUpTexture, { this->posX, this->posY }, 0, 1, WHITE);
}
this->timer += deltaTime;
// Every 10 seconds, a power up will spawn
if (this->timer >= 5.0f && this->visible == false && this->powerInEffect == false) {
respawn();
this->visible = true;
}
// Despawn power up if player didnt pick it up in time
if (this->timer >= 1.0f && this->visible) {
this->visible = false;
this->timer = 0;
}
// Timer for Slow Time Power Up
if (this->timer >= 4.0f && this->powerInEffect) {
this->powerInEffect = false;
this->timer = 0;
gameState.catSpeedMult = 1;
PlaySound(this->normalTimeSound);
}
if (checkForClick(crossHairPosition) && this->visible) {
switch (this->type) {
case SHIELDTYPE:
this->visible = false;
this->timer = 0;
gameState.shield = 3;
PlaySound(this->shieldSound);
break;
case HEALTYPE:
this->visible = false;
this->timer = 0;
gameState.health ++;
PlaySound(this->healSound);
break;
case LESSCATSTYPE:
this->visible = false;
this->timer = 0;
gameState.flagDespawnCat = true;
PlaySound(this->lessCatsSound);
break;
case SLOWTIMETYPE:
this->visible = false;
this->powerInEffect = true;
this->timer = 0;
gameState.catSpeedMult = 0.25;
PlaySound(this->slowTimeSound);
break;
case ENUMCOUNT:
CloseWindow();
break;
}
}
}
void PowerUp::getNewType(){
switch (GetRandomValue(0, ENUMCOUNT-1)) {
case 0:
this->type = SHIELDTYPE;
this->powerUpTexture = shieldTexture;
break;
case 1:
this->type = HEALTYPE;
this->powerUpTexture = healTexture;
break;
case 2:
this->type = LESSCATSTYPE;
this->powerUpTexture = lessCatsTexture;
break;
case 3:
this->type = SLOWTIMETYPE;
this->powerUpTexture = slowTimeTexture;
break;
}
}
void PowerUp::respawn(){
getNewType();
this->timer = 0;
this->posX = (float)GetRandomValue(50, (int)(700-this->powerUpTexture.width));
this->posY = (float)GetRandomValue(50, (int)(350-this->powerUpTexture.height));
}
bool PowerUp::checkForClick(Vector2 crossHairPosition){
if (((crossHairPosition.x <= (this->posX + (float)this->powerUpTexture.width) && crossHairPosition.x >= this->posX) &&
(crossHairPosition.y <= (this->posY + (float)this->powerUpTexture.height) && crossHairPosition.y >= this->posY))
&& IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
return true;
}
return false;
}