more work on first level

This commit is contained in:
Sebastian Krzyszkowiak 2012-04-08 23:25:14 +02:00
parent 676d2d8900
commit 4c039847a0
5 changed files with 145 additions and 52 deletions

View file

@ -43,8 +43,43 @@ 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;
game->level.speed+=0.000005;
if (game->level.speed<0.0020) return false;
return true;
}
bool Walk(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state != TM_ACTIONSTATE_RUNNING) return false;
game->level.derpy_x+=0.001;
if (game->level.derpy_x<0.05) return false;
return true;
}
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;
if (game->level.st_pos<0.275) return false;
return true;
}
bool Fly(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state == TM_ACTIONSTATE_INIT) { action->arguments=NULL; return false; }
if (state != TM_ACTIONSTATE_RUNNING) return false;
if (!action->arguments) {
action->arguments++;
TM_AddBackgroundAction(&Accelerate, NULL, 0);
}
game->level.derpy_y-=0.004;
if (game->level.derpy_y>0.2) return false;
return true;
}
bool Stop(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state != TM_ACTIONSTATE_RUNNING) return false;
game->level.speed=0;
game->level.sheet_speed = 0;
//game->level.sheet_pos = 0;
return true;
}
@ -58,6 +93,19 @@ void Level_Draw(struct Game *game) {
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_set_target_bitmap(game->level.derpy);
al_clear_to_color(al_map_rgba(0,0,0,0));
al_draw_bitmap_region(game->level.derpy_walkcycle,al_get_bitmap_width(game->level.derpy)*(game->level.sheet_pos%game->level.sheet_cols),al_get_bitmap_height(game->level.derpy)*(game->level.sheet_pos/game->level.sheet_cols),al_get_bitmap_width(game->level.derpy), al_get_bitmap_height(game->level.derpy),0,0,0);
if (game->level.sheet_speed) {
game->level.sheet_tmp++;
if (game->level.sheet_tmp%game->level.sheet_speed) game->level.sheet_pos++;
if (game->level.sheet_pos>=game->level.sheet_cols*game->level.sheet_rows) game->level.sheet_pos=0;
}
al_set_target_bitmap(al_get_backbuffer(game->display));
al_draw_bitmap(game->level.derpy, game->level.derpy_x*al_get_display_width(game->display), game->level.derpy_y*al_get_display_height(game->display), 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) {
@ -132,46 +180,44 @@ bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState st
return false;
}
bool napis2(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
bool Welcome(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
float* tmp; bool* in;
if (!action->arguments) {
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(int)));
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float)));
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(bool)));
}
int* tmp;
tmp = (int*)action->arguments->value;
tmp = (float*)action->arguments->value;
in = (bool*)action->arguments->next->value;
if (state == TM_ACTIONSTATE_INIT) {
*tmp = 0;
} else if (state == TM_ACTIONSTATE_RUNNING) {
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 100, 0, "lol");
*tmp+=5;
if (*tmp>=al_get_display_width(game->display)) { *tmp=0; return true; }
*in = true;
//PrintConsole(game, "WELCOME INIT");
}
else if (state == TM_ACTIONSTATE_RUNNING) {
//al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 20, 0, "Level 1");
//PrintConsole(game, "WELCOME RUNNING FADE=%f, IN=%d", *in);
int fade = *tmp;
if (fade>255) fade=255;
if (*tmp > 1500) { *tmp=255; *in=false; }
al_draw_tinted_bitmap(game->level.welcome, al_map_rgba_f(fade/255.0,fade/255.0,fade/255.0,fade/255.0), 0, 0, 0);
if (*in) {
*tmp+=tps(game, 600);
//if (*tmp>=256) { return false; }
} else {
*tmp-=tps(game, 600);
if (*tmp<=0) { return true; }
}
} else {
free(action->arguments->value);
free(action->arguments->next->value);
TM_DestroyArgs(action->arguments);
action->arguments = NULL;
//TM_AddBackgroundAction(&Accelerate, NULL, 1000);
}
return false;
}
bool napis(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (!action->arguments) {
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(int)));
}
int* tmp;
tmp = (int*)action->arguments->value;
if (state == TM_ACTIONSTATE_INIT) {
*tmp = 0;
} else if (state == TM_ACTIONSTATE_RUNNING) {
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 20, 0, "wat");
*tmp+=10;
if (*tmp>=al_get_display_width(game->display)) { *tmp=0; return true; }
} else {
TM_AddBackgroundAction(&napis2, NULL, 0);
TM_DestroyArgs(action->arguments);
action->arguments = NULL;
}
return false;
}
bool wyjscie(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
if (state == TM_ACTIONSTATE_DESTROY) {
Level_Passed(game);
TM_AddBackgroundAction(&FadeOut, NULL, 0);
@ -185,18 +231,44 @@ void Level_Load(struct Game *game) {
game->level.fg_pos=0.2;
game->level.st_pos=0.1;
game->level.speed = 0;
game->level.derpy_x = -0.2;
game->level.derpy_y = 0.6;
game->level.sheet_rows = 4;
game->level.sheet_cols = 6;
game->level.sheet_pos = 0;
game->level.sheet_speed = 2;
game->level.sheet_tmp = 0;
al_clear_to_color(al_map_rgb(0,0,0));
if (game->level.current_level!=1) Moonwalk_Load(game);
else {
TM_Init(game);
TM_AddBackgroundAction(&Accelerate, NULL, 5000);
TM_AddAction(&napis, NULL);
TM_AddAction(&napis, NULL);
TM_AddDelay(60*1000);
TM_AddAction(&napis, NULL);
TM_AddBackgroundAction(&napis2, NULL, 1125);
TM_AddAction(&wyjscie, NULL);
TM_AddBackgroundAction(&FadeIn, NULL, 0);
TM_AddDelay(1000);
TM_AddAction(&Welcome, NULL);
TM_AddAction(&Walk, NULL);
TM_AddAction(&Move, NULL);
TM_AddAction(&Stop, NULL);
TM_AddDelay(5*1000);
TM_AddAction(&Fly, NULL);
// Derpy walks in... (background - owl)
// Derpy reads a letter
// Letter on screen
// Derpy: fly! (background - accelerate)
// first part gameplay goes here
TM_AddDelay(60*1000);
// wings disappear, deccelerate, fall down
// run
// show Fluttershy's house
// second part gameplay goes here
//
// cutscene goes here
//
TM_AddAction(&PassLevel, NULL);
}
}
@ -230,16 +302,21 @@ void Level_Unload(struct Game *game) {
}
void Level_UnloadBitmaps(struct Game *game) {
al_destroy_bitmap(game->level.derpy);
al_destroy_bitmap(game->level.derpy_walkcycle);
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);
al_destroy_bitmap(game->level.welcome);
}
}
void Level_PreloadBitmaps(struct Game *game) {
game->level.derpy_walkcycle = LoadScaledBitmap("derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4);
game->level.derpy = al_create_bitmap(al_get_display_width(game->display)*0.1953125, al_get_display_height(game->display)*0.25);
if (game->level.current_level!=1) Moonwalk_PreloadBitmaps(game);
else {
// TODO: handle strange display aspects
@ -247,5 +324,11 @@ void Level_PreloadBitmaps(struct Game *game) {
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));
game->level.welcome = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
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), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, ALLEGRO_ALIGN_CENTRE, "Level 1");
al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.275, ALLEGRO_ALIGN_CENTRE, "Fluttershy");
al_set_target_bitmap(al_get_backbuffer(game->display));
}
}

