-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
122 lines (109 loc) · 2.62 KB
/
main.c
File metadata and controls
122 lines (109 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
116
117
118
119
120
121
122
/*Main
# Project: FireFlight - ECE453
# Write by Raul Matheus Martins
# Sponsored by Plexu and CAPES - Brazil*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include "headers/basic.h"
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "headers/basic.h"
#include "headers/screen.h"
#include "headers/game_logic.h"
#include "headers/screen_opt.h"
#include "headers/I_O.h"
#include "headers/neolib.h"
SDL_Event event;
#define GAMETIME 5000
int main()
{
int exit = 1, fire_count = 0, fire_ext = 0, start = 0, water = 100, lvl = 0, temp;
int screen_time = 0, spreed_time = 0, win = -1;
int reset = 0, difc_lvl[100];
int fd = -1;
Spot table[8][8];
SDL_Surface * screen = make_screen();
SDL_Surface * tree_fire = NULL;
TTF_Font * font_small = NULL;
SDL_Surface * plexus = NULL;
TTF_Font * font_big = NULL;
SDL_Surface * back = NULL;
SDL_Surface * tree = NULL;
SDL_Surface * rect = NULL;
SDL_Surface * base = NULL;
SDL_Surface * Surfaces[] = {screen, back, tree, tree_fire, rect, plexus, base};
int * dados[] = {&fire_count, &fire_ext, &water, &lvl, &start, &reset, &win};
TTF_Font * font[] = {font_small, font_big};
if(load(Surfaces, font))
exit = 0;
if(init_serial(&fd) == 1)
exit = 0;
difc_table(difc_lvl, 50 + 25 * lvl);
init_table(table, dados);
turn_onoff(0);
SDL_Delay(30);
openBluetooh(fd);
turn_onoff(1);
SDL_Delay(100);
fd = connectBluART();
screen_time = spreed_time = SDL_GetTicks();
clearAll(1, 1, 1);
while(event.type != SDL_QUIT && exit)
{
temp = lvl;
//Check for any User input over SDL interface
while(SDL_PollEvent(&event))
{
mouse_events(&event, dados, table, 1, &fd);
if(temp != lvl)
{
difc_table(difc_lvl, 50 + 25 * lvl);
temp = lvl;
}
}
//Update the screen at 30 FPS
if(fps(&screen_time))
{
// clearAll(1, 0, 0);
// int i;
// for(i = 0; i < 1000 ; i++)
// {
// writeTile(i,0x0000FF);
// printf("i = %d\n", i);
// SDL_Delay(1000);
// }
if(!apply_screen(Surfaces, table, dados, font))
{
printf("Error updating screen\n");
exit = 0;
}
}
//Update the game at GAMETIME sec. based on current status
if(timer(&spreed_time, GAMETIME))
{
if(difc_lvl[rand() % 100] && start)
{
if(reset)
init_table(table, dados);
else
fire_spread(table, dados);
}
}
read_heli(table, fd, dados);
SDL_Delay(.1);
}
//Close and free all surfaces and fds
SDL_FreeSurface(back);
SDL_FreeSurface(tree);
SDL_FreeSurface(tree_fire);
TTF_CloseFont(font_small);
TTF_CloseFont(font_big);
SDL_Quit();
turn_onoff(0);
close(fd);
return 0;
}