-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.c
More file actions
103 lines (89 loc) · 2.27 KB
/
screen.c
File metadata and controls
103 lines (89 loc) · 2.27 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
/*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/screen_opt.h"
#include <string.h>
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGTH = 600;
const int SCREEN_BPP = 32;
int DISPLAY_WIDTH = 800;
int DISPLAY_HEIGTH = 600;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *display = NULL;
int init()
{
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
return 0;
const SDL_VideoInfo *info = SDL_GetVideoInfo();
int surface_flags;
surface_flags = SDL_SWSURFACE;
if(info->current_w < SCREEN_WIDTH || info->current_h < SCREEN_HEIGTH)
{
DISPLAY_WIDTH = info->current_w;
DISPLAY_HEIGTH = info->current_h;
surface_flags |= SDL_FULLSCREEN;
}
char en_var[] = "SDL_VIDEO_CENTERED=center";
SDL_putenv(en_var);
display = SDL_SetVideoMode(DISPLAY_WIDTH, DISPLAY_HEIGTH, SCREEN_BPP, surface_flags);
if( display == NULL )
return 0;
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGTH, SCREEN_BPP, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
if( screen == NULL )
return 0;
if( TTF_Init() == -1 )
return 0;
SDL_WM_SetCaption("FireFlight - ECE 453 Project", NULL );
return 1;
}
int load_files()
{
background = load_image ( "files/fundo.png", 0 );
if( background == NULL )
return 0;
return 1;
}
void clean_up()
{
SDL_FreeSurface(background);
SDL_FreeSurface(screen);
SDL_Quit();
}
SDL_Surface *make_screen()
{
if( init() == 0 )
return NULL;
if( load_files() == 0 )
return NULL;
return screen;
}
void screen_clean()
{
apply_surface( 0, 0, background, screen, NULL );
}
void closeWindow()
{
clean_up();
}
int update_display(Sint16 x, Sint16 y)
{
SDL_Rect teste = {x, y, (Uint16)DISPLAY_WIDTH, (Uint16)DISPLAY_HEIGTH};
apply_surface(0,0, screen, display, &teste);
if(SDL_Flip(display) == -1)
return 0;
return 1;
}
int apply_screen(SDL_Surface ** Surfaces, Spot table[][8], int ** dados, TTF_Font ** font)
{
apply_surface(0, 0, Surfaces[1], Surfaces[0], NULL);
show_table(table, Surfaces[2], Surfaces[3], Surfaces[6], Surfaces[0]);
screen_text(Surfaces, dados, font);
return(update_display(0,0));
}