-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsdl.c
124 lines (111 loc) · 3.56 KB
/
sdl.c
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
/*
** init.c for in /home/notwak42/Projects/C/Bomberman/BombGit/Bomberman/sdl
**
** Made by MASERA Mathieu
** Login <masera_m@etna-alternance.net>
**
** Started on Wed Jul 4 09:37:04 2018 MASERA Mathieu
** Last update Wed Jul 4 09:37:07 2018 MASERA Mathieu
*/
#include <stdlib.h>
#include <stdio.h>
#include "constant.h"
#include "enum.h"
// doit être include au départ, défini SDL/* et t_sdl
#include "sdl.h"
//
#include "map.h"
#include "player_info.h"
#include "client_request.h"
#include "server.h"
#include "libmy.h"
#include "base_map_manager.h"
//On init la structure avec tous ses champs a NULL
t_sdl *init_sdl()
{
t_sdl *sdl;
if ((sdl = malloc(sizeof(t_sdl))) == NULL) {
return (NULL);
}
sdl->window = NULL;
sdl->renderer = NULL;
sdl->menu_background = NULL;
sdl->join_game = NULL;
sdl->create_game = NULL;
sdl->server_welcome = NULL;
sdl->white_back = NULL;
return (sdl);
}
//Init de la window et du renderer
t_sdl *init_window(t_sdl *sdl)
{
SDL_Window *window;
SDL_Renderer *renderer;
window = SDL_CreateWindow(
"Bomberman ETNA 2019",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
WINDOW_W,
WINDOW_H,
SDL_WINDOW_SHOWN);
if (!window) {
printf("window init error");
return NULL;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
SDL_ShowSimpleMessageBox(0, "renderer init error", SDL_GetError(), window);
return (NULL);
}
sdl->window = window;
sdl->renderer = renderer;
return (sdl);
}
t_sdl *init_fronts(t_sdl *sdl)
{
SDL_Surface *img, *join_game_text, *create_server_text, *server_welcome_text, *white;
SDL_Texture *background_texture, *join_texture, *server_texture, *server_welcome, *white_back;
SDL_Color black = {0, 0, 0, 0};
TTF_Font *police;
//SDL_IMAGE load an image
#ifdef linux
img = IMG_Load("/usr/share/bomberman/ressources/Bomberman.jpg");
white = IMG_Load("/usr/share/bomberman/ressources/white.jpg");
#else
img = IMG_Load("ressources/Bomberman.jpg");
white = IMG_Load("ressources/white.jpg");
#endif
if (!img || !white)
{
SDL_ShowSimpleMessageBox(0, "img init error", SDL_GetError(), sdl->window);
}
#ifdef linux
police = TTF_OpenFont("/usr/share/bomberman/ressources/bm.ttf", 65);
#else
police = TTF_OpenFont("ressources/bm.ttf", 65);
#endif
join_game_text = TTF_RenderText_Blended(police, "join_game", black);
create_server_text = TTF_RenderText_Blended(police, "create_server", black);
server_welcome_text = TTF_RenderText_Blended(police, "WELCOME SERVER", black);
background_texture = SDL_CreateTextureFromSurface(sdl->renderer, img);
white_back = SDL_CreateTextureFromSurface(sdl->renderer, white);
join_texture = SDL_CreateTextureFromSurface(sdl->renderer, join_game_text);
server_texture = SDL_CreateTextureFromSurface(sdl->renderer, create_server_text);
server_welcome = SDL_CreateTextureFromSurface(sdl->renderer, server_welcome_text);
if (!background_texture || !join_texture || !server_texture) {
SDL_ShowSimpleMessageBox(0, "init texture error", SDL_GetError(), sdl->window);
}
//we clean surface as we converted them to texture so we don't need them anymore
SDL_FreeSurface(img);
SDL_FreeSurface(white);
SDL_FreeSurface(join_game_text);
SDL_FreeSurface(create_server_text);
SDL_FreeSurface(server_welcome_text);
TTF_CloseFont(police);
sdl->menu_background = background_texture;
sdl->white_back = white_back;
sdl->join_game = join_texture;
sdl->create_game = server_texture;
sdl->server_welcome = server_welcome;
return (sdl);
}