View file

@ -45,8 +45,6 @@ enum gamestate_enum {
struct Moonwalk {
ALLEGRO_BITMAP *fade_bitmap; /*!< Bitmap used on fade-in and fade-out animations. */
ALLEGRO_BITMAP *image; /*!< Background texture. */
ALLEGRO_BITMAP *derpy_walkcycle; /*!< Derpy walk cycle spritesheet. */
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
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. */
@ -61,7 +59,12 @@ struct Level {
int current_level;
float speed;
float bg_pos, st_pos, fg_pos, cl_pos;
float derpy_x, derpy_y;
int sheet_rows, sheet_cols, sheet_pos, sheet_tmp, sheet_speed;
ALLEGRO_BITMAP *background, *stage, *foreground, *clouds;
ALLEGRO_BITMAP *welcome;
ALLEGRO_BITMAP *derpy_walkcycle; /*!< Derpy walk cycle spritesheet. */
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
struct Moonwalk moonwalk;
};

View file

@ -28,9 +28,9 @@ void Moonwalk_Draw(struct Game *game) {
al_set_sample_instance_playing(game->level.moonwalk.music, true);
al_set_sample_instance_position(game->level.moonwalk.music, game->level.moonwalk.music_pos);
}
al_set_target_bitmap(game->level.moonwalk.derpy);
al_set_target_bitmap(game->level.derpy);
al_clear_to_color(al_map_rgba(0,0,0,0));
al_draw_bitmap_region(game->level.moonwalk.derpy_walkcycle,al_get_bitmap_width(game->level.moonwalk.derpy)*(game->level.moonwalk.derpy_frame%6),al_get_bitmap_height(game->level.moonwalk.derpy)*(game->level.moonwalk.derpy_frame/6),al_get_bitmap_width(game->level.moonwalk.derpy), al_get_bitmap_height(game->level.moonwalk.derpy),0,0,0);
al_draw_bitmap_region(game->level.derpy_walkcycle,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_set_target_bitmap(al_get_backbuffer(game->display));
game->level.moonwalk.derpy_pos=game->level.moonwalk.derpy_pos+tps(game, 60*0.00092);
@ -57,7 +57,7 @@ void Moonwalk_Draw(struct Game *game) {
}
}
al_draw_scaled_bitmap(game->level.moonwalk.image,0,0,al_get_bitmap_width(game->level.moonwalk.image),al_get_bitmap_height(game->level.moonwalk.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_bitmap(game->level.moonwalk.derpy, game->level.moonwalk.derpy_pos*al_get_display_width(game->display), al_get_display_height(game->display)-al_get_bitmap_height(game->level.moonwalk.derpy), ALLEGRO_FLIP_HORIZONTAL);
al_draw_bitmap(game->level.derpy, game->level.moonwalk.derpy_pos*al_get_display_width(game->display), al_get_display_height(game->display)-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL);
al_draw_textf(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level);
al_draw_text(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");
}
@ -89,9 +89,9 @@ int Moonwalk_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
void Moonwalk_PreloadBitmaps(struct Game *game) {
game->level.moonwalk.image =LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->level.moonwalk.derpy_walkcycle = LoadScaledBitmap("derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4);
game->level.derpy_walkcycle = LoadScaledBitmap("derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4);
game->level.moonwalk.derpy = al_create_bitmap(al_get_display_width(game->display)*0.1953125, al_get_display_height(game->display)*0.25);
game->level.derpy = al_create_bitmap(al_get_display_width(game->display)*0.1953125, al_get_display_height(game->display)*0.25);
game->level.moonwalk.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->level.moonwalk.fade_bitmap);
@ -116,8 +116,6 @@ void Moonwalk_Preload(struct Game *game) {
void Moonwalk_UnloadBitmaps(struct Game *game) {
al_destroy_bitmap(game->level.moonwalk.image);
al_destroy_bitmap(game->level.moonwalk.derpy);
al_destroy_bitmap(game->level.moonwalk.derpy_walkcycle);
}
void Moonwalk_Unload(struct Game *game) {
@ -125,7 +123,7 @@ void Moonwalk_Unload(struct Game *game) {
game->level.moonwalk.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->level.moonwalk.fade_bitmap);
al_draw_bitmap(game->level.moonwalk.image,0,0,0);
al_draw_bitmap(game->level.moonwalk.derpy, game->level.moonwalk.derpy_pos*al_get_display_width(game->display), al_get_display_height(game->display)-al_get_bitmap_height(game->level.moonwalk.derpy), ALLEGRO_FLIP_HORIZONTAL);
al_draw_bitmap(game->level.derpy, game->level.moonwalk.derpy_pos*al_get_display_width(game->display), al_get_display_height(game->display)-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL);
al_draw_textf(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level);
al_draw_text(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");
al_set_target_bitmap(al_get_backbuffer(game->display));

View file

@ -160,7 +160,7 @@ struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enu
return action;
}
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay) {
struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay) {
struct TM_Action *action = malloc(sizeof(struct TM_Action));
if (background) {
struct TM_Action *pom = background;
@ -187,6 +187,7 @@ void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum T
PrintConsole(game, "Timeline Manager: init action (background) %d", action->id);
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
}
return action;
}
void TM_AddDelay(float delay) {
@ -276,7 +277,7 @@ void TM_Destroy() {
}
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg) {
struct TM_Arguments* tmp;
struct TM_Arguments* tmp = args;
if (!args) {
tmp = malloc(sizeof(struct TM_Arguments));
tmp->value = arg;
@ -300,3 +301,10 @@ void TM_DestroyArgs(struct TM_Arguments* args) {
args = pom;
}
}
bool TM_Initialized() {
if (game) return true;
return false;
}
// TODO: write TM_AddQueuedBackgroundAction

View file

@ -48,9 +48,10 @@ void TM_Init(struct Game* game);
void TM_Process();
void TM_HandleEvent(ALLEGRO_EVENT *ev);
struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args);
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay);
struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay);
void TM_AddDelay(float delay);
void TM_Pause(bool pause);
void TM_Destroy();
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg);
void TM_DestroyArgs(struct TM_Arguments* args);
bool TM_Initialized();