mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 19:16:44 +01:00
some first demo sidescrolling level
This commit is contained in:
parent
8eab7da8f1
commit
676d2d8900
3 changed files with 52 additions and 5 deletions
51
src/level.c
51
src/level.c
|
@ -41,10 +41,36 @@ void Level_Passed(struct Game *game) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||||
|
if (state != TM_ACTIONSTATE_RUNNING) return false;
|
||||||
|
game->level.speed+=0.000001;
|
||||||
|
if (game->level.speed<0.0025) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Level_Draw(struct Game *game) {
|
void Level_Draw(struct Game *game) {
|
||||||
if (game->level.current_level!=1) Moonwalk_Draw(game);
|
if (game->level.current_level!=1) Moonwalk_Draw(game);
|
||||||
else {
|
else {
|
||||||
al_clear_to_color(al_map_rgb(128,0,0));
|
al_clear_to_color(al_map_rgb(0,0,0));
|
||||||
|
al_draw_bitmap(game->level.clouds, (-game->level.cl_pos)*al_get_bitmap_width(game->level.clouds), 0, 0);
|
||||||
|
al_draw_bitmap(game->level.clouds, (1+(-game->level.cl_pos))*al_get_bitmap_width(game->level.clouds), 0, 0);
|
||||||
|
al_draw_bitmap(game->level.background, (-game->level.bg_pos)*al_get_bitmap_width(game->level.background), 0, 0);
|
||||||
|
al_draw_bitmap(game->level.background, (1+(-game->level.bg_pos))*al_get_bitmap_width(game->level.background), 0, 0);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
if (game->level.speed > 0) {
|
||||||
|
game->level.cl_pos += game->level.speed * 0.6;
|
||||||
|
game->level.bg_pos += game->level.speed * 0.6;
|
||||||
|
game->level.st_pos += game->level.speed * 1;
|
||||||
|
game->level.fg_pos += game->level.speed * 1.75;
|
||||||
|
if (game->level.cl_pos >= 1) game->level.cl_pos=1-game->level.cl_pos;
|
||||||
|
if (game->level.bg_pos >= 1) game->level.bg_pos=1-game->level.bg_pos;
|
||||||
|
if (game->level.st_pos >= 1) game->level.st_pos=1-game->level.st_pos;
|
||||||
|
if (game->level.fg_pos >= 1) game->level.fg_pos=1-game->level.fg_pos;
|
||||||
|
}
|
||||||
|
game->level.cl_pos += 0.0001;
|
||||||
TM_Process();
|
TM_Process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,13 +180,19 @@ bool wyjscie(struct Game *game, struct TM_Action *action, enum TM_ActionState st
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level_Load(struct Game *game) {
|
void Level_Load(struct Game *game) {
|
||||||
|
game->level.cl_pos=0;
|
||||||
|
game->level.bg_pos=0;
|
||||||
|
game->level.fg_pos=0.2;
|
||||||
|
game->level.st_pos=0.1;
|
||||||
|
game->level.speed=0;
|
||||||
al_clear_to_color(al_map_rgb(0,0,0));
|
al_clear_to_color(al_map_rgb(0,0,0));
|
||||||
if (game->level.current_level!=1) Moonwalk_Load(game);
|
if (game->level.current_level!=1) Moonwalk_Load(game);
|
||||||
else {
|
else {
|
||||||
TM_Init(game);
|
TM_Init(game);
|
||||||
|
TM_AddBackgroundAction(&Accelerate, NULL, 5000);
|
||||||
TM_AddAction(&napis, NULL);
|
TM_AddAction(&napis, NULL);
|
||||||
TM_AddAction(&napis, NULL);
|
TM_AddAction(&napis, NULL);
|
||||||
TM_AddDelay(2000);
|
TM_AddDelay(60*1000);
|
||||||
TM_AddAction(&napis, NULL);
|
TM_AddAction(&napis, NULL);
|
||||||
TM_AddBackgroundAction(&napis2, NULL, 1125);
|
TM_AddBackgroundAction(&napis2, NULL, 1125);
|
||||||
TM_AddAction(&wyjscie, NULL);
|
TM_AddAction(&wyjscie, NULL);
|
||||||
|
@ -185,6 +217,7 @@ void Level_ProcessLogic(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||||
void Level_Preload(struct Game *game) {
|
void Level_Preload(struct Game *game) {
|
||||||
Pause_Preload(game);
|
Pause_Preload(game);
|
||||||
if (game->level.current_level!=1) Moonwalk_Preload(game);
|
if (game->level.current_level!=1) Moonwalk_Preload(game);
|
||||||
|
Level_PreloadBitmaps(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level_Unload(struct Game *game) {
|
void Level_Unload(struct Game *game) {
|
||||||
|
@ -193,12 +226,26 @@ void Level_Unload(struct Game *game) {
|
||||||
else {
|
else {
|
||||||
TM_Destroy();
|
TM_Destroy();
|
||||||
}
|
}
|
||||||
|
Level_UnloadBitmaps(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level_UnloadBitmaps(struct Game *game) {
|
void Level_UnloadBitmaps(struct Game *game) {
|
||||||
if (game->level.current_level!=1) Moonwalk_UnloadBitmaps(game);
|
if (game->level.current_level!=1) Moonwalk_UnloadBitmaps(game);
|
||||||
|
else {
|
||||||
|
al_destroy_bitmap(game->level.foreground);
|
||||||
|
al_destroy_bitmap(game->level.background);
|
||||||
|
al_destroy_bitmap(game->level.stage);
|
||||||
|
al_destroy_bitmap(game->level.clouds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level_PreloadBitmaps(struct Game *game) {
|
void Level_PreloadBitmaps(struct Game *game) {
|
||||||
if (game->level.current_level!=1) Moonwalk_PreloadBitmaps(game);
|
if (game->level.current_level!=1) Moonwalk_PreloadBitmaps(game);
|
||||||
|
else {
|
||||||
|
// TODO: handle strange display aspects
|
||||||
|
game->level.clouds = LoadScaledBitmap("levels/1/clouds.png", al_get_display_height(game->display)*4.73307291666666666667, al_get_display_height(game->display));
|
||||||
|
game->level.foreground = LoadScaledBitmap("levels/1/foreground.png", al_get_display_height(game->display)*4.73307291666666666667, al_get_display_height(game->display));
|
||||||
|
game->level.background = LoadScaledBitmap("levels/1/background.png", al_get_display_height(game->display)*4.73307291666666666667, al_get_display_height(game->display));
|
||||||
|
game->level.stage = LoadScaledBitmap("levels/1/stage.png", al_get_display_height(game->display)*4.73307291666666666667, al_get_display_height(game->display));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,9 @@ struct Moonwalk {
|
||||||
/*! \brief Resources used by Level state. */
|
/*! \brief Resources used by Level state. */
|
||||||
struct Level {
|
struct Level {
|
||||||
int current_level;
|
int current_level;
|
||||||
|
float speed;
|
||||||
|
float bg_pos, st_pos, fg_pos, cl_pos;
|
||||||
|
ALLEGRO_BITMAP *background, *stage, *foreground, *clouds;
|
||||||
struct Moonwalk moonwalk;
|
struct Moonwalk moonwalk;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,6 @@ void Moonwalk_Preload(struct Game *game) {
|
||||||
fprintf(stderr, "Audio clip sample not loaded!\n" );
|
fprintf(stderr, "Audio clip sample not loaded!\n" );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Moonwalk_PreloadBitmaps(game);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Moonwalk_UnloadBitmaps(struct Game *game) {
|
void Moonwalk_UnloadBitmaps(struct Game *game) {
|
||||||
|
@ -138,7 +136,6 @@ void Moonwalk_Unload(struct Game *game) {
|
||||||
DrawConsole(game);
|
DrawConsole(game);
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
}
|
}
|
||||||
Moonwalk_UnloadBitmaps(game);
|
|
||||||
al_destroy_bitmap(game->level.moonwalk.fade_bitmap);
|
al_destroy_bitmap(game->level.moonwalk.fade_bitmap);
|
||||||
al_destroy_sample_instance(game->level.moonwalk.music);
|
al_destroy_sample_instance(game->level.moonwalk.music);
|
||||||
al_destroy_sample(game->level.moonwalk.sample);
|
al_destroy_sample(game->level.moonwalk.sample);
|
||||||
|
|
Loading…
Reference in a new issue