From dd822e5b9d736dfc472dee6d3d3bd657a1020e3a Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Tue, 21 Feb 2012 23:33:02 +0100 Subject: [PATCH] work on map state --- src/main.c | 4 ++-- src/main.h | 8 ++++--- src/map.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 8c0ddee..cf85b98 100644 --- a/src/main.c +++ b/src/main.c @@ -67,7 +67,7 @@ void PreloadGameState(struct Game *game) { al_flip_display(); Map_Preload(game); } else { - PrintConsole(game, "ERROR: Attempted to preload unknown gamestate %d!", game->gamestate); + PrintConsole(game, "ERROR: Attempted to preload unknown gamestate %d!", game->loadstate); } PrintConsole(game, "finished"); } @@ -119,7 +119,7 @@ void LoadGameState(struct Game *game) { PrintConsole(game, "Load GAMESTATE_MAP..."); Map_Load(game); } else { - PrintConsole(game, "ERROR: Attempted to load unknown gamestate %d!", game->gamestate); + PrintConsole(game, "ERROR: Attempted to load unknown gamestate %d!", game->loadstate); } PrintConsole(game, "finished"); game->gamestate = game->loadstate; diff --git a/src/main.h b/src/main.h index 8baca87..4525973 100644 --- a/src/main.h +++ b/src/main.h @@ -13,7 +13,8 @@ enum gamestate_enum { GAMESTATE_MENU, GAMESTATE_ABOUT, GAMESTATE_INTRO, - GAMESTATE_MAP + GAMESTATE_MAP, + GAMESTATE_LEVEL }; struct Menu { @@ -39,9 +40,10 @@ struct About { }; struct Map { - ALLEGRO_BITMAP *map, *background, *map_bg, *highlight; + ALLEGRO_BITMAP *map, *background, *map_bg, *highlight, *arrow; int selected, available; - ALLEGRO_SAMPLE *sample; + float arrowpos; + ALLEGRO_SAMPLE *sample, *click_sample; }; struct Intro { diff --git a/src/map.c b/src/map.c index 503be6b..d78d433 100644 --- a/src/map.c +++ b/src/map.c @@ -1,10 +1,40 @@ #include #include #include +#include #include "map.h" void Map_Draw(struct Game *game) { al_draw_bitmap(game->map.map, 0, 0, 0); + float x,y; + switch (game->map.selected) { + case 1: + x=0.18; + y=0.225; + break; + case 2: + x=0.5; + y=0.3125; + break; + case 3: + x=0.738; + y=0.425; + break; + case 4: + x=0.61; + y=0.7625; + break; + case 5: + x=0.17; + y=0.725; + break; + case 6: + x=0.41; + y=0.518; + break; + } + al_draw_scaled_bitmap(game->map.arrow, 0, 0, al_get_bitmap_width(game->map.arrow), al_get_bitmap_height(game->map.arrow), al_get_display_width(game->display)*x, al_get_display_height(game->display)*y + ((sin(game->map.arrowpos)+0.5)/20.0)*al_get_display_height(game->display), al_get_display_width(game->display)*0.1, al_get_display_height(game->display)*0.16, 0); + game->map.arrowpos += 0.1; } void Map_Load(struct Game *game) { @@ -19,20 +49,41 @@ void Map_Load(struct Game *game) { Map_Draw(game); } int Map_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { - //if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) { + if ((((game->map.selected<4) || (game->map.selected==6)) && (ev->keyboard.keycode==ALLEGRO_KEY_LEFT)) || ((game->map.selected>4) && (game->map.selected!=6) && (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT)) || ((game->map.selected==4) && (ev->keyboard.keycode==ALLEGRO_KEY_UP)) || ((game->map.selected==6) && (ev->keyboard.keycode==ALLEGRO_KEY_DOWN))) { + game->map.selected--; + al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + } else if (((game->map.selected<3) && (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT)) || ((game->map.selected==4) && (ev->keyboard.keycode==ALLEGRO_KEY_LEFT)) || ((game->map.selected==3) && (ev->keyboard.keycode==ALLEGRO_KEY_DOWN)) || ((game->map.selected==5) && (ev->keyboard.keycode==ALLEGRO_KEY_UP))) { + game->map.selected++; + al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + } else if ((ev->keyboard.keycode==ALLEGRO_KEY_LEFT) || (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT) || (ev->keyboard.keycode==ALLEGRO_KEY_UP) || (ev->keyboard.keycode==ALLEGRO_KEY_DOWN)) { + al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + } else if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) { + PrintConsole(game, "Selecting level %d...", game->map.selected); + UnloadGameState(game); + game->gamestate = GAMESTATE_LOADING; + game->loadstate = GAMESTATE_LEVEL; + return 0; + } else if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) { UnloadGameState(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_MENU; return 0; - //} + } else { return 0; } + if (game->map.selected<1) game->map.selected=1; + if (game->map.selected>game->map.available) game->map.selected=game->map.available; + return 0; } void Map_Preload(struct Game *game) { game->map.available = 6; game->map.selected = game->map.available; + PrintConsole(game, "Last level available: %d", game->map.selected); + game->map.arrowpos = 0; game->map.map = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); game->map.background = al_load_bitmap( "data/table.png" ); game->map.map_bg = al_load_bitmap( "data/map/background.png" ); + game->map.arrow = al_load_bitmap( "data/arrow.png" ); + game->map.click_sample = al_load_sample( "data/click.flac" ); char filename[30] = { }; sprintf(filename, "data/map/highlight%d.png", game->map.available); game->map.highlight = al_load_bitmap( filename ); @@ -42,6 +93,10 @@ void Map_Preload(struct Game *game) { fprintf(stderr, "Audio clip sample not loaded!\n" ); exit(-1); } + if (!game->map.click_sample){ + fprintf(stderr, "Audio clip sample#2 not loaded!\n" ); + exit(-1); + } al_set_target_bitmap(game->map.map); al_draw_scaled_bitmap(game->map.background,0,0,al_get_bitmap_width(game->map.background),al_get_bitmap_height(game->map.background),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0); @@ -61,5 +116,7 @@ void Map_Unload(struct Game *game) { al_destroy_bitmap(game->map.background); al_destroy_bitmap(game->map.map_bg); al_destroy_bitmap(game->map.highlight); + al_destroy_bitmap(game->map.arrow); al_destroy_sample(game->map.sample); + al_destroy_sample(game->map.click_sample); }