mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 20:18:00 +01:00
more level modularity
This commit is contained in:
parent
8fa37d619c
commit
cd3fbbccf0
6 changed files with 60 additions and 59 deletions
67
src/level.c
67
src/level.c
|
@ -58,10 +58,18 @@ void SelectDerpySpritesheet(struct Game *game, char* name) {
|
|||
}
|
||||
|
||||
void RegisterDerpySpritesheet(struct Game *game, char* name) {
|
||||
struct Spritesheet *s = game->level.derpy_sheets;
|
||||
while (s) {
|
||||
if (!strcmp(s->name, name)) {
|
||||
//PrintConsole(game, "Derpy spritesheet %s already registered!", name);
|
||||
return;
|
||||
}
|
||||
s = s->next;
|
||||
}
|
||||
char filename[255] = { };
|
||||
sprintf(filename, "levels/derpy/%s.ini", name);
|
||||
ALLEGRO_CONFIG *config = al_load_config_file(GetDataFilePath(filename));
|
||||
struct Spritesheet *s = malloc(sizeof(struct Spritesheet));
|
||||
s = malloc(sizeof(struct Spritesheet));
|
||||
s->name = malloc((strlen(name)+1)*sizeof(char));
|
||||
strcpy(s->name, name);
|
||||
s->bitmap = NULL;
|
||||
|
@ -136,21 +144,19 @@ void Level_Logic(struct Game *game) {
|
|||
}
|
||||
|
||||
void Level_Resume(struct Game *game) {
|
||||
// TODO: make it modular
|
||||
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) {
|
||||
TM_Resume();
|
||||
}
|
||||
if (game->level.current_level==1) Dodger_Resume(game);
|
||||
else Moonwalk_Resume(game);
|
||||
TM_Resume();
|
||||
}
|
||||
|
||||
void Level_Pause(struct Game *game) {
|
||||
// TODO: make it modular
|
||||
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) {
|
||||
TM_Pause();
|
||||
}
|
||||
if (game->level.current_level==1) Dodger_Pause(game);
|
||||
else Moonwalk_Pause(game);
|
||||
TM_Pause();
|
||||
}
|
||||
|
||||
void Level_Draw(struct Game *game) {
|
||||
|
@ -164,7 +170,7 @@ void Level_Draw(struct Game *game) {
|
|||
if (game->level.current_level==1) Dodger_Draw(game);
|
||||
else Moonwalk_Draw(game);
|
||||
|
||||
if (game->level.unloading) return;
|
||||
if (!game->level.foreground) return;
|
||||
|
||||
al_draw_bitmap(game->level.foreground, (-game->level.fg_pos)*al_get_bitmap_width(game->level.foreground), 0 ,0);
|
||||
al_draw_bitmap(game->level.foreground, (1+(-game->level.fg_pos))*al_get_bitmap_width(game->level.foreground), 0 ,0);
|
||||
|
@ -285,35 +291,32 @@ void Level_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
}
|
||||
|
||||
void Level_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
PrintConsole(game, "Initializing level %d...", game->level.input.current_level);
|
||||
|
||||
game->level.current_level = game->level.input.current_level;
|
||||
game->level.derpy_sheets = NULL;
|
||||
game->level.derpy = NULL;
|
||||
game->level.unloading = false;
|
||||
Pause_Preload(game);
|
||||
RegisterDerpySpritesheet(game, "stand");
|
||||
if (game->level.current_level!=1) {
|
||||
RegisterDerpySpritesheet(game, "walk");
|
||||
Moonwalk_Preload(game, progress);
|
||||
}
|
||||
else {
|
||||
RegisterDerpySpritesheet(game, "walk");
|
||||
RegisterDerpySpritesheet(game, "fly");
|
||||
RegisterDerpySpritesheet(game, "run");
|
||||
RegisterDerpySpritesheet(game, "stand"); // default
|
||||
|
||||
Dodger_Preload(game, progress);
|
||||
//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("levels/1/music.flac") );
|
||||
game->level.music = al_create_sample_instance(game->level.sample);
|
||||
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
|
||||
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
|
||||
//TODO: make music handling global
|
||||
if (game->level.current_level==1) Dodger_Preload(game, progress);
|
||||
else Moonwalk_Preload(game, progress);
|
||||
|
||||
if (!game->level.sample){
|
||||
fprintf(stderr, "Audio clip sample not loaded!\n" );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
Level_PreloadBitmaps(game, progress);
|
||||
|
||||
game->level.music = al_create_sample_instance(game->level.sample);
|
||||
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
|
||||
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
|
||||
|
||||
if (!game->level.sample){
|
||||
fprintf(stderr, "Audio clip sample not loaded!\n" );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Level_Unload(struct Game *game) {
|
||||
|
@ -351,6 +354,7 @@ void Level_UnloadBitmaps(struct Game *game) {
|
|||
al_destroy_bitmap(game->level.meter_bmp);
|
||||
al_destroy_bitmap(game->level.meter_image);
|
||||
al_destroy_bitmap(game->level.welcome);
|
||||
game->level.foreground = NULL;
|
||||
}
|
||||
|
||||
void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
|
@ -378,7 +382,8 @@ 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: maybe handle strange display aspects */
|
||||
//TODO: load proper bitmap files for each level
|
||||
//TODO: maybe handle strange display aspects
|
||||
game->level.clouds = LoadScaledBitmap("levels/1/clouds.png", game->viewportHeight*4.73307291666666666667, game->viewportHeight);
|
||||
PROGRESS;
|
||||
game->level.foreground = LoadScaledBitmap("levels/1/foreground.png", game->viewportHeight*4.73307291666666666667, game->viewportHeight);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "main.h"
|
||||
|
||||
void SelectDerpySpritesheet(struct Game *game, char* name);
|
||||
void RegisterDerpySpritesheet(struct Game *game, char* name);
|
||||
void Level_Passed(struct Game *game);
|
||||
void Level_Pause(struct Game *game);
|
||||
void Level_Resume(struct Game *game);
|
||||
|
|
|
@ -188,7 +188,7 @@ void Dodger_Load(struct Game *game) {
|
|||
game->level.dodger.obstacles = NULL;
|
||||
}
|
||||
|
||||
int Dodger_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
void Dodger_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
if (game->level.handle_input) {
|
||||
if (ev->keyboard.keycode==ALLEGRO_KEY_LEFT) {
|
||||
game->level.speed_modifier = 0.75;
|
||||
|
@ -196,7 +196,6 @@ int Dodger_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
game->level.speed_modifier = 1.3;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Dodger_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
|
@ -238,6 +237,10 @@ void Dodger_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, flo
|
|||
}
|
||||
|
||||
void Dodger_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
RegisterDerpySpritesheet(game, "walk");
|
||||
RegisterDerpySpritesheet(game, "stand");
|
||||
RegisterDerpySpritesheet(game, "fly");
|
||||
RegisterDerpySpritesheet(game, "run");
|
||||
}
|
||||
|
||||
void Dodger_UnloadBitmaps(struct Game *game) {
|
||||
|
@ -267,3 +270,6 @@ void Dodger_Unload(struct Game *game) {
|
|||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void Dodger_Resume(struct Game *game) {}
|
||||
void Dodger_Pause(struct Game *game) {}
|
||||
|
|
|
@ -25,7 +25,9 @@ void Dodger_Logic(struct Game *game);
|
|||
void Dodger_Preload(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Dodger_Unload(struct Game *game);
|
||||
void Dodger_Load(struct Game *game);
|
||||
int Dodger_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Dodger_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Dodger_UnloadBitmaps(struct Game *game);
|
||||
void Dodger_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Dodger_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Dodger_Resume(struct Game *game);
|
||||
void Dodger_Pause(struct Game *game);
|
||||
|
|
|
@ -68,13 +68,9 @@ void Moonwalk_Load(struct Game *game) {
|
|||
FadeGameState(game, true);
|
||||
}
|
||||
|
||||
int Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
return 0;
|
||||
}
|
||||
void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {}
|
||||
|
||||
void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
/*game->level.derpy_sheet = LoadScaledBitmap("levels/derpcycle.png", game->viewportWidth*0.1953125*6, game->viewportHeight*0.25*4);*/
|
||||
|
||||
// nasty hack: overwrite level backgrounds
|
||||
al_destroy_bitmap(game->level.background);
|
||||
al_destroy_bitmap(game->level.foreground);
|
||||
|
@ -89,25 +85,14 @@ void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, f
|
|||
}
|
||||
|
||||
void Moonwalk_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
PrintConsole(game, "Initializing level %d...", game->level.current_level);
|
||||
RegisterDerpySpritesheet(game, "walk");
|
||||
// nasty hack: overwrite level music
|
||||
al_destroy_sample(game->level.sample);
|
||||
game->level.sample = al_load_sample( GetDataFilePath("levels/moonwalk.flac") );
|
||||
//TODO: make music handling global
|
||||
game->level.music = al_create_sample_instance(game->level.sample);
|
||||
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
|
||||
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
|
||||
|
||||
if (!game->level.sample){
|
||||
fprintf(stderr, "Audio clip sample not loaded!\n" );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void Moonwalk_UnloadBitmaps(struct Game *game) {
|
||||
}
|
||||
|
||||
void Moonwalk_Unload(struct Game *game) {
|
||||
//FadeGameState(game, false);
|
||||
}
|
||||
|
||||
void Moonwalk_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
}
|
||||
void Moonwalk_UnloadBitmaps(struct Game *game) {}
|
||||
void Moonwalk_Unload(struct Game *game) {}
|
||||
void Moonwalk_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev) {}
|
||||
void Moonwalk_Resume(struct Game *game) {}
|
||||
void Moonwalk_Pause(struct Game *game) {}
|
||||
|
|
|
@ -25,7 +25,9 @@ void Moonwalk_Logic(struct Game *game);
|
|||
void Moonwalk_Preload(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Moonwalk_Unload(struct Game *game);
|
||||
void Moonwalk_Load(struct Game *game);
|
||||
int Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Moonwalk_UnloadBitmaps(struct Game *game);
|
||||
void Moonwalk_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Moonwalk_ProcessEvent(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void Moonwalk_Resume(struct Game *game);
|
||||
void Moonwalk_Pause(struct Game *game);
|
||||
|
|
Loading…
Reference in a new issue