From 3e17070298c097ab52c2934ba752d15d53ca210d Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Fri, 6 Apr 2012 18:25:04 +0200 Subject: [PATCH] better structure of level-moonwalk relationship --- src/level.c | 44 +++++++++++++++++++++++++++++++++++++------- src/level.h | 1 + src/moonwalk.c | 19 ++----------------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/level.c b/src/level.c index e20fa4d..d257992 100644 --- a/src/level.c +++ b/src/level.c @@ -20,32 +20,62 @@ */ #include #include "moonwalk.h" +#include "config.h" +#include "pause.h" #include "level.h" +void Level_Passed(struct Game *game) { + if (game->level.current_level<6) { + int available = atoi(GetConfigOptionDefault("MuffinAttack", "level", "1")); + available++; + if ((available<2) || (available>7)) available=1; + if (available==(game->level.current_level+1)) { + char* text = malloc(2*sizeof(char)); + sprintf(text, "%d", available); + SetConfigOption("MuffinAttack", "level", text); + free(text); + } + } else { + SetConfigOption("MuffinAttack", "completed", "1"); + } +} + void Level_Draw(struct Game *game) { - Moonwalk_Draw(game); + if (game->level.current_level!=1) Moonwalk_Draw(game); + else { + al_clear_to_color(al_map_rgb(0,0,0)); + } } void Level_Load(struct Game *game) { - Moonwalk_Load(game); + if (game->level.current_level!=1) Moonwalk_Load(game); } int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { - return Moonwalk_Keydown(game, ev); + if (game->level.current_level!=1) Moonwalk_Keydown(game, ev); + if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) { + game->gamestate = GAMESTATE_PAUSE; + game->loadstate = GAMESTATE_LEVEL; + Pause_Load(game); + } + return 0; } void Level_Preload(struct Game *game) { - Moonwalk_Preload(game); + Pause_Preload(game); + if (game->level.current_level!=1) Moonwalk_Preload(game); } void Level_Unload(struct Game *game) { - Moonwalk_Unload(game); + Pause_Unload_Real(game); + if (game->level.current_level!=1) Moonwalk_Unload(game); + else Level_Passed(game); } void Level_UnloadBitmaps(struct Game *game) { - Moonwalk_UnloadBitmaps(game); + if (game->level.current_level!=1) Moonwalk_UnloadBitmaps(game); } void Level_PreloadBitmaps(struct Game *game) { - Moonwalk_PreloadBitmaps(game); + if (game->level.current_level!=1) Moonwalk_PreloadBitmaps(game); } diff --git a/src/level.h b/src/level.h index 350549c..d408710 100644 --- a/src/level.h +++ b/src/level.h @@ -20,6 +20,7 @@ */ #include "main.h" +void Level_Passed(struct Game *game); void Level_Draw(struct Game *game); void Level_Preload(struct Game *game); void Level_Unload(struct Game *game); diff --git a/src/moonwalk.c b/src/moonwalk.c index 61a007f..7fac070 100644 --- a/src/moonwalk.c +++ b/src/moonwalk.c @@ -20,9 +20,8 @@ */ #include #include -#include "pause.h" +#include "level.h" #include "moonwalk.h" -#include "config.h" void Moonwalk_Draw(struct Game *game) { if (!al_get_sample_instance_playing(game->level.moonwalk.music) && (game->loadstate==GAMESTATE_LEVEL)) { @@ -36,17 +35,8 @@ void Moonwalk_Draw(struct Game *game) { game->level.moonwalk.derpy_pos=game->level.moonwalk.derpy_pos+tps(game, 60*0.00092); if (game->level.moonwalk.derpy_pos>1) { UnloadGameState(game); + Level_Passed(game); if (game->level.current_level<6) { - - int available = atoi(GetConfigOptionDefault("MuffinAttack", "level", "1")); - available++; - if ((available<2) || (available>7)) available=1; - if (available==(game->level.current_level+1)) { - char* text = malloc(2*sizeof(char)); - sprintf(text, "%d", available); - SetConfigOption("MuffinAttack", "level", text); - free(text); - } game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_MAP; //LoadGameState(game); @@ -93,9 +83,6 @@ int Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) { game->level.moonwalk.music_pos = al_get_sample_instance_position(game->level.moonwalk.music); al_set_sample_instance_playing(game->level.moonwalk.music, false); - game->gamestate = GAMESTATE_PAUSE; - game->loadstate = GAMESTATE_LEVEL; - Pause_Load(game); } return 0; } @@ -127,7 +114,6 @@ void Moonwalk_Preload(struct Game *game) { } Moonwalk_PreloadBitmaps(game); - Pause_Preload(game); } void Moonwalk_UnloadBitmaps(struct Game *game) { @@ -137,7 +123,6 @@ void Moonwalk_UnloadBitmaps(struct Game *game) { } void Moonwalk_Unload(struct Game *game) { - Pause_Unload_Real(game); ALLEGRO_EVENT ev; game->level.moonwalk.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); al_set_target_bitmap(game->level.moonwalk.fade_bitmap);