-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_opt.c
More file actions
167 lines (149 loc) · 4.54 KB
/
screen_opt.c
File metadata and controls
167 lines (149 loc) · 4.54 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
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
158
159
160
161
162
163
164
165
166
167
/*Game User/Screen Functions
# Project: FireFlight - ECE453
# Write by Raul Matheus Martins
# Sponsored by Plexu and CAPES - Brazil*/
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "headers/basic.h"
#include "headers/game_logic.h"
#include "headers/I_O.h"
#include "headers/neolib.h"
SDL_Color textColor = {0x00, 0x00, 0x00, 0x00};
void screen_text(SDL_Surface ** Surfaces, int ** dados, TTF_Font ** font)
{
SDL_Surface * stemp = NULL;
char * temp;
temp = (char *) malloc(150 * sizeof(char));
int off_x = 0;
if(*dados[3] == 2)
off_x = 333;
else if(*dados[3] == 1)
off_x = 283;
else
off_x = 233;
apply_surface(off_x, 256, Surfaces[4], Surfaces[0], NULL);
sprintf(temp, "Difficulty lvl: 1 2 3");
stemp = TTF_RenderUTF8_Blended(font[0], temp, textColor);
apply_surface(10, 255, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
sprintf(temp, "Remaining Fires: %d", *(dados[0]));
stemp = TTF_RenderUTF8_Blended(font[0], temp, textColor);
apply_surface(10, 305, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
sprintf(temp, "Fires Extinguished: %d", *(dados[1]));
stemp = TTF_RenderUTF8_Blended(font[0], temp, textColor);
apply_surface(10, 355, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
if(*dados[2] > 30)
sprintf(temp, "Water Level: %d", *dados[2]);
else if(*dados[2] > 0)
sprintf(temp, "Water Level: %d - Critical", *dados[2]);
else
sprintf(temp, "No water! Go to base!");
stemp = TTF_RenderUTF8_Blended(font[0], temp, textColor);
apply_surface(10, 405, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
if(*dados[4])
{
if(*dados[6] == -1)
sprintf(temp, "PAUSE");
else if(*dados[6] == 1)
sprintf(temp, "YOU WIN!");
else if(*dados[6] == 0)
sprintf(temp, "Game Over!");
stemp = TTF_RenderUTF8_Blended(font[1], temp, textColor);
apply_surface(100, 455, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
sprintf(temp, "RESET");
stemp = TTF_RenderUTF8_Blended(font[1], temp, textColor);
apply_surface(100, 525, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
}
else
{
sprintf(temp, "START");
stemp = TTF_RenderUTF8_Blended(font[1], temp, textColor);
apply_surface(100, 455, stemp, Surfaces[0], NULL);
SDL_FreeSurface(stemp);
}
free(temp);
apply_surface(600, 100, Surfaces[5], Surfaces[0], NULL);
}
//Temporary function until SDL Screen is not implemented - FINAL
void show_table(Spot table[][8], SDL_Surface * tree, SDL_Surface * tree_fire, SDL_Surface * base, SDL_Surface * screen)
{
int i, j;
int off_x = 395, off_y = 180;
for(i = 1; i < 7; i++)
for(j = 1; j < 7; j++)
{
if(table[i][j].fire_lvl == 0)
apply_surface( off_x + i*45, off_y + j*50, tree, screen, NULL);
else if(table[i][j].fire_lvl == 1)
apply_surface( off_x + i*45, off_y + j*50, tree_fire, screen, NULL);
else if(table[i][j].fire_lvl == -2)
apply_surface( off_x + i*45, off_y + j*50, base, screen, NULL);
send_tile(table, i, j);
}
}
void mouse_events(SDL_Event * event, int ** dados, Spot table[][8], int teste_mode, int * fd)
{
int x, y;
if(event->type == SDL_MOUSEBUTTONDOWN)
{
if(event->button.button == SDL_BUTTON_LEFT)
{
x = event->motion.x;
y = event->motion.y;
if(( x > 233) && ( x < (233 + 39) ) && ( y > 256) && ( y < (256 + 39)))
*(dados[3]) = 0;
if(( x > 283) && ( x < (285 + 39) ) && ( y > 256) && ( y < (256 + 39)))
*(dados[3]) = 1;
if(( x > 333) && ( x < (335 + 39) ) && ( y > 256) && ( y < (256 + 39)))
*(dados[3]) = 2;
if(( x > 100) && ( x < (100 + 165) ) && ( y > 455) && ( y < (455 + 50)))
*(dados[4]) = !*(dados[4]);
if(( x > 100) && ( x < (100 + 165) ) && ( y > 525) && ( y < (525 + 50)))
*(dados[5]) = 1;
if((x > 780) && (x < 800) && (y > 580) && (y < 600))
{
SDL_Delay(500);
turn_onoff(0);
SDL_Delay(500);
SDL_Delay(500);
turn_onoff(1);
*fd = connectBluART();
printf("Restarted\n");
}
//Use user input over the title to change status
if(teste_mode)
{
int i, j;
int off_x = 395, off_y = 180;
if((x > off_x) && (x < off_x + 45*8) && (y > off_y) && (y < off_y + 50*8))
{
i = (x - off_x)/45;
j = (y - off_y)/50;
if(table[i][j].fire_lvl == 0)
{
table[i][j].fire_lvl = 1;
if( (*dados[0]) >= 0 )
(*dados[0])=(*dados[0]) + 1;
}
else if(table[i][j].fire_lvl == 1)
{
table[i][j].fire_lvl = 0;
if( *(dados[0]) <= 36 )
{
*(dados[0])=*(dados[0]) - 1;
*(dados[1])=*(dados[1]) + 1;
if(*(dados[2]) > 0)
*(dados[2])=*(dados[2]) - 10;
}
}
}
}
}
}
}