3 Copyright (C) 2003 Nuno Subtil
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 static const char cvsid
[] =
21 "$Id: menu.c,v 1.26 2003/11/30 17:43:55 nsubtil Exp $";
43 #include "render_map.h"
47 #include "level-demo.h"
48 #include "level-classic.h"
51 void menu_setup_map(struct map
*map
)
55 for(y
= 0; y
< map
->height
; y
++)
56 for(x
= 0; x
< map
->width
; x
++)
58 if(MAP(map
, x
, y
).content
== MAP_CONTENT_FOOD
)
60 MAP_FOOD(map
, x
, y
).type
= FOOD_TYPE_INTERMITTENT
;
61 MAP_FOOD(map
, x
, y
).status
= FOOD_STATUS_EATEN
;
62 MAP_FOOD(map
, x
, y
).time
= sqrt(pow(x
, 2) + pow(y
, 2)) / 5.0;
63 MAP_FOOD(map
, x
, y
).active_time
= 10.0;
64 MAP_FOOD(map
, x
, y
).fade_out
= 1.0;
65 MAP_FOOD(map
, x
, y
).inactive_time
= 3.0;
66 MAP_FOOD(map
, x
, y
).fade_in
= 1.0;
74 struct menu_entry main_menu
[] =
76 { "gfx/start-game-high.tga", "gfx/start-game-low.tga", NULL
, NULL
},
77 { "gfx/resolution-high.tga", "gfx/resolution-low.tga", NULL
, NULL
},
78 { "gfx/high_scores-high.tga", "gfx/high_scores-low.tga", NULL
, NULL
},
79 { "gfx/exit-high.tga", "gfx/exit-low.tga", NULL
, NULL
}
81 int main_menu_num
= 4;
82 int c
, current_selection
= 0;
84 for(c
= 0; c
< main_menu_num
; c
++)
86 main_menu
[c
].image_high
= gfx_get(main_menu
[c
].image_name_high
);
87 if(main_menu
[c
].image_high
->id
== -1)
89 gfx_alpha_from_key(main_menu
[c
].image_name_high
, 0, 0, 0);
90 gfx_upload_texture(main_menu
[c
].image_name_high
);
93 main_menu
[c
].image_low
= gfx_get(main_menu
[c
].image_name_low
);
94 if(main_menu
[c
].image_low
->id
== -1)
96 gfx_alpha_from_key(main_menu
[c
].image_name_low
, 0, 0, 0);
97 gfx_upload_texture(main_menu
[c
].image_name_low
);
102 game
= game_new(GAME_TYPE_DEMO
);
103 game
->map
= map_load_from_ascii((char **)level_demo
, NULL
,
104 LEVEL_DEMO_WIDTH
, LEVEL_DEMO_HEIGHT
);
105 menu_setup_map(game
->map
);
108 // game_load_level(LEVEL_DEMO);
109 game
->demo_camera
= (struct camera
*)malloc(sizeof(struct camera
));
110 game
->demo_camera
->type
= CAMERA_TYPE_DEMO
;
111 game_reset_camera(game
, -1);
114 audio_play_music("sfx/hummingbird.ogg");
115 screen_set_fadein(0.5);
121 int last_update
, ticks
;
123 switch((current_selection
= menu(game
, main_menu
,
124 main_menu_num
, current_selection
))) {
127 last_update
= SDL_GetTicks();
130 audio_fade_music(500);
131 screen_set_fadeout(0.5);
137 ticks
= SDL_GetTicks();
138 diff
= ticks
- last_update
;
140 delta
+= (float)diff
/ 1000;
145 // screen_update_gamma((float)diff / 1000);
146 render_start_frame();
147 render_setup(game
, -1);
148 map_render_opaque_objects(game
);
149 game_draw_opaque_objects(game
, -1);
150 game_draw_translucent_objects(game
, -1);
151 map_render_translucent_objects(game
, -1);
154 /* classic single-player */
155 gm
= game_new(GAME_TYPE_CLASSIC
);
156 gm
->map
= map_load_from_ascii((char **)level_classic
,
157 (char **)level_classic_ghost_map
,
158 LEVEL_CLASSIC_WIDTH
, LEVEL_CLASSIC_HEIGHT
);
160 // player_add_new(gm);
161 // screen_set_num_viewports(2);
162 // screen_reset_gamma();
165 screen_set_num_viewports(1);
166 audio_play_music("sfx/hummingbird.ogg");
170 menu_resolution(game
);
189 void menu_resolution(struct game
*game
)
191 struct menu_entry menu_resolution
[] =
193 { "gfx/640-480-high.tga", "gfx/640-480-low.tga", NULL
, NULL
},
194 { "gfx/800-600-high.tga", "gfx/800-600-low.tga", NULL
, NULL
},
195 { "gfx/1024-768-high.tga", "gfx/1024-768-low.tga", NULL
, NULL
},
196 { "gfx/1400-1050-high.tga", "gfx/1400-1050-low.tga", NULL
, NULL
}
198 int menu_resolution_num
= 4;
199 int ret
, c
, width
, new_w
= 0, height
, new_h
= 0;
200 int current_selection
= 0;
202 for(c
= 0; c
< menu_resolution_num
; c
++)
204 menu_resolution
[c
].image_high
= gfx_get(menu_resolution
[c
].image_name_high
);
205 if(menu_resolution
[c
].image_high
->id
== -1)
207 gfx_alpha_from_key(menu_resolution
[c
].image_name_high
, 0, 0, 0);
208 gfx_upload_texture(menu_resolution
[c
].image_name_high
);
211 menu_resolution
[c
].image_low
= gfx_get(menu_resolution
[c
].image_name_low
);
212 if(menu_resolution
[c
].image_low
->id
== -1)
214 gfx_alpha_from_key(menu_resolution
[c
].image_name_low
, 0, 0, 0);
215 gfx_upload_texture(menu_resolution
[c
].image_name_low
);
219 screen_get_resolution(&width
, &height
);
222 current_selection
= 0;
225 current_selection
= 1;
228 current_selection
= 2;
231 current_selection
= 3;
234 current_selection
= 0;
238 while ((ret
= menu(game
, menu_resolution
,
239 menu_resolution_num
, current_selection
)) != -1) {
265 current_selection
= ret
;
266 screen_set_resolution(new_w
, new_h
);
267 screen_switch_resolution();
271 void menu_high_scores(void)
276 int menu(struct game
*game
, struct menu_entry
*m
, int n
, int cur
)
280 struct image_rgba32
*banner
;
286 banner
= gfx_get("gfx/pacman-arena-banner.tga");
289 gfx_alpha_from_key("gfx/pacman-arena-banner.tga", 0, 0, 0);
290 gfx_upload_texture("gfx/pacman-arena-banner.tga");
295 game_load_level(LEVEL_DEMO);
296 camera_type = CAMERA_TYPE_DEMO;
301 vp
= screen_get_viewport(0);
303 last_update
= SDL_GetTicks();
307 int diff
, top
, left
, width
, height
;
311 if(input_kstate(SDLK_ESCAPE
))
313 input_kclear(SDLK_ESCAPE
);
317 if(input_kstate(SDLK_RETURN
))
319 input_kclear(SDLK_RETURN
);
324 if(input_kstate(SDLK_DOWN
))
326 input_kclear(SDLK_DOWN
);
327 selected
= (selected
+ 1) % n
;
331 if(input_kstate(SDLK_UP
))
333 input_kclear(SDLK_UP
);
334 selected
= (selected
+ n
- 1) % n
;
337 diff
= SDL_GetTicks() - last_update
;
341 game_update(game
, (float)diff
/ 1000);
342 last_update
= SDL_GetTicks();
344 // screen_update_gamma((float)diff / 1000);
345 render_start_frame();
346 render_setup(game
, -1);
347 map_render_opaque_objects(game
);
348 game_draw_opaque_objects(game
, -1);
349 game_draw_translucent_objects(game
, -1);
350 map_render_translucent_objects(game
, -1);
354 top
= vp
->height
/ 2 - vp
->height
/ 5;
359 for(c
= 0; c
< n
; c
++)
363 if(m
[c
].image_high
->width
> width
)
364 width
= m
[c
].image_high
->width
;
366 height
+= m
[c
].image_high
->height
+ 20;
369 if(m
[c
].image_low
->width
> width
)
370 width
= m
[c
].image_low
->width
;
372 height
+= m
[c
].image_low
->height
+ 20;
377 left
= vp
->width
/ 2 - width
/ 2;
379 glDisable(GL_TEXTURE_2D
);
381 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
382 glColor4f(0.0, 0.0, 0.0, 0.5);
385 glVertex2i(left
, top
);
386 glVertex2i(left
+ width
, top
);
387 glVertex2i(left
+ width
, top
+ height
);
388 glVertex2i(left
, top
+ height
);
391 for(c
= 0; c
< n
; c
++)
395 render_draw_scaled_image(
396 m
[c
].image_name_high
,
397 vp
->width
/ 2 - m
[c
].image_high
->width
/ 2,
399 vp
->width
/ 2 + m
[c
].image_high
->width
/ 2,
400 top
+ m
[c
].image_high
->height
);
402 top
+= m
[c
].image_high
->height
+ 20;
403 height
+= m
[c
].image_high
->height
+ 20;
405 render_draw_scaled_image(
407 vp
->width
/ 2 - m
[c
].image_low
->width
/ 2,
409 vp
->width
/ 2 + m
[c
].image_low
->width
/ 2,
410 top
+ m
[c
].image_low
->height
);
412 top
+= m
[c
].image_low
->height
+ 20;
413 height
+= m
[c
].image_high
->height
+ 20;
418 render_draw_scaled_image("gfx/pacman-arena-banner.tga", 0, 0,
419 vp
->width
, vp
->width
* banner
->height
/ banner
->width
);
421 render_finish_frame();