diff --git a/src/gamestates/level.c b/src/gamestates/level.c index f7096e2..6ab5031 100644 --- a/src/gamestates/level.c +++ b/src/gamestates/level.c @@ -246,6 +246,13 @@ void Level_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) { TM_HandleEvent(ev); } +char* GetLevelFilename(struct Game *game, char* filename) { + char* name = strdup(filename); + char* ch = strchr(name, '?'); + ch[0] = '0' + game->level.current_level; + return name; +} + void Level_Preload(struct Game *game, void (*progress)(struct Game*, float)) { PrintConsole(game, "Initializing level %d...", game->level.input.current_level); @@ -256,8 +263,7 @@ void Level_Preload(struct Game *game, void (*progress)(struct Game*, float)) { Pause_Preload(game); RegisterDerpySpritesheet(game, "stand"); // default - //TODO: load proper music file for each level - game->level.sample = al_load_sample( GetDataFilePath("levels/1/music.flac") ); + game->level.sample = al_load_sample( GetDataFilePath(GetLevelFilename(game, "levels/?/music.flac")) ); LEVELS(Preload, game); @@ -347,14 +353,13 @@ void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, floa game->level.derpy = al_create_bitmap(al_get_bitmap_width(*(game->level.derpy_sheet))/game->level.sheet_cols, al_get_bitmap_height(*(game->level.derpy_sheet))/game->level.sheet_rows); - //TODO: load proper bitmap files for each level - game->level.clouds = LoadScaledBitmap("levels/1/clouds.png", game->viewportHeight*4.73307291666666666667, game->viewportHeight); + game->level.clouds = LoadScaledBitmap(GetLevelFilename(game, "levels/?/clouds.png"), game->viewportHeight*4.73307291666666666667, game->viewportHeight); PROGRESS; - game->level.foreground = LoadScaledBitmap("levels/1/foreground.png", game->viewportHeight*4.73307291666666666667, game->viewportHeight); + game->level.foreground = LoadScaledBitmap(GetLevelFilename(game, "levels/?/foreground.png"), game->viewportHeight*4.73307291666666666667, game->viewportHeight); PROGRESS; - game->level.background = LoadScaledBitmap("levels/1/background.png", game->viewportHeight*4.73307291666666666667, game->viewportHeight); + game->level.background = LoadScaledBitmap(GetLevelFilename(game, "levels/?/background.png"), game->viewportHeight*4.73307291666666666667, game->viewportHeight); PROGRESS; - game->level.stage = LoadScaledBitmap("levels/1/stage.png", game->viewportHeight*4.73307291666666666667, game->viewportHeight); + game->level.stage = LoadScaledBitmap(GetLevelFilename(game, "levels/?/stage.png"), game->viewportHeight*4.73307291666666666667, game->viewportHeight); PROGRESS; game->level.meter_image = LoadScaledBitmap("levels/meter.png", game->viewportWidth*0.075, game->viewportWidth*0.075*0.96470588235294117647); PROGRESS; diff --git a/src/gamestates/level.h b/src/gamestates/level.h index 76f827f..7669cc5 100644 --- a/src/gamestates/level.h +++ b/src/gamestates/level.h @@ -34,3 +34,4 @@ void Level_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev); int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev); void Level_UnloadBitmaps(struct Game *game); void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)); +char* GetLevelFilename(struct Game *game, char* filename); diff --git a/src/gamestates/menu.c b/src/gamestates/menu.c index e0c5229..dce9b55 100644 --- a/src/gamestates/menu.c +++ b/src/gamestates/menu.c @@ -220,7 +220,7 @@ void Menu_Preload(struct Game *game, void (*progress)(struct Game*, float)) { al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); game->menu.rain = al_load_bitmap( GetDataFilePath("menu/rain.png") ); PROGRESS; - game->menu.pie = al_load_bitmap( GetDataFilePath("levels/pie1.png") ); + game->menu.pie = al_load_bitmap( GetDataFilePath("menu/pie.png") ); al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR); PROGRESS; diff --git a/src/levels/actions.c b/src/levels/actions.c index 10e81c6..7dc9b9d 100644 --- a/src/levels/actions.c +++ b/src/levels/actions.c @@ -162,3 +162,51 @@ bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState } return true; } + +bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { + if (state == TM_ACTIONSTATE_INIT) action->arguments = NULL; + if (state == TM_ACTIONSTATE_DESTROY) { + ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; + al_set_audio_stream_playing(*stream, false); + al_destroy_audio_stream(*stream); + free(action->arguments->next->value); + free(action->arguments->value); + TM_DestroyArgs(action->arguments); + } + if (state == TM_ACTIONSTATE_DRAW) { + float* f = (float*)action->arguments->value; + al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); + return false; + } + else if (state == TM_ACTIONSTATE_PAUSE) { + ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; + al_set_audio_stream_playing(*stream, false); + } else if (state == TM_ACTIONSTATE_RESUME) { + ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; + al_set_audio_stream_playing(*stream, true); + } + if (state != TM_ACTIONSTATE_RUNNING) return false; + if (!action->arguments) { + action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); + float* f = (float*)action->arguments->value; + *f = 0; + action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(ALLEGRO_AUDIO_STREAM*))); + ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; + *stream = al_load_audio_stream(GetDataFilePath("levels/1/letter.flac"), 4, 1024); + al_attach_audio_stream_to_mixer(*stream, game->audio.voice); + al_set_audio_stream_playing(*stream, true); + al_set_audio_stream_gain(*stream, 2.00); + action->arguments->next->next = NULL; + } + float* f = (float*)action->arguments->value; + *f+=5; + if (*f>255) *f=255; + al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); + struct ALLEGRO_KEYBOARD_STATE keyboard; + al_get_keyboard_state(&keyboard); + // FIXME: do it the proper way + if (al_key_down(&keyboard, ALLEGRO_KEY_ENTER)) { + return true; + } + return false; +} diff --git a/src/levels/actions.h b/src/levels/actions.h index 6a2e07c..63baf78 100644 --- a/src/levels/actions.h +++ b/src/levels/actions.h @@ -42,3 +42,6 @@ bool Welcome(struct Game *game, struct TM_Action *action, enum TM_ActionState st /*! \brief Pass level and fade-out after few seconds. */ bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState state); + +/*! \brief Shows letter from Twilight on screen. */ +bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state); diff --git a/src/levels/level1.c b/src/levels/level1.c index bf1eed1..326db80 100644 --- a/src/levels/level1.c +++ b/src/levels/level1.c @@ -99,11 +99,11 @@ inline int Level1_PreloadSteps() { void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) { PROGRESS_INIT(Level1_PreloadSteps()); - game->level.owl = LoadScaledBitmap("levels/owl.png", game->viewportWidth*0.08, game->viewportWidth*0.08); + game->level.owl = LoadScaledBitmap("levels/1/owl.png", game->viewportWidth*0.08, game->viewportWidth*0.08); PROGRESS; game->level.letter_font = al_load_ttf_font(GetDataFilePath("fonts/DejaVuSans.ttf"),game->viewportHeight*0.0225,0 ); PROGRESS; - game->level.letter = LoadScaledBitmap("levels/letter.png", game->viewportHeight*1.3, game->viewportHeight*1.2); + game->level.letter = LoadScaledBitmap("levels/1/letter.png", game->viewportHeight*1.3, game->viewportHeight*1.2); al_set_target_bitmap(game->level.letter); float y = 0.20; float x = 0.19; diff --git a/src/levels/modules/dodger.c b/src/levels/modules/dodger.c index 976e832..efe5272 100644 --- a/src/levels/modules/dodger.c +++ b/src/levels/modules/dodger.c @@ -224,19 +224,19 @@ inline int Dodger_PreloadSteps() { void Dodger_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) { PROGRESS_INIT(Dodger_PreloadSteps()); - game->level.dodger.obst_bmps.pie1 = LoadScaledBitmap("levels/pie1.png", game->viewportWidth*0.1, game->viewportHeight*0.08); + game->level.dodger.obst_bmps.pie1 = LoadScaledBitmap("levels/dodger/pie1.png", game->viewportWidth*0.1, game->viewportHeight*0.08); PROGRESS; - game->level.dodger.obst_bmps.pie2 = LoadScaledBitmap("levels/pie2.png", game->viewportWidth*0.1, game->viewportHeight*0.08); + game->level.dodger.obst_bmps.pie2 = LoadScaledBitmap("levels/dodger/pie2.png", game->viewportWidth*0.1, game->viewportHeight*0.08); PROGRESS; - game->level.dodger.obst_bmps.pig = LoadScaledBitmap("levels/pig.png", (int)(game->viewportWidth*0.15)*3, (int)(game->viewportHeight*0.2)*3); + game->level.dodger.obst_bmps.pig = LoadScaledBitmap("levels/dodger/pig.png", (int)(game->viewportWidth*0.15)*3, (int)(game->viewportHeight*0.2)*3); PROGRESS; - game->level.dodger.obst_bmps.screwball = LoadScaledBitmap("levels/screwball.png", (int)(game->viewportHeight*0.2)*4*1.4, (int)(game->viewportHeight*0.2)*4); + game->level.dodger.obst_bmps.screwball = LoadScaledBitmap("levels/dodger/screwball.png", (int)(game->viewportHeight*0.2)*4*1.4, (int)(game->viewportHeight*0.2)*4); PROGRESS; - game->level.dodger.obst_bmps.muffin = LoadScaledBitmap("levels/muffin.png", game->viewportWidth*0.07, game->viewportHeight*0.1); + game->level.dodger.obst_bmps.muffin = LoadScaledBitmap("levels/dodger/muffin.png", game->viewportWidth*0.07, game->viewportHeight*0.1); PROGRESS; - game->level.dodger.obst_bmps.cherry = LoadScaledBitmap("levels/cherry.png", game->viewportWidth*0.03, game->viewportHeight*0.08); + game->level.dodger.obst_bmps.cherry = LoadScaledBitmap("levels/dodger/cherry.png", game->viewportWidth*0.03, game->viewportHeight*0.08); PROGRESS; - game->level.dodger.obst_bmps.badmuffin = LoadScaledBitmap("levels/badmuffin.png", game->viewportWidth*0.07, game->viewportHeight*0.1); + game->level.dodger.obst_bmps.badmuffin = LoadScaledBitmap("levels/dodger/badmuffin.png", game->viewportWidth*0.07, game->viewportHeight*0.1); PROGRESS; } diff --git a/src/levels/modules/dodger/actions.c b/src/levels/modules/dodger/actions.c index 6ff69a4..e496411 100644 --- a/src/levels/modules/dodger/actions.c +++ b/src/levels/modules/dodger/actions.c @@ -179,51 +179,3 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti } return false; } - -bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { - if (state == TM_ACTIONSTATE_INIT) action->arguments = NULL; - if (state == TM_ACTIONSTATE_DESTROY) { - ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; - al_set_audio_stream_playing(*stream, false); - al_destroy_audio_stream(*stream); - free(action->arguments->next->value); - free(action->arguments->value); - TM_DestroyArgs(action->arguments); - } - if (state == TM_ACTIONSTATE_DRAW) { - float* f = (float*)action->arguments->value; - al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); - return false; - } - else if (state == TM_ACTIONSTATE_PAUSE) { - ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; - al_set_audio_stream_playing(*stream, false); - } else if (state == TM_ACTIONSTATE_RESUME) { - ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; - al_set_audio_stream_playing(*stream, true); - } - if (state != TM_ACTIONSTATE_RUNNING) return false; - if (!action->arguments) { - action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); - float* f = (float*)action->arguments->value; - *f = 0; - action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(ALLEGRO_AUDIO_STREAM*))); - ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; - *stream = al_load_audio_stream(GetDataFilePath("levels/letter.flac"), 4, 1024); - al_attach_audio_stream_to_mixer(*stream, game->audio.voice); - al_set_audio_stream_playing(*stream, true); - al_set_audio_stream_gain(*stream, 2.00); - action->arguments->next->next = NULL; - } - float* f = (float*)action->arguments->value; - *f+=5; - if (*f>255) *f=255; - al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); - struct ALLEGRO_KEYBOARD_STATE keyboard; - al_get_keyboard_state(&keyboard); - // FIXME: do it the proper way - if (al_key_down(&keyboard, ALLEGRO_KEY_ENTER)) { - return true; - } - return false; -} diff --git a/src/levels/modules/dodger/actions.h b/src/levels/modules/dodger/actions.h index dd4cc96..26888fc 100644 --- a/src/levels/modules/dodger/actions.h +++ b/src/levels/modules/dodger/actions.h @@ -39,6 +39,3 @@ bool Run(struct Game *game, struct TM_Action *action, enum TM_ActionState state) /*! \brief Generates obstacles. */ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_ActionState state); - -/*! \brief Shows letter from Twilight on screen. */ -bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state); diff --git a/src/levels/modules/moonwalk.c b/src/levels/modules/moonwalk.c index 84f2a17..8ae1ad6 100644 --- a/src/levels/modules/moonwalk.c +++ b/src/levels/modules/moonwalk.c @@ -76,15 +76,9 @@ inline int Moonwalk_PreloadSteps() { void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) { PROGRESS_INIT(Moonwalk_PreloadSteps()); - // nasty hack: overwrite level backgrounds - al_destroy_bitmap(game->level.background); - al_destroy_bitmap(game->level.foreground); + // nasty hack: overwrite level background al_destroy_bitmap(game->level.stage); - al_destroy_bitmap(game->level.clouds); - game->level.background=al_create_bitmap(0,0); - game->level.foreground=al_create_bitmap(0,0); - game->level.clouds=al_create_bitmap(0,0); - game->level.stage = LoadScaledBitmap("levels/disco.jpg", game->viewportWidth, game->viewportHeight); + game->level.stage = LoadScaledBitmap("levels/moonwalk/disco.jpg", game->viewportWidth, game->viewportHeight); PROGRESS; al_set_target_bitmap(al_get_backbuffer(game->display)); } @@ -93,7 +87,7 @@ void Moonwalk_Preload(struct Game *game) { RegisterDerpySpritesheet(game, "walk"); // nasty hack: overwrite level music al_destroy_sample(game->level.sample); - game->level.sample = al_load_sample( GetDataFilePath("levels/moonwalk.flac") ); + game->level.sample = al_load_sample( GetDataFilePath("levels/moonwalk/moonwalk.flac") ); } void Moonwalk_UnloadBitmaps(struct Game *game) {}