-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld_interface.c
More file actions
115 lines (104 loc) · 2.62 KB
/
world_interface.c
File metadata and controls
115 lines (104 loc) · 2.62 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
#include "world_interface.h"
#include <stdlib.h>
#include <raylib.h>
#include <stdio.h>
#include "game.h"
extern game_t *pgame;
textBox_t *ga_pTextBoxes[MAX_TEXTBOX];
t_broadcast *ga_pbroadCasts[MAX_BROADCASTS];
static unsigned g_numberOfBroadCasts;
void textBoxTick(textBox_t *ptext)
{
if(CheckCollisionCircleRec(pgame->m_mousePosWorld, 1, (Rectangle){ptext->m_pos.x, ptext->m_pos.y, ptext->m_width, ptext->m_fontsize}))
{
ptext->m_color = GREEN;
ptext->m_hovered = true;
}else{
ptext->m_color = ptext->m_origincolor;
ptext->m_hovered = false;
}
if(ptext->m_hovered && IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
ptext->m_color = ORANGE;
ptext->m_pressed = true;
}
// text boxes functionalities
if(ptext->m_pressed == true)
switch (ptext->m_ID)
{
case TEXT_STARTWAVE:
pgame->m_waveState = WAVE_STARTED;
ptext->m_show = false;
ptext->m_pressed = false;
break;
default:
break;
}
}
void createTextBox(char *text, Vector2 pos, int fontSize, Color color, TextBoxes ID)
{
textBox_t *ptext = malloc(sizeof(textBox_t));
ga_pTextBoxes[ID] = ptext;
ptext->m_text = text;
ptext->m_pos = pos;
ptext->m_width = MeasureText(text, fontSize);
ptext->m_hovered = false;
ptext->m_pressed = false;
ptext->m_show = false;
ptext->m_fontsize = fontSize;
ptext->m_origincolor = color;
ptext->m_ID = ID;
}
textBox_t *getTextBoxByID(int ID)
{
return ga_pTextBoxes[ID];
}
void createBroadcast(char *text, int duration, int fontsize)
{
t_broadcast *pbrod = malloc(sizeof(t_broadcast));
for(int i = 0; i < MAX_BROADCASTS; i++)
{
if(ga_pbroadCasts[i] != NULL)continue;
ga_pbroadCasts[i] = pbrod;
pbrod->m_ID = i;
break;
}
pbrod->m_text = text;
pbrod->m_duration = duration;
pbrod->m_tick = 0;
++g_numberOfBroadCasts;
}
void broadcastTick(t_broadcast *pbrod)
{
++pbrod->m_tick;
if(pbrod->m_tick >= pbrod->m_duration)
{
distroyBroadcast(pbrod->m_ID);
return;
}
}
t_broadcast *getBroadcastByID(int ID)
{
return ga_pbroadCasts[ID];
}
void distroyBroadcast(int ID)
{
if(ID == -1)
{
for(int i = 0; i < MAX_BROADCASTS; i++)
{
if(ga_pbroadCasts[i] == NULL)continue;
free(ga_pbroadCasts[i]);
ga_pbroadCasts[i] = NULL;
}
g_numberOfBroadCasts = 0;
return;
}
free(ga_pbroadCasts[ID]);
ga_pbroadCasts[ID] = NULL;
--g_numberOfBroadCasts;
}
unsigned getNumberOfBroadcasts()
{
return g_numberOfBroadCasts;
}