mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-13 04:27:59 +01:00
general reorganization. again. levels have now another abstraction layer, yay! :D
This commit is contained in:
parent
74bf535c07
commit
d62be104e8
28 changed files with 299 additions and 180 deletions
|
@ -1,16 +1,17 @@
|
|||
SET(SRC_LIST
|
||||
about.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
|
||||
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
|
||||
|
|
|
@ -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);
|
|
@ -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));
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
|
@ -20,14 +20,12 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#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);
|
||||
}
|
|
@ -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);
|
|
@ -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));
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
#include "../config.h"
|
||||
#include "map.h"
|
||||
|
||||
void Map_Draw(struct Game *game) {
|
|
@ -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);
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
#include "../config.h"
|
||||
#include "menu.h"
|
||||
|
||||
void DrawMenuState(struct Game *game) {
|
|
@ -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);
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
#include "../config.h"
|
||||
#include "pause.h"
|
||||
#include "menu.h"
|
||||
#include "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 Pause_Draw(struct Game *game);
|
||||
void Pause_Preload(struct Game *game);
|
|
@ -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) {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
181
src/levels/level1.c
Normal file
181
src/levels/level1.c
Normal file
|
@ -0,0 +1,181 @@
|
|||
/*! \file level1.c
|
||||
* \brief Level 1 code.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#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);
|
||||
}
|
34
src/levels/level1.h
Normal file
34
src/levels/level1.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*! \file level1.h
|
||||
* \brief Level 1 headers.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
|
||||
*
|
||||
* 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);
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#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);
|
||||
|
|
|
@ -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();
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -26,14 +26,14 @@
|
|||
#include <getopt.h>
|
||||
#include <locale.h>
|
||||
#include <signal.h>
|
||||
#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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue