menu is now really menu (but all of options lead to exit :))

This commit is contained in:
Sebastian Krzyszkowiak 2012-02-16 23:36:25 +01:00
parent 6fc7999ea2
commit 4bebe71fa6
6 changed files with 52 additions and 5 deletions

View file

@ -35,4 +35,6 @@ void Loading_Load(struct Game *game) {
al_draw_text(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.0234, al_get_display_height(game->display)*0.85, ALLEGRO_ALIGN_LEFT, "Loading...");
al_set_target_bitmap(al_get_backbuffer(game->display));
al_destroy_bitmap(game->loading.image);
}
}
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; }

View file

@ -1,4 +1,5 @@
#include "main.h"
void Loading_Draw(struct Game *game);
void Loading_Load(struct Game *game);
void Loading_Load(struct Game *game);
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev);

10
main.c
View file

@ -122,9 +122,17 @@ int main(int argc, char **argv){
if(ev.type == ALLEGRO_EVENT_TIMER) {
redraw = true;
}
else if((ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) || (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)) {
else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
}
else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
if (game.gamestate==GAMESTATE_LOADING) {
if (Loading_Keydown(&game, &ev)) break;
}
else if (game.gamestate==GAMESTATE_MENU) {
if (Menu_Keydown(&game, &ev)) break;
}
}
if(redraw && al_is_event_queue_empty(game.event_queue)) {
redraw = false;

3
main.h
View file

@ -21,7 +21,8 @@ struct Menu {
float cloud_position, cloud2_position;
int mountain_position;
ALLEGRO_SAMPLE *sample, *rain_sample;
ALLEGRO_FONT *font_title, *font_subtitle;
ALLEGRO_FONT *font_title, *font_subtitle, *font, *font_selected;
int selected;
};
struct Loading {

34
menu.c
View file

@ -33,6 +33,17 @@ void Menu_Draw(struct Game *game) {
al_draw_text(game->menu.font_title, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, ALLEGRO_ALIGN_CENTRE, "Super Derpy");
al_draw_text(game->menu.font_subtitle, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.275, ALLEGRO_ALIGN_CENTRE, "Muffin Attack");
ALLEGRO_FONT *font;
font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected;
al_draw_text(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.5, ALLEGRO_ALIGN_CENTRE, "Start game");
font = game->menu.font; if (game->menu.selected==1) font = game->menu.font_selected;
al_draw_text(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.6, ALLEGRO_ALIGN_CENTRE, "Options");
font = game->menu.font; if (game->menu.selected==2) font = game->menu.font_selected;
al_draw_text(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.7, ALLEGRO_ALIGN_CENTRE, "About");
font = game->menu.font; if (game->menu.selected==3) font = game->menu.font_selected;
al_draw_text(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.8, ALLEGRO_ALIGN_CENTRE, "Exit");
game->menu.cloud_position-=0.1;
game->menu.cloud2_position-=0.025;
if (game->menu.cloud_position<-80) game->menu.cloud_position=100;
@ -58,6 +69,8 @@ void Menu_Preload(struct Game *game) {
game->menu.font_title = al_load_ttf_font("ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.16,0 );
game->menu.font_subtitle = al_load_ttf_font("ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.08,0 );
game->menu.font = al_load_ttf_font("ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.05,0 );
game->menu.font_selected = al_load_ttf_font("ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.065,0 );
if (!game->menu.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
@ -113,6 +126,12 @@ void Menu_Preload(struct Game *game) {
al_draw_text(game->menu.font_title, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, ALLEGRO_ALIGN_CENTRE, "Super Derpy");
al_draw_text(game->menu.font_subtitle, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.275, ALLEGRO_ALIGN_CENTRE, "Muffin Attack");
game->menu.selected = 0;
al_draw_text(game->menu.font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.5, ALLEGRO_ALIGN_CENTRE, "Start game");
al_draw_text(game->menu.font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.6, ALLEGRO_ALIGN_CENTRE, "Options");
al_draw_text(game->menu.font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.7, ALLEGRO_ALIGN_CENTRE, "About");
al_draw_text(game->menu.font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.8, ALLEGRO_ALIGN_CENTRE, "Exit");
al_set_target_bitmap(al_get_backbuffer(game->display));
}
@ -136,6 +155,8 @@ void Menu_Unload(struct Game *game) {
al_destroy_bitmap(game->menu.pie_bitmap);
al_destroy_font(game->menu.font_title);
al_destroy_font(game->menu.font_subtitle);
al_destroy_font(game->menu.font);
al_destroy_font(game->menu.font_selected);
}
void Menu_Load(struct Game *game) {
@ -147,4 +168,17 @@ void Menu_Load(struct Game *game) {
al_draw_tinted_bitmap(game->menu.menu_fade_bitmap,al_map_rgba_f(fadeloop/255.0,fadeloop/255.0,fadeloop/255.0,1),0,0,0);
al_flip_display();
}
}
int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
if (ev->keyboard.keycode==ALLEGRO_KEY_UP) {
game->menu.selected--;
} else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) {
game->menu.selected++;
} else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) || (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE)) {
return 1;
}
if (game->menu.selected==-1) game->menu.selected=3;
if (game->menu.selected==4) game->menu.selected=0;
return 0;
}

3
menu.h
View file

@ -3,4 +3,5 @@
void Menu_Draw(struct Game *game);
void Menu_Preload(struct Game *game);
void Menu_Unload(struct Game *game);
void Menu_Load(struct Game *game);
void Menu_Load(struct Game *game);
int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev);