bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewportWidth, game->viewportHeight)); } float* fadeloop; ALLEGRO_BITMAP* fade_bitmap; fadeloop = (float*)action->arguments->value; fade_bitmap = (ALLEGRO_BITMAP*)action->arguments->next->value; if (state == TM_ACTIONSTATE_INIT) { *fadeloop = 0; al_set_target_bitmap(fade_bitmap); al_clear_to_color(al_map_rgb(0,0,0)); al_set_target_bitmap(al_get_backbuffer(game->display)); } else if (state == TM_ACTIONSTATE_RUNNING) { *fadeloop+=10; if (*fadeloop>=256) return true; } else if (state == TM_ACTIONSTATE_DRAW) { al_draw_tinted_bitmap(fade_bitmap,al_map_rgba_f(1,1,1,*fadeloop/255.0),0,0,0); } else if (state == TM_ACTIONSTATE_DESTROY) { PrintConsole(game, "Leaving level with %d HP", (int)(game->level.hp*100)); al_destroy_bitmap(fade_bitmap); free(fadeloop); Level_Unload(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_MAP; TM_DestroyArgs(action->arguments); action->arguments = NULL; } return false; }
bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(game->viewportWidth, game->viewportHeight)); } float* fadeloop; ALLEGRO_BITMAP* fade_bitmap; fadeloop = (float*)action->arguments->value; fade_bitmap = (ALLEGRO_BITMAP*)action->arguments->next->value; if (state == TM_ACTIONSTATE_INIT) { *fadeloop = 255; al_set_target_bitmap(fade_bitmap); al_clear_to_color(al_map_rgb(0,0,0)); al_set_target_bitmap(al_get_backbuffer(game->display)); } else if (state == TM_ACTIONSTATE_RUNNING) { *fadeloop-=10; if (*fadeloop<=0) return true; } else if (state == TM_ACTIONSTATE_DRAW) { al_draw_tinted_bitmap(fade_bitmap,al_map_rgba_f(1,1,1,*fadeloop/255.0),0,0,0); } else if (state == TM_ACTIONSTATE_DESTROY) { al_destroy_bitmap(fade_bitmap); free(fadeloop); TM_DestroyArgs(action->arguments); action->arguments = NULL; al_play_sample_instance(game->level.music); } return false; }
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(float))); action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(bool))); } tmp = (float*)action->arguments->value; in = (bool*)action->arguments->next->value; if (state == TM_ACTIONSTATE_INIT) { *tmp = 0; *in = true; /*PrintConsole(game, "WELCOME INIT");*/ } else if (state == TM_ACTIONSTATE_RUNNING) { /*PrintConsole(game, "WELCOME RUNNING FADE=%f, IN=%d", *in); */ float fade = *tmp; if (fade>255) fade=255; if (*tmp > 2048) { *tmp=255; *in=false; } if (*in) { *tmp+=10; } else { *tmp-=10; if (*tmp<=0) { return true; } } } else if (state == TM_ACTIONSTATE_DRAW) { al_draw_tinted_bitmap(game->level.welcome, al_map_rgba_f(*tmp/255.0,*tmp/255.0,*tmp/255.0,*tmp/255.0), 0, 0, 0); } else if (state == TM_ACTIONSTATE_DESTROY) { free(action->arguments->value); free(action->arguments->next->value); TM_DestroyArgs(action->arguments); action->arguments = NULL; } return false; }
bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state == TM_ACTIONSTATE_INIT) { float* f = (float*)malloc(sizeof(float)); *f = 0; ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)malloc(sizeof(ALLEGRO_AUDIO_STREAM*)); *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, false); al_set_audio_stream_gain(*stream, 2.00); action->arguments = TM_AddToArgs(action->arguments, (void*)f); action->arguments = TM_AddToArgs(action->arguments, (void*)stream); action->arguments->next->next = NULL; } else 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); } else 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) || (state == TM_ACTIONSTATE_START)) { 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; 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; }
void Gamestate_Start(struct Game *game, struct GamestateResources* data) { data->pos = 1; data->fade = 0; data->tan = 64; data->tick = 0; data->fadeout = false; data->underscore=true; strcpy(data->text, "#"); TM_AddDelay(data->timeline, 300); TM_AddQueuedBackgroundAction(data->timeline, FadeIn, TM_AddToArgs(NULL, 1, data), 0, "fadein"); TM_AddDelay(data->timeline, 1500); TM_AddAction(data->timeline, Play, TM_AddToArgs(NULL, 1, data->kbd), "playkbd"); TM_AddQueuedBackgroundAction(data->timeline, Type, TM_AddToArgs(NULL, 1, data), 0, "type"); TM_AddDelay(data->timeline, 3200); TM_AddAction(data->timeline, Play, TM_AddToArgs(NULL, 1, data->key), "playkey"); TM_AddDelay(data->timeline, 50); TM_AddAction(data->timeline, FadeOut, TM_AddToArgs(NULL, 1, data), "fadeout"); TM_AddDelay(data->timeline, 1000); TM_AddAction(data->timeline, End, NULL, "end"); al_play_sample_instance(data->sound); }
bool Type(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { struct GamestateResources *data = TM_GetArg(action->arguments, 0); if (state == TM_ACTIONSTATE_RUNNING) { strncpy(data->text, text, data->pos++); data->text[data->pos] = 0; if (strcmp(data->text, text) != 0) { TM_AddBackgroundAction(data->timeline, Type, TM_AddToArgs(NULL, 1, data), 60 + rand() % 60, "type"); } else{ al_stop_sample_instance(data->kbd); } return true; } return false; }
bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { int* count; if (!action->arguments) { action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(int))); } count = (int*)action->arguments->value; if (state == TM_ACTIONSTATE_INIT) { *count = 0; } else if (state == TM_ACTIONSTATE_RUNNING) { if (rand()%(10000/(int)(85*game->level.speed_modifier))<=3) { PrintConsole(game, "OBSTACLE %d", *count); (*count)++; struct Obstacle *obst = malloc(sizeof(struct Obstacle)); obst->prev = NULL; obst->x = 100; obst->y = (rand()%91)-1; obst->speed = 1; obst->points = -10; 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; if (rand()%100<=50) { obst->callback= NULL; obst->data = NULL; obst->points = -5; obst->bitmap = &(game->level.dodger.obst_bmps.badmuffin); } else if (rand()%100<=12) { obst->callback= &Obst_RotateSin; obst->data = malloc(sizeof(float)); *((float*)obst->data) = 0; obst->points = 8; obst->bitmap = &(game->level.dodger.obst_bmps.muffin); } else if (rand()%100<=12) { obst->callback= &Obst_RotateSin; obst->data = malloc(sizeof(float)); *((float*)obst->data) = 0; obst->points = 4; obst->bitmap = &(game->level.dodger.obst_bmps.cherry); } else if (rand()%100<=65) { obst->callback= &Obst_MoveUp; if (rand()%100<=80) obst->bitmap = &(game->level.dodger.obst_bmps.pie1); else { obst->bitmap = &(game->level.dodger.obst_bmps.pie2); obst->points = -12; } obst->data = malloc(sizeof(float)); *((float*)obst->data) = 0.25+(rand()%50/100.0); obst->y*=1.8; obst->angle = ((rand()%50)/100.0)-0.25; } else if (rand()%100<=80) { obst->callback = &Obst_MoveSin; obst->data = malloc(sizeof(float)); *((float*)obst->data) = 0; obst->bitmap = &(game->level.dodger.obst_bmps.pig); obst->rows = 3; obst->cols = 3; obst->speed = 1.2; obst->anim_speed = 2; obst->points = -20; } else { obst->callback = &Obst_MoveUpDown; obst->bitmap = &(game->level.dodger.obst_bmps.screwball); obst->data = malloc(sizeof(bool)); *((bool*)obst->data) = rand()%2; obst->rows = 4; obst->cols = 4; obst->speed = 1.1; obst->anim_speed = 2; obst->points = -25; } if (game->level.dodger.obstacles) { game->level.dodger.obstacles->prev = obst; obst->next = game->level.dodger.obstacles; } else { obst->next = NULL; } game->level.dodger.obstacles = obst; if (*count > 128) return true; } } else if (state == TM_ACTIONSTATE_DESTROY) { free(action->arguments->value); TM_DestroyArgs(action->arguments); action->arguments = NULL; } return false; }