Repository navigation
Expand file tree
/
Copy pathTimer.cpp
More file actions
69 lines (55 loc) · 1.98 KB
/
Copy pathTimer.cpp
File metadata and controls
69 lines (55 loc) · 1.98 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
#include "Timer.h"
// Constructor: Load images and textures for the timer
Timer::Timer() {
ImageClock = LoadImageAnim("VFX/clock.gif", &AnimFrames);
TextureClock = LoadTextureFromImage(ImageClock);
TextureTimerBar = LoadTexture("VFX/timerBar.png");
}
// Update and draw the timer
void Timer::UpdateTimer(Font LoadedFont) {
// Calculate the height of the bar based on remaining time
int barHeight = static_cast<int>(400 * (TimeLeft / InitialTimer));
// Draw the decreasing bar
DrawRectangleGradientV(140, (GetScreenHeight()) - barHeight - 275, 80, barHeight, GREEN, RED);
DrawTexture(TextureTimerBar, 90, 245, WHITE);
DrawTexture(TextureClock, 40, 630, WHITE);
// Handle frame animation for the clock
FrameCounter++;
if (FrameCounter >= FrameDelay && TimeLeft > 0) {
// Move to the next frame
CurrentAnimFrame++;
// Loop back to the first frame if needed
if (CurrentAnimFrame >= AnimFrames) {
CurrentAnimFrame = 0;
}
// Calculate memory offset for next frame data
NextFrameDataOffset = ImageClock.width * ImageClock.height * 4 * CurrentAnimFrame;
// Update texture with next frame data
UpdateTexture(TextureClock, ((unsigned char *)ImageClock.data) + NextFrameDataOffset);
FrameCounter = 0;
}
// Draw the remaining time
DrawTextEx(LoadedFont, TextFormat("%.1f", TimeLeft), {20, 580}, 40, 0, WHITE);
}
// Get the remaining time
float Timer::GetTimeLeft() const {
return TimeLeft;
}
// Set the timer to a specific time
void Timer::SetTimer(float time) {
TimeLeft = time;
}
// Get the initial timer value
float Timer::GetInitialTimer() const {
return InitialTimer;
}
// Add time to the timer
void Timer::AddToTimer(float seconds) {
TimeLeft += seconds;
if (TimeLeft > InitialTimer) {
TimeLeft = InitialTimer;
}
if (TimeLeft <= 0) {
TimeLeft = 0;
}
}