moonwalk is now timeline based

This commit is contained in:
Sebastian Krzyszkowiak 2012-09-29 01:58:34 +02:00
parent c863dfe58c
commit 85ae970597
12 changed files with 75 additions and 44 deletions

View file

@ -131,7 +131,7 @@ void Level_Logic(struct Game *game) {
game->level.sheet_tmp+=1;
if (game->level.sheet_tmp >= (game->level.sheet_speed/game->level.speed_modifier)/game->level.sheet_speed_modifier) {
game->level.sheet_pos++;
game->level.sheet_tmp = 0;
game->level.sheet_tmp -= (game->level.sheet_speed/game->level.speed_modifier)/game->level.sheet_speed_modifier;
}
if (game->level.sheet_pos>=game->level.sheet_cols*game->level.sheet_rows-game->level.sheet_blanks) {
game->level.sheet_pos=0;

View file

@ -27,6 +27,7 @@ bool LevelFailed(struct Game *game, struct TM_Action *action, enum TM_ActionStat
al_draw_filled_rectangle(0, 0, game->viewportWidth, game->viewportHeight, al_map_rgba(0,0,0,100));
al_draw_text_with_shadow(game->menu.font_title, al_map_rgb(255,255,255), game->viewportWidth*0.5, game->viewportHeight*0.4, ALLEGRO_ALIGN_CENTRE, "Failed!");
} else if (state == TM_ACTIONSTATE_RUNNING) {
// FIXME: this should be more generic. Some callback function?
game->level.speed-=0.00001;
if (game->level.speed<=0) {
return true;
@ -156,9 +157,13 @@ bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState
if (state == TM_ACTIONSTATE_DESTROY) {
Level_Passed(game);
Level_Unload(game);
if (game->level.current_level<6) {
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_MAP;
//TM_AddBackgroundAction(&FadeOut, NULL, 0, "fadeout");
} else {
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_ABOUT;
}
}
return true;
}
@ -192,7 +197,7 @@ bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
*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);
*stream = al_load_audio_stream(GetDataFilePath(GetLevelFilename(game, "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);

View file

@ -74,7 +74,7 @@ void Level1_Load(struct Game *game) {
obst->angle = 0;
obst->callback = NULL;
obst->data = NULL;
obst->bitmap = &(game->level.owl);
obst->bitmap = &(game->level.level1.owl);
game->level.dodger.obstacles = obst;
}
@ -86,7 +86,7 @@ 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);
al_destroy_bitmap(game->level.level1.owl);
}
void Level1_Preload(struct Game *game) {
@ -99,7 +99,7 @@ inline int Level1_PreloadSteps() {
void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
PROGRESS_INIT(Level1_PreloadSteps());
game->level.owl = LoadScaledBitmap("levels/1/owl.png", game->viewportWidth*0.08, game->viewportWidth*0.08);
game->level.level1.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;

View file

@ -21,9 +21,15 @@
#include <stdio.h>
#include "../gamestates/level.h"
#include "modules/moonwalk.h"
#include "../timeline.h"
#include "actions.h"
#include "level2.h"
void Level2_Load(struct Game *game) {
Moonwalk_Load(game);
TM_AddAction(&DoMoonwalk, NULL, "moonwalk");
TM_AddAction(&PassLevel, NULL, "passlevel");
FadeGameState(game, true);
}
void Level2_Unload(struct Game *game) {

View file

@ -1,4 +1,4 @@
/*! \file Level3.c
/*! \file level3.c
* \brief Level 3 code.
*/
/*
@ -21,9 +21,16 @@
#include <stdio.h>
#include "../gamestates/level.h"
#include "modules/moonwalk.h"
#include "../timeline.h"
#include "actions.h"
#include "level3.h"
void Level3_Load(struct Game *game) {
Moonwalk_Load(game);
TM_AddAction(&DoMoonwalk, NULL, "moonwalk");
TM_AddAction(&PassLevel, NULL, "passlevel");
TM_AddBackgroundAction(&ShowMeter, NULL, 0, "showmeter");
FadeGameState(game, true);
}
void Level3_Unload(struct Game *game) {

View file

@ -1,4 +1,4 @@
/*! \file Level4.c
/*! \file level4.c
* \brief Level 4 code.
*/
/*
@ -21,9 +21,16 @@
#include <stdio.h>
#include "../gamestates/level.h"
#include "modules/moonwalk.h"
#include "../timeline.h"
#include "actions.h"
#include "level4.h"
void Level4_Load(struct Game *game) {
Moonwalk_Load(game);
TM_AddAction(&DoMoonwalk, NULL, "moonwalk");
TM_AddAction(&PassLevel, NULL, "passlevel");
TM_AddBackgroundAction(&ShowMeter, NULL, 0, "showmeter");
FadeGameState(game, true);
}
void Level4_Unload(struct Game *game) {

View file

@ -1,4 +1,4 @@
/*! \file Level5.c
/*! \file level5.c
* \brief Level 5 code.
*/
/*
@ -21,9 +21,16 @@
#include <stdio.h>
#include "../gamestates/level.h"
#include "modules/moonwalk.h"
#include "../timeline.h"
#include "actions.h"
#include "level5.h"
void Level5_Load(struct Game *game) {
Moonwalk_Load(game);
TM_AddAction(&DoMoonwalk, NULL, "moonwalk");
TM_AddAction(&PassLevel, NULL, "passlevel");
TM_AddBackgroundAction(&ShowMeter, NULL, 0, "showmeter");
FadeGameState(game, true);
}
void Level5_Unload(struct Game *game) {

View file

@ -1,4 +1,4 @@
/*! \file Level6.c
/*! \file level6.c
* \brief Level 6 code.
*/
/*
@ -21,9 +21,14 @@
#include <stdio.h>
#include "../gamestates/level.h"
#include "modules/moonwalk.h"
#include "../timeline.h"
#include "actions.h"
#include "level6.h"
void Level6_Load(struct Game *game) {
Moonwalk_Load(game);
TM_AddBackgroundAction(&PassLevel, NULL, 5000, "passlevel");
FadeGameState(game, true);
}
void Level6_Unload(struct Game *game) {

View file

@ -24,7 +24,7 @@
#include "../../actions.h"
#include "../../../gamestates/level.h"
// TODO: make it configurable and move to generic actions
bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state != TM_ACTIONSTATE_RUNNING) return false;
game->level.speed+=0.000015;
@ -32,6 +32,7 @@ bool Accelerate(struct Game *game, struct TM_Action *action, enum TM_ActionState
return true;
}
// TODO: make it configurable and move to generic actions
bool Walk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state == TM_ACTIONSTATE_INIT) action->arguments = NULL;
if (state != TM_ACTIONSTATE_RUNNING) return false;
@ -42,9 +43,10 @@ bool Walk(struct Game *game, struct TM_Action *action, enum TM_ActionState state
return true;
}
// TODO: make it configurable and move to generic actions
bool Move(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state != TM_ACTIONSTATE_RUNNING) return false;
game->level.speed=0.00035;
game->level.speed=0.000345;
if (game->level.st_pos<0.275) return false;
return true;
}

View file

@ -23,36 +23,30 @@
#include "../../gamestates/level.h"
#include "moonwalk.h"
void Moonwalk_Logic(struct Game *game) {
game->level.moonwalk.derpy_pos=game->level.moonwalk.derpy_pos+0.00092;
game->level.moonwalk.derpy_frame_tmp++;
if (game->level.moonwalk.derpy_frame_tmp%3==0) {
if (game->level.moonwalk.derpy_frame_tmp%5==0) game->level.moonwalk.derpy_frame++;
if (game->level.moonwalk.derpy_frame_tmp%22==21) game->level.moonwalk.derpy_frame--;
game->level.moonwalk.derpy_frame++;
if (game->level.moonwalk.derpy_frame>=24) game->level.moonwalk.derpy_frame=0;
// TODO: use Walk action instead
bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state == TM_ACTIONSTATE_INIT) {
SelectDerpySpritesheet(game, "walk");
game->level.sheet_speed_modifier = 0.94;
game->level.moonwalk.derpy_pos = -0.2;
}
else if (state == TM_ACTIONSTATE_RUNNING) {
game->level.moonwalk.derpy_pos=game->level.moonwalk.derpy_pos+0.00092;
if (game->level.moonwalk.derpy_pos>1) {
return true;
}
}
return false;
}
void Moonwalk_Logic(struct Game *game) {}
void Moonwalk_Draw(struct Game *game) {
al_set_target_bitmap(game->level.derpy);
al_clear_to_color(al_map_rgba(0,0,0,0));
al_draw_bitmap_region(*(game->level.derpy_sheet),al_get_bitmap_width(game->level.derpy)*(game->level.moonwalk.derpy_frame%6),al_get_bitmap_height(game->level.derpy)*(game->level.moonwalk.derpy_frame/6),al_get_bitmap_width(game->level.derpy), al_get_bitmap_height(game->level.derpy),0,0,0);
al_draw_bitmap_region(*(game->level.derpy_sheet),al_get_bitmap_width(game->level.derpy)*(game->level.sheet_pos%6),al_get_bitmap_height(game->level.derpy)*(game->level.sheet_pos/6),al_get_bitmap_width(game->level.derpy), al_get_bitmap_height(game->level.derpy),0,0,0);
al_set_target_bitmap(al_get_backbuffer(game->display));
if (game->level.moonwalk.derpy_pos>1) {
game->level.moonwalk.derpy_pos=-1;
Level_Passed(game);
UnloadGameState(game);
if (game->level.current_level<6) {
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_MAP;
} else {
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_ABOUT;
}
return;
}
al_draw_scaled_bitmap(game->level.stage,0,0,al_get_bitmap_width(game->level.stage),al_get_bitmap_height(game->level.stage),0,0,game->viewportWidth, game->viewportHeight,0);
al_draw_bitmap(game->level.derpy, game->level.moonwalk.derpy_pos*game->viewportWidth, game->viewportHeight*0.95-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL);
al_draw_textf(game->font, al_map_rgb(255,255,255), game->viewportWidth/2, game->viewportHeight/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level);
@ -60,12 +54,8 @@ void Moonwalk_Draw(struct Game *game) {
}
void Moonwalk_Load(struct Game *game) {
SelectDerpySpritesheet(game, "walk");
game->level.moonwalk.derpy_frame = 0;
game->level.moonwalk.derpy_frame_tmp = 0;
game->level.moonwalk.derpy_pos = -0.2;
game->level.moonwalk.derpy_pos = 0;
al_play_sample_instance(game->level.music);
FadeGameState(game, true);
}
void Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {}

View file

@ -19,7 +19,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "../../main.h"
#include "../../timeline.h"
bool DoMoonwalk(struct Game *game, struct TM_Action *action, enum TM_ActionState state);
void Moonwalk_Draw(struct Game *game);
void Moonwalk_Logic(struct Game *game);
void Moonwalk_Preload(struct Game *game);

View file

@ -93,8 +93,6 @@ struct Spritesheet {
/*! \brief Resources used by Moonwalk level module. */
struct Moonwalk {
int derpy_frame; /*!< Current frame of Derpy animation. */
int derpy_frame_tmp; /*!< Counter used to slow down Derpy animation. */
double derpy_pos; /*!< Position of Derpy on screen. */
};
@ -145,7 +143,6 @@ struct Level {
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
unsigned int music_pos; /*!< Position of sample instance. Used when pausing game. */
ALLEGRO_BITMAP *owl; /*!< Owlicious bitmap. */
ALLEGRO_BITMAP *background; /*!< Bitmap of the background layer of the scene. */
ALLEGRO_BITMAP *stage; /*!< Bitmap of the stage layer of the scene. */
ALLEGRO_BITMAP *foreground; /*!< Bitmap of the foreground layer of the scene. */
@ -159,6 +156,9 @@ struct Level {
bool debug_show_sprite_frames; /*!< When true, displays colorful borders around spritesheets and their active areas. */
struct Spritesheet* derpy_sheets; /*!< List of spritesheets of Derpy character. */
//struct Spritesheet* pony_sheets; /*!< List of spritesheets of character rescued by Derpy. */
struct {
ALLEGRO_BITMAP *owl; /*!< Owlicious bitmap. */
} level1; /*!< Resources used by level 1. */
struct Moonwalk moonwalk; /*!< Moonwalk module data. */
struct Dodger dodger; /*!< Dodger module data. */
};