diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f99863..a48f80e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,16 +1,17 @@ SET(SRC_LIST - about.c - allegro_utils.c + main.c + allegro_utils.c config.c - disclaimer.c - intro.c - level.c - loading.c - main.c - map.c - menu.c - pause.c - timeline.c + timeline.c + gamestates/about.c + gamestates/disclaimer.c + gamestates/intro.c + gamestates/level.c + gamestates/loading.c + gamestates/map.c + gamestates/menu.c + gamestates/pause.c + levels/level1.c levels/moonwalk.c levels/dodger.c levels/actions.c diff --git a/src/about.c b/src/gamestates/about.c similarity index 100% rename from src/about.c rename to src/gamestates/about.c diff --git a/src/about.h b/src/gamestates/about.h similarity index 98% rename from src/about.h rename to src/gamestates/about.h index 893b4e8..8762369 100644 --- a/src/about.h +++ b/src/gamestates/about.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void About_Draw(struct Game *game); void About_Logic(struct Game *game); diff --git a/src/disclaimer.c b/src/gamestates/disclaimer.c similarity index 100% rename from src/disclaimer.c rename to src/gamestates/disclaimer.c diff --git a/src/disclaimer.h b/src/gamestates/disclaimer.h similarity index 98% rename from src/disclaimer.h rename to src/gamestates/disclaimer.h index 7bf5927..e5308bb 100644 --- a/src/disclaimer.h +++ b/src/gamestates/disclaimer.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void Disclaimer_Draw(struct Game *game); void Disclaimer_Preload(struct Game *game, void (*progress)(struct Game*, float)); diff --git a/src/intro.c b/src/gamestates/intro.c similarity index 99% rename from src/intro.c rename to src/gamestates/intro.c index a17e7a9..6b881ef 100644 --- a/src/intro.c +++ b/src/gamestates/intro.c @@ -251,8 +251,7 @@ void Intro_Preload(struct Game *game, void (*progress)(struct Game*, float)) { PrintConsole(game, "Chainpreloading GAMESTATE_MAP..."); PROGRESS; void MapProgress(struct Game* game, float p) { - /* if (progress) (*progress)(game, load_p+=1/load_a); */ - if (progress) (*progress)(game, 0.625+0.375*p); + if (progress) (*progress)(game, load_p+=1/load_a); } Map_Preload(game, &MapProgress); } diff --git a/src/intro.h b/src/gamestates/intro.h similarity index 98% rename from src/intro.h rename to src/gamestates/intro.h index a8a433e..b0585da 100644 --- a/src/intro.h +++ b/src/gamestates/intro.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void Intro_Draw(struct Game *game); void Intro_Logic(struct Game *game); diff --git a/src/level.c b/src/gamestates/level.c similarity index 71% rename from src/level.c rename to src/gamestates/level.c index d80973e..32dbe03 100644 --- a/src/level.c +++ b/src/gamestates/level.c @@ -20,14 +20,12 @@ */ #include #include -#include "levels/actions.h" -#include "levels/dodger/actions.h" -#include "levels/moonwalk.h" -#include "levels/dodger.h" -#include "config.h" +#include "../levels/moonwalk.h" +#include "../levels/level1.h" +#include "../config.h" #include "pause.h" #include "level.h" -#include "timeline.h" +#include "../timeline.h" void SelectDerpySpritesheet(struct Game *game, char* name) { struct Spritesheet *tmp = game->level.derpy_sheets; @@ -109,7 +107,7 @@ void Level_Passed(struct Game *game) { void Level_Logic(struct Game *game) { if (game->level.current_level==1) { - Dodger_Logic(game); + Level1_Logic(game); } else { Moonwalk_Logic(game); } @@ -146,7 +144,7 @@ void Level_Logic(struct Game *game) { void Level_Resume(struct Game *game) { al_set_sample_instance_position(game->level.music, game->level.music_pos); al_set_sample_instance_playing(game->level.music, true); - if (game->level.current_level==1) Dodger_Resume(game); + if (game->level.current_level==1) Level1_Resume(game); else Moonwalk_Resume(game); TM_Resume(); } @@ -154,7 +152,7 @@ void Level_Resume(struct Game *game) { void Level_Pause(struct Game *game) { game->level.music_pos = al_get_sample_instance_position(game->level.music); al_set_sample_instance_playing(game->level.music, false); - if (game->level.current_level==1) Dodger_Pause(game); + if (game->level.current_level==1) Level1_Pause(game); else Moonwalk_Pause(game); TM_Pause(); } @@ -167,7 +165,7 @@ void Level_Draw(struct Game *game) { al_draw_bitmap(game->level.stage, (-game->level.st_pos)*al_get_bitmap_width(game->level.stage), 0 ,0); al_draw_bitmap(game->level.stage, (1+(-game->level.st_pos))*al_get_bitmap_width(game->level.stage), 0 ,0); - if (game->level.current_level==1) Dodger_Draw(game); + if (game->level.current_level==1) Level1_Draw(game); else Moonwalk_Draw(game); if (!game->level.foreground) return; @@ -188,6 +186,7 @@ void Level_Draw(struct Game *game) { TM_Draw(); } + void Level_Load(struct Game *game) { game->level.failed=false; game->level.hp=1; @@ -209,58 +208,7 @@ void Level_Load(struct Game *game) { TM_Init(game); if (game->level.current_level!=1) Moonwalk_Load(game); else { - Dodger_Load(game); - // TODO: move to level 1 specific function - TM_AddBackgroundAction(&FadeIn, NULL, 0, "fadein"); - TM_AddDelay(1000); - TM_AddQueuedBackgroundAction(&Welcome, NULL, 0, "welcome"); - TM_AddDelay(1000); - TM_AddAction(&Walk, NULL, "walk"); - TM_AddAction(&Move, NULL, "move"); - TM_AddAction(&Stop, NULL, "stop"); - TM_AddDelay(1000); - TM_AddAction(&Letter, NULL, "letter"); - TM_AddDelay(200); - TM_AddQueuedBackgroundAction(&Accelerate, NULL, 0, "accelerate"); - TM_AddAction(&Fly, NULL, "fly"); - TM_AddDelay(500); - /* first part gameplay goes here */ - - /* actions for generating obstacles should go here - * probably as regular actions. When one ends, harder one - * begins. After last one part with muffins starts. */ - TM_AddAction(&GenerateObstacles, NULL, "obstacles"); - TM_AddDelay(3*1000); - /* wings disappear, deccelerate */ - TM_AddAction(&Run, NULL, "run"); - TM_AddDelay(3*1000); - /* show Fluttershy's house - - // second part gameplay goes here - - // cutscene goes here */ - TM_AddAction(&PassLevel, NULL, "passlevel"); - - // init level specific obstacle for Dodger module - struct Obstacle *obst = malloc(sizeof(struct Obstacle)); - obst->prev = NULL; - obst->next = NULL; - obst->x = 83.5; - obst->y = 55; - obst->speed = 1; - obst->points = 0; - obst->hit = false; - obst->rows = 1; - obst->cols = 1; - obst->pos = 0; - obst->blanks = 0; - obst->anim_speed = 0; - obst->tmp_pos = 0; - obst->angle = 0; - obst->callback = NULL; - obst->data = NULL; - obst->bitmap = &(game->level.owl); - game->level.dodger.obstacles = obst; + Level1_Load(game); } } @@ -274,7 +222,7 @@ int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { } else if ((game->debug) && (ev->keyboard.keycode==ALLEGRO_KEY_F4)) { game->level.debug_show_sprite_frames = !game->level.debug_show_sprite_frames; } - if (game->level.current_level==1) Dodger_Keydown(game, ev); + if (game->level.current_level==1) Level1_Keydown(game, ev); else Moonwalk_Keydown(game, ev); if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) { game->gamestate = GAMESTATE_PAUSE; @@ -285,7 +233,7 @@ int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { } void Level_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) { - if (game->level.current_level==1) Dodger_ProcessEvent(game, ev); + if (game->level.current_level==1) Level1_ProcessEvent(game, ev); else Moonwalk_ProcessEvent(game, ev); TM_HandleEvent(ev); } @@ -303,8 +251,8 @@ void Level_Preload(struct Game *game, void (*progress)(struct Game*, float)) { //TODO: load proper music file for each level game->level.sample = al_load_sample( GetDataFilePath("levels/1/music.flac") ); - if (game->level.current_level==1) Dodger_Preload(game, progress); - else Moonwalk_Preload(game, progress); + if (game->level.current_level==1) Level1_Preload(game); + else Moonwalk_Preload(game); Level_PreloadBitmaps(game, progress); @@ -328,10 +276,11 @@ void Level_Unload(struct Game *game) { al_destroy_sample(game->level.sample); Level_UnloadBitmaps(game); if (game->level.current_level!=1) Moonwalk_Unload(game); - else Dodger_Unload(game); + else Level1_Unload(game); TM_Destroy(); } + void Level_UnloadBitmaps(struct Game *game) { al_destroy_bitmap(game->level.derpy); struct Spritesheet *tmp = game->level.derpy_sheets; @@ -340,13 +289,7 @@ void Level_UnloadBitmaps(struct Game *game) { tmp = tmp->next; } if (game->level.current_level!=1) Moonwalk_UnloadBitmaps(game); - else { - Dodger_UnloadBitmaps(game); - // TODO: move to level 1 specific function - al_destroy_font(game->level.letter_font); - al_destroy_bitmap(game->level.letter); - al_destroy_bitmap(game->level.owl); - } + else Level1_UnloadBitmaps(game); al_destroy_bitmap(game->level.foreground); al_destroy_bitmap(game->level.background); al_destroy_bitmap(game->level.clouds); @@ -357,17 +300,21 @@ void Level_UnloadBitmaps(struct Game *game) { game->level.foreground = NULL; } +int Level_PreloadSteps(struct Game *game) { + if (game->level.current_level==1) return Level1_PreloadSteps(); + else return Moonwalk_PreloadSteps(); +} + void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) { - PROGRESS_INIT(19); int x = 0; + struct Spritesheet *tmp = game->level.derpy_sheets; while (tmp) { x++; tmp = tmp->next; } - if (game->level.current_level==1) load_a+=x; - else load_a=9+x; - // FIXME: pleaaaaseee + + PROGRESS_INIT(8+x+Level_PreloadSteps(game)); tmp = game->level.derpy_sheets; while (tmp) { @@ -398,64 +345,10 @@ void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, floa PROGRESS; game->level.welcome = al_create_bitmap(game->viewportWidth, game->viewportHeight/2); PROGRESS; - al_set_target_bitmap(game->level.welcome); - al_clear_to_color(al_map_rgba(0,0,0,0)); - al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1"); - al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy"); - PROGRESS; - - if (game->level.current_level!=1) Moonwalk_PreloadBitmaps(game, progress); - else { - // TODO: move to level 1 specific function - game->level.owl = LoadScaledBitmap("levels/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); - al_set_target_bitmap(game->level.letter); - float y = 0.20; - float x = 0.19; - void draw_text(char* text) { - al_draw_text(game->level.letter_font, al_map_rgb(0,0,0), al_get_bitmap_width(game->level.letter)*x, game->viewportHeight*y, ALLEGRO_ALIGN_LEFT, text); - y+=0.028; - } - draw_text("Dear Derpy,"); - draw_text(""); - x = 0.20; - draw_text("I'm glad you decided to help us! I found a few tips"); - draw_text("in my library that might be useful on your mission."); - draw_text("I would like to share them with you."); - draw_text(""); - x = 0.21; - draw_text("Muffins regenerate your energy, so collect as many"); - draw_text("as you can. Cherries can help you as well. But be"); - draw_text("careful and avoid the muffinzombies - they can"); - draw_text("harm you!"); - draw_text(""); - x = 0.22; - draw_text("Discord is not fully awake yet, but he's already"); - draw_text("causing chaos all over Equestria and his strange"); - draw_text("creatures may try to stop you. Don't let them!"); - draw_text(""); - x = 0.23; - draw_text("Last but not least - You should be able to see the"); - draw_text("constellation Orion in the sky tonight. Be sure to"); - draw_text("take a moment to look for it if you have one to"); - draw_text("spare. It's beautiful!"); - draw_text(""); - x = 0.25; - draw_text("The fate of Equestria rests in your hooves."); - draw_text("Be safe and good luck!"); - draw_text(""); - x = 0.26; - draw_text("Yours,"); - draw_text("Twilight Sparkle"); - al_draw_text_with_shadow(game->menu.font, al_map_rgb(255,255,255), al_get_bitmap_width(game->level.letter)*0.5, al_get_bitmap_height(game->level.letter)*0.8, ALLEGRO_ALIGN_CENTRE, "Press enter to continue..."); - al_set_target_bitmap(al_get_backbuffer(game->display)); - PROGRESS; - - Dodger_PreloadBitmaps(game, progress); - al_set_target_bitmap(al_get_backbuffer(game->display)); + void ChildProgress(struct Game* game, float p) { + if (progress) (*progress)(game, load_p+=1/load_a); } + if (game->level.current_level!=1) Moonwalk_PreloadBitmaps(game, &ChildProgress); + else Level1_PreloadBitmaps(game, &ChildProgress); } diff --git a/src/level.h b/src/gamestates/level.h similarity index 98% rename from src/level.h rename to src/gamestates/level.h index c153e64..76f827f 100644 --- a/src/level.h +++ b/src/gamestates/level.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void SelectDerpySpritesheet(struct Game *game, char* name); void RegisterDerpySpritesheet(struct Game *game, char* name); diff --git a/src/loading.c b/src/gamestates/loading.c similarity index 100% rename from src/loading.c rename to src/gamestates/loading.c diff --git a/src/loading.h b/src/gamestates/loading.h similarity index 98% rename from src/loading.h rename to src/gamestates/loading.h index 657e5e7..f8e75df 100644 --- a/src/loading.h +++ b/src/gamestates/loading.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void Loading_Draw(struct Game *game); void Loading_Preload(struct Game *game, void (*progress)(struct Game*, float)); diff --git a/src/map.c b/src/gamestates/map.c similarity index 99% rename from src/map.c rename to src/gamestates/map.c index 7573d99..1faf272 100644 --- a/src/map.c +++ b/src/gamestates/map.c @@ -20,7 +20,7 @@ */ #include #include -#include "config.h" +#include "../config.h" #include "map.h" void Map_Draw(struct Game *game) { diff --git a/src/map.h b/src/gamestates/map.h similarity index 98% rename from src/map.h rename to src/gamestates/map.h index 0b851f2..98b993a 100644 --- a/src/map.h +++ b/src/gamestates/map.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void Map_Draw(struct Game *game); void Map_Logic(struct Game *game); diff --git a/src/menu.c b/src/gamestates/menu.c similarity index 99% rename from src/menu.c rename to src/gamestates/menu.c index 243ef10..e0c5229 100644 --- a/src/menu.c +++ b/src/gamestates/menu.c @@ -20,7 +20,7 @@ */ #include #include -#include "config.h" +#include "../config.h" #include "menu.h" void DrawMenuState(struct Game *game) { diff --git a/src/menu.h b/src/gamestates/menu.h similarity index 98% rename from src/menu.h rename to src/gamestates/menu.h index 0b28562..6827e14 100644 --- a/src/menu.h +++ b/src/gamestates/menu.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void DrawMenuState(struct Game *game); void Menu_Draw(struct Game *game); diff --git a/src/pause.c b/src/gamestates/pause.c similarity index 99% rename from src/pause.c rename to src/gamestates/pause.c index aa3b3dc..16043b7 100644 --- a/src/pause.c +++ b/src/gamestates/pause.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include -#include "config.h" +#include "../config.h" #include "pause.h" #include "menu.h" #include "level.h" diff --git a/src/pause.h b/src/gamestates/pause.h similarity index 98% rename from src/pause.h rename to src/gamestates/pause.h index 00a17c1..ac299cc 100644 --- a/src/pause.h +++ b/src/gamestates/pause.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "main.h" +#include "../main.h" void Pause_Draw(struct Game *game); void Pause_Preload(struct Game *game); diff --git a/src/levels/actions.c b/src/levels/actions.c index b5f7b74..458290d 100644 --- a/src/levels/actions.c +++ b/src/levels/actions.c @@ -20,7 +20,7 @@ */ #include "actions.h" -#include "../level.h" +#include "../gamestates/level.h" bool LevelFailed(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state == TM_ACTIONSTATE_INIT) { diff --git a/src/levels/dodger.c b/src/levels/dodger.c index ff01d77..8f5a79d 100644 --- a/src/levels/dodger.c +++ b/src/levels/dodger.c @@ -20,7 +20,7 @@ */ #include #include -#include "../level.h" +#include "../gamestates/level.h" #include "dodger.h" #include "actions.h" #include "dodger/actions.h" @@ -218,8 +218,12 @@ void Dodger_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) { } } +inline int Dodger_PreloadSteps() { + return 7; +} + void Dodger_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) { - float load_p = 12/19.0, load_a = 19; // FIXME: please! + PROGRESS_INIT(Dodger_PreloadSteps()); game->level.dodger.obst_bmps.pie1 = LoadScaledBitmap("levels/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); @@ -236,7 +240,7 @@ void Dodger_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, flo PROGRESS; } -void Dodger_Preload(struct Game *game, void (*progress)(struct Game*, float)) { +void Dodger_Preload(struct Game *game) { RegisterDerpySpritesheet(game, "walk"); RegisterDerpySpritesheet(game, "stand"); RegisterDerpySpritesheet(game, "fly"); diff --git a/src/levels/dodger.h b/src/levels/dodger.h index 9a735e8..e4ecf04 100644 --- a/src/levels/dodger.h +++ b/src/levels/dodger.h @@ -22,7 +22,7 @@ void Dodger_Draw(struct Game *game); void Dodger_Logic(struct Game *game); -void Dodger_Preload(struct Game *game, void (*progress)(struct Game*, float)); +void Dodger_Preload(struct Game *game); void Dodger_Unload(struct Game *game); void Dodger_Load(struct Game *game); void Dodger_Keydown(struct Game *game, ALLEGRO_EVENT *ev); @@ -31,3 +31,4 @@ void Dodger_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, flo void Dodger_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev); void Dodger_Resume(struct Game *game); void Dodger_Pause(struct Game *game); +inline int Dodger_PreloadSteps(); diff --git a/src/levels/dodger/actions.c b/src/levels/dodger/actions.c index 7ba4898..6fa73f0 100644 --- a/src/levels/dodger/actions.c +++ b/src/levels/dodger/actions.c @@ -22,7 +22,7 @@ #include "actions.h" #include "callbacks.h" #include "../actions.h" -#include "../../level.h" +#include "../../gamestates/level.h" bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { diff --git a/src/levels/level1.c b/src/levels/level1.c new file mode 100644 index 0000000..123829e --- /dev/null +++ b/src/levels/level1.c @@ -0,0 +1,181 @@ +/*! \file level1.c + * \brief Level 1 code. + */ +/* + * Copyright (c) Sebastian Krzyszkowiak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include "../gamestates/level.h" +#include "dodger.h" +#include "actions.h" +#include "dodger/actions.h" + +void Level1_Load(struct Game *game) { + Dodger_Load(game); + TM_AddBackgroundAction(&FadeIn, NULL, 0, "fadein"); + TM_AddDelay(1000); + TM_AddQueuedBackgroundAction(&Welcome, NULL, 0, "welcome"); + TM_AddDelay(1000); + TM_AddAction(&Walk, NULL, "walk"); + TM_AddAction(&Move, NULL, "move"); + TM_AddAction(&Stop, NULL, "stop"); + TM_AddDelay(1000); + TM_AddAction(&Letter, NULL, "letter"); + TM_AddDelay(200); + TM_AddQueuedBackgroundAction(&Accelerate, NULL, 0, "accelerate"); + TM_AddAction(&Fly, NULL, "fly"); + TM_AddDelay(500); + /* first part gameplay goes here */ + + /* actions for generating obstacles should go here + * probably as regular actions. When one ends, harder one + * begins. After last one part with muffins starts. */ + TM_AddAction(&GenerateObstacles, NULL, "obstacles"); + TM_AddDelay(3*1000); + /* wings disappear, deccelerate */ + TM_AddAction(&Run, NULL, "run"); + TM_AddDelay(3*1000); + /* show Fluttershy's house + + // second part gameplay goes here + + // cutscene goes here */ + TM_AddAction(&PassLevel, NULL, "passlevel"); + + // init level specific obstacle for Dodger module + struct Obstacle *obst = malloc(sizeof(struct Obstacle)); + obst->prev = NULL; + obst->next = NULL; + obst->x = 83.5; + obst->y = 55; + obst->speed = 1; + obst->points = 0; + obst->hit = false; + obst->rows = 1; + obst->cols = 1; + obst->pos = 0; + obst->blanks = 0; + obst->anim_speed = 0; + obst->tmp_pos = 0; + obst->angle = 0; + obst->callback = NULL; + obst->data = NULL; + obst->bitmap = &(game->level.owl); + game->level.dodger.obstacles = obst; +} + +void Level1_Unload(struct Game *game) { + Dodger_Unload(game); +} + +void Level1_UnloadBitmaps(struct Game *game) { + Dodger_UnloadBitmaps(game); + al_destroy_font(game->level.letter_font); + al_destroy_bitmap(game->level.letter); + al_destroy_bitmap(game->level.owl); +} + +void Level1_Preload(struct Game *game) { + Dodger_Preload(game); +} + +inline int Level1_PreloadSteps() { + return 4+Dodger_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); + 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); + al_set_target_bitmap(game->level.letter); + float y = 0.20; + float x = 0.19; + void draw_text(char* text) { + al_draw_text(game->level.letter_font, al_map_rgb(0,0,0), al_get_bitmap_width(game->level.letter)*x, game->viewportHeight*y, ALLEGRO_ALIGN_LEFT, text); + y+=0.028; + } + draw_text("Dear Derpy,"); + draw_text(""); + x = 0.20; + draw_text("I'm glad you decided to help us! I found a few tips"); + draw_text("in my library that might be useful on your mission."); + draw_text("I would like to share them with you."); + draw_text(""); + x = 0.21; + draw_text("Muffins regenerate your energy, so collect as many"); + draw_text("as you can. Cherries can help you as well. But be"); + draw_text("careful and avoid the muffinzombies - they can"); + draw_text("harm you!"); + draw_text(""); + x = 0.22; + draw_text("Discord is not fully awake yet, but he's already"); + draw_text("causing chaos all over Equestria and his strange"); + draw_text("creatures may try to stop you. Don't let them!"); + draw_text(""); + x = 0.23; + draw_text("Last but not least - You should be able to see the"); + draw_text("constellation Orion in the sky tonight. Be sure to"); + draw_text("take a moment to look for it if you have one to"); + draw_text("spare. It's beautiful!"); + draw_text(""); + x = 0.25; + draw_text("The fate of Equestria rests in your hooves."); + draw_text("Be safe and good luck!"); + draw_text(""); + x = 0.26; + draw_text("Yours,"); + draw_text("Twilight Sparkle"); + al_draw_text_with_shadow(game->menu.font, al_map_rgb(255,255,255), al_get_bitmap_width(game->level.letter)*0.5, al_get_bitmap_height(game->level.letter)*0.8, ALLEGRO_ALIGN_CENTRE, "Press enter to continue..."); + al_set_target_bitmap(al_get_backbuffer(game->display)); + PROGRESS; + + al_set_target_bitmap(game->level.welcome); + al_clear_to_color(al_map_rgba(0,0,0,0)); + al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1"); + al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy"); + PROGRESS; + al_set_target_bitmap(al_get_backbuffer(game->display)); + + Dodger_PreloadBitmaps(game, progress); +} + +void Level1_Draw(struct Game *game) { + Dodger_Draw(game); +} + +void Level1_Logic(struct Game *game) { + Dodger_Logic(game); +} + +void Level1_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { + Dodger_Keydown(game, ev); +} + +void Level1_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) { + Dodger_ProcessEvent(game, ev); +} + +void Level1_Resume(struct Game *game) { + Dodger_Resume(game); +} + +void Level1_Pause(struct Game *game) { + Dodger_Pause(game); +} diff --git a/src/levels/level1.h b/src/levels/level1.h new file mode 100644 index 0000000..8832e00 --- /dev/null +++ b/src/levels/level1.h @@ -0,0 +1,34 @@ +/*! \file level1.h + * \brief Level 1 headers. + */ +/* + * Copyright (c) Sebastian Krzyszkowiak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "../main.h" + +void Level1_Load(struct Game *game); +void Level1_Unload(struct Game *game); +void Level1_UnloadBitmaps(struct Game *game); +void Level1_Preload(struct Game *game); +void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)); +inline int Level1_PreloadSteps(); +void Level1_Draw(struct Game *game); +void Level1_Logic(struct Game *game); +void Level1_Keydown(struct Game *game, ALLEGRO_EVENT *ev); +void Level1_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev); +void Level1_Resume(struct Game *game); +void Level1_Pause(struct Game *game); diff --git a/src/levels/moonwalk.c b/src/levels/moonwalk.c index 74a8a6a..285ae75 100644 --- a/src/levels/moonwalk.c +++ b/src/levels/moonwalk.c @@ -20,7 +20,7 @@ */ #include #include -#include "../level.h" +#include "../gamestates/level.h" #include "moonwalk.h" void Moonwalk_Logic(struct Game *game) { @@ -70,7 +70,12 @@ void Moonwalk_Load(struct Game *game) { void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {} +inline int Moonwalk_PreloadSteps() { + return 1; +} + 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); @@ -80,11 +85,11 @@ void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, f 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); - + PROGRESS; al_set_target_bitmap(al_get_backbuffer(game->display)); } -void Moonwalk_Preload(struct Game *game, void (*progress)(struct Game*, float)) { +void Moonwalk_Preload(struct Game *game) { RegisterDerpySpritesheet(game, "walk"); // nasty hack: overwrite level music al_destroy_sample(game->level.sample); diff --git a/src/levels/moonwalk.h b/src/levels/moonwalk.h index 660ef3f..6891df5 100644 --- a/src/levels/moonwalk.h +++ b/src/levels/moonwalk.h @@ -22,7 +22,7 @@ void Moonwalk_Draw(struct Game *game); void Moonwalk_Logic(struct Game *game); -void Moonwalk_Preload(struct Game *game, void (*progress)(struct Game*, float)); +void Moonwalk_Preload(struct Game *game); void Moonwalk_Unload(struct Game *game); void Moonwalk_Load(struct Game *game); void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev); @@ -31,3 +31,4 @@ void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, f void Moonwalk_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev); void Moonwalk_Resume(struct Game *game); void Moonwalk_Pause(struct Game *game); +inline int Moonwalk_PreloadSteps(); diff --git a/src/main.c b/src/main.c index 4f42bc7..945078b 100644 --- a/src/main.c +++ b/src/main.c @@ -26,14 +26,14 @@ #include #include #include -#include "menu.h" -#include "loading.h" -#include "about.h" -#include "intro.h" -#include "map.h" -#include "level.h" -#include "pause.h" -#include "disclaimer.h" +#include "gamestates/menu.h" +#include "gamestates/loading.h" +#include "gamestates/about.h" +#include "gamestates/intro.h" +#include "gamestates/map.h" +#include "gamestates/level.h" +#include "gamestates/pause.h" +#include "gamestates/disclaimer.h" #include "config.h" /*! \brief Macro for preloading gamestate. diff --git a/src/main.h b/src/main.h index 29523d2..46c8f32 100644 --- a/src/main.h +++ b/src/main.h @@ -110,7 +110,7 @@ struct Dodger { ALLEGRO_BITMAP *screwball; /*!< Screwball spritesheet bitmap. */ } obst_bmps; /*!< Obstacle bitmaps. */ struct Obstacle *obstacles; /*!< List of obstacles being currently rendered. */ -}; +} dodger; /*! \brief Resources used by Level state and shared between level modules. */ struct Level { diff --git a/src/timeline.c b/src/timeline.c index 6f608f2..e61a2bf 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -25,7 +25,7 @@ unsigned int lastid; struct Game* game = NULL; struct TM_Action *queue, *background; -// TODO: consider moving globals to structure +// TODO: consider moving globals to some structure void TM_Init(struct Game* g) { PrintConsole(g, "Timeline Manager: init");