mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 20:18:00 +01:00
load proper resources for each level, and add dummy resources for each level :D
This commit is contained in:
parent
5083033a4b
commit
c863dfe58c
10 changed files with 77 additions and 77 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {}
|
||||
|
|
Loading…
Reference in a new issue