/* start the game from level 0 */ void dot_game_initialize(void * data, bool demo_seed) { APP_INSTANCE * app = (APP_INSTANCE *)data; if(demo_seed) { t3f_srand(&app->rng_state, app->demo_seed); } else { t3f_srand(&app->rng_state, time(0)); } dot_game_setup_level(data, 0); app->game.score = 0; app->game.combo = 0; app->game.lives = 3; app->game.shield.active = false; app->game.old_bg_color = app->level_color[0]; app->game.bg_color_fade = 0.0; if(app->music_enabled) { t3f_play_music(DOT_MUSIC_BGM); } app->game.tick = 0; app->state = DOT_STATE_GAME; }
void paddle_game_init(void) { al_hide_mouse_cursor(t3f_display); /* place paddles */ paddle[0].x = 32.0; paddle[0].y = 240.0 - 64.0 / 2.0; paddle[0].object = t3f_create_collision_object(0, 0, 16, 64, 32, 32, 0); t3f_move_collision_object_xy(paddle[0].object, paddle[0].x, paddle[0].y); paddle[0].active = true; paddle[1].x = 640.0 - 32.0 - 16.0; paddle[1].y = 240.0 - 64.0 / 2.0; paddle[1].object = t3f_create_collision_object(0, 0, 16, 64, 32, 32, 0); t3f_move_collision_object_xy(paddle[1].object, paddle[1].x, paddle[1].y); paddle[1].active = true; /* place ball */ ball.object = t3f_create_collision_object(0, 0, 16, 16, 32, 32, 0); paddle_init_ball(1.0); /* reset scores */ score[0] = 0; score[1] = 0; t3f_srand(&rng_state, time(0)); paddle_state = EXAMPLE_STATE_GAME; t3f_play_music("data/music/game.xm"); }
void paddle_game_exit(void) { t3f_destroy_collision_object(paddle[0].object); t3f_destroy_collision_object(paddle[1].object); t3f_destroy_collision_object(ball.object); al_show_mouse_cursor(t3f_display); t3f_play_music("data/music/menu.xm"); paddle_state = EXAMPLE_STATE_TITLE; }
int main(int argc, char * argv[]) { if(!demo_initialize(argc, argv)) { printf("Failed to initialize!\n"); return 1; } t3f_play_music("demo_music.ogg", 0.0, 0.0); t3f_run(); t3f_stop_music(); return 0; }
int dot_menu_proc_music_yes(void * data, int i, void * pp) { APP_INSTANCE * app = (APP_INSTANCE *)data; app->music_enabled = true; al_set_config_value(t3f_config, "Game Data", "Music Enabled", "true"); if(t3f_get_music_state() != T3F_MUSIC_STATE_PLAYING) { t3f_play_music(DOT_MUSIC_TITLE); } app->current_menu = DOT_MENU_MAIN; dot_update_first_run(); return 1; }
/* finish the game */ void dot_game_exit(void * data) { APP_INSTANCE * app = (APP_INSTANCE *)data; char buf[256] = {0}; /* save high score */ sprintf(buf, "%d", app->game.high_score); al_set_config_value(t3f_config, "Game Data", "High Score", buf); al_save_config_file(al_path_cstr(t3f_config_path, '/'), t3f_config); /* upload score */ if(app->upload_scores && !app->demo_file) { sprintf(buf, "%d", app->game.level + 1); al_stop_timer(t3f_timer); dot_show_message(data, "Uploading score..."); if(t3net_upload_score(DOT_LEADERBOARD_SUBMIT_URL, "dot_to_dot_sweep", DOT_LEADERBOARD_VERSION, "normal", "none", app->user_name, dot_leaderboard_obfuscate_score(app->game.score), buf)) { dot_show_message(data, "Downloading leaderboard..."); app->leaderboard = t3net_get_leaderboard(DOT_LEADERBOARD_RETRIEVE_URL, "dot_to_dot_sweep", DOT_LEADERBOARD_VERSION, "normal", "none", 10, 0); if(app->leaderboard) { app->leaderboard_spot = dot_get_leaderboard_spot(app->leaderboard, app->user_name, dot_leaderboard_obfuscate_score(app->game.score)); } } al_resume_timer(t3f_timer); } /* go back to intro */ dot_intro_setup(data); if(!app->leaderboard) { app->state = DOT_STATE_INTRO; if(app->music_enabled) { t3f_play_music(DOT_MUSIC_TITLE); } } else { if(app->music_enabled) { t3f_stop_music(); } app->state = DOT_STATE_LEADERBOARD; app->current_menu = DOT_MENU_LEADERBOARD_2; } }
bool pp2_play_music(char * fn) { bool ret = false; /* if music played during rewind, ignore */ if(pp2_replay_rewind) { return true; } if(!(t3f_flags & T3F_USE_SOUND)) { return false; } ret = t3f_play_music(fn); pp2_music_playing = true; return ret; }
int dot_menu_proc_leaderboard_main_menu(void * data, int i, void * pp) { APP_INSTANCE * app = (APP_INSTANCE *)data; if(app->leaderboard) { t3net_destroy_leaderboard(app->leaderboard); app->leaderboard = NULL; } dot_intro_setup(data); app->state = DOT_STATE_INTRO; app->current_menu = DOT_MENU_MAIN; if(app->music_enabled) { t3f_play_music(DOT_MUSIC_TITLE); } return 1; }
int main(int argc, char * argv[]) { if(!paddle_initialize()) { return 1; } /* play the menu music - setting both loop points to 0.0 makes the entire song loop - if your song has loop points, pass them here (paramaters are read as seconds) */ t3f_play_music("data/music/menu.xm"); /* run the T^3 Framework - exits when you call t3f_exit() somewhere in your logic routine - clicking the close button in windowed mode calls t3f_exit() */ t3f_run(); /* stop the music before exiting */ t3f_stop_music(); return 0; }
/* the main game logic function */ void dot_game_logic(void * data) { APP_INSTANCE * app = (APP_INSTANCE *)data; int colored = 0; float rgb = 1.0; int i, m; /* handle level bg color transition */ if(app->game.bg_color_fade < 1.0) { app->game.bg_color_fade += 1.0 / 60.0; if(app->game.bg_color_fade > 1.0) { app->game.bg_color_fade = 1.0; } } /* make level colors darker after every 10 levels */ m = app->game.level / 10; for(i = 0; i < m; i++) { rgb *= 0.75; } app->game.bg_color = dot_darken_color(dot_transition_color(app->game.old_bg_color, app->level_color[app->game.level % 10], app->game.bg_color_fade), rgb); dot_game_emo_logic(data); dot_bg_objects_logic(data, app->game.speed); switch(app->game.state) { /* balls move slow for a few seconds so player can get ready */ case DOT_GAME_STATE_START: { app->game.state_tick++; if(app->touch_id >= 0) { if(app->touch_x >= DOT_GAME_TOUCH_START_X && app->touch_x < DOT_GAME_TOUCH_END_X && app->touch_y >= DOT_GAME_TOUCH_START_Y && app->touch_y < DOT_GAME_TOUCH_END_Y) { t3f_play_sample(app->sample[DOT_SAMPLE_GO], 1.0, 0.0, 1.0); app->game.state = DOT_GAME_STATE_PLAY; app->game.state_tick = 0; app->game.player.lost_touch = false; app->game.player.ball.active = true; app->game.player.want_shield = true; app->game.player.touch_offset_x = 0; app->game.player.touch_offset_y = 0; app->game.level_start = false; al_hide_mouse_cursor(t3f_display); } } /* handle ball logic */ colored = dot_game_move_balls(data); break; } case DOT_GAME_STATE_PAUSE: { if(app->touch_id >= 0 && t3f_distance(app->touch_x, app->touch_y, app->game.player.ball.x, app->game.player.ball.y) < DOT_GAME_GRAB_SPOT_SIZE) { app->game.player.touch_offset_x = app->game.player.ball.x - app->touch_x; app->game.player.touch_offset_y = app->game.player.ball.y - app->touch_y; app->game.state = DOT_GAME_STATE_PLAY; al_hide_mouse_cursor(t3f_display); } break; } case DOT_GAME_STATE_DONE: { for(i = 0; i < DOT_MAX_PARTICLES; i++) { if(app->particle[i].active) { break; } } if(i == DOT_MAX_PARTICLES) { dot_game_exit(data); } break; } /* normal game state */ default: { /* handle shield logic */ dot_game_shield_logic(data); /* move player */ dot_game_move_player(data); /* handle ball logic */ colored = dot_game_move_balls(data); dot_game_check_player_collisions(data); /* move on to next level */ if(colored == 0) { dot_game_accumulate_score(data); for(i = 0; i < DOT_GAME_MAX_BALLS; i++) { if(app->game.ball[i].active && app->game.ball[i].type == 6) { dot_game_create_splash_effect(data, app->game.ball[i].x, app->game.ball[i].y, app->game.ball[i].r, app->dot_color[app->game.ball[i].type]); } } if(app->touch_id >= 0) { t3f_touch[app->touch_id].active = false; } al_show_mouse_cursor(t3f_display); app->game.old_bg_color = app->game.bg_color; dot_game_setup_level(data, app->game.level + 1); app->game.bg_color_fade = 0.0; app->game.combo = 0; app->game.shield.active = false; } break; } } if(t3f_key[ALLEGRO_KEY_ESCAPE] || t3f_key[ALLEGRO_KEY_BACK]) { dot_intro_setup(data); app->state = DOT_STATE_INTRO; if(app->music_enabled) { t3f_play_music(DOT_MUSIC_TITLE); } t3f_key[ALLEGRO_KEY_ESCAPE] = 0; t3f_key[ALLEGRO_KEY_BACK] = 0; } app->game.tick++; }
bool initialize(int argc, char * argv[]) { const char * val; ALLEGRO_BITMAP * bp; process_arguments(argc, argv); if(!t3f_initialize(640, 480, 60.0, "The Devil", logic, render, T3F_DEFAULT | T3F_USE_MOUSE)) { return false; } t3f_3d_set_projection(&projection, 0, 0, 640, 480, 320, 240); t3f_3d_select_projection(&projection); animation[ANIMATION_PLAYER] = t3f_load_animation_from_bitmap("data/player.png"); if(!animation[ANIMATION_PLAYER]) { return false; } animation[ANIMATION_DEMON] = t3f_load_animation_from_bitmap("data/demon.png"); if(!animation[ANIMATION_DEMON]) { return false; } animation[ANIMATION_ARCHDEMON] = t3f_load_animation_from_bitmap("data/archdemon.png"); if(!animation[ANIMATION_ARCHDEMON]) { return false; } animation[ANIMATION_PLAYER_SHOT] = t3f_load_animation_from_bitmap("data/player_shot.png"); if(!animation[ANIMATION_PLAYER_SHOT]) { return false; } animation[ANIMATION_ENEMY_SHOT] = t3f_load_animation_from_bitmap("data/enemy_shot.png"); if(!animation[ANIMATION_ENEMY_SHOT]) { return false; } animation[ANIMATION_SPIRIT] = t3f_create_animation(); if(!animation[ANIMATION_SPIRIT]) { return false; } bp = al_load_bitmap("data/spirit0.png"); t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp); t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 0, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5); bp = al_load_bitmap("data/spirit1.png"); t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp); t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 1, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5); bp = al_load_bitmap("data/spirit2.png"); t3f_animation_add_bitmap(animation[ANIMATION_SPIRIT], bp); t3f_animation_add_frame(animation[ANIMATION_SPIRIT], 2, 0, 0, 0, al_get_bitmap_width(bp), al_get_bitmap_height(bp), 0, 5); animation[ANIMATION_LOGO] = t3f_load_animation_from_bitmap("data/logo.png"); if(!animation[ANIMATION_LOGO]) { return false; } animation[ANIMATION_TITLE] = t3f_load_animation_from_bitmap("data/title_logo.png"); if(!animation[ANIMATION_TITLE]) { return false; } sprite_sheet = al_create_bitmap(512, 512); if(!sprite_sheet) { return false; } t3f_start_sprite_sheet(sprite_sheet, T3F_SPRITE_SHEET_TYPE_SPRITES); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_PLAYER]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_DEMON]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_ARCHDEMON]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_PLAYER_SHOT]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_ENEMY_SHOT]); t3f_add_animation_to_sprite_sheet(animation[ANIMATION_SPIRIT]); t3f_finish_sprite_sheet(); font[FONT_GAME] = al_load_bitmap_font("data/default_font.png"); if(!font[FONT_GAME]) { return false; } sample[SAMPLE_GAME_OVER] = al_load_sample("data/game_over.ogg"); if(!sample[SAMPLE_GAME_OVER]) { return false; } sample[SAMPLE_LEVEL_UP] = al_load_sample("data/level_up.ogg"); if(!sample[SAMPLE_LEVEL_UP]) { return false; } sample[SAMPLE_MAX_MULTIPLIER] = al_load_sample("data/max_multiplier.ogg"); if(!sample[SAMPLE_MAX_MULTIPLIER]) { return false; } sample[SAMPLE_HIGH_SCORE] = al_load_sample("data/high_score.ogg"); if(!sample[SAMPLE_HIGH_SCORE]) { return false; } sample[SAMPLE_TWIN_SHOT] = al_load_sample("data/twin_shot.ogg"); if(!sample[SAMPLE_TWIN_SHOT]) { return false; } sample[SAMPLE_TRIPLE_SHOT] = al_load_sample("data/triple_shot.ogg"); if(!sample[SAMPLE_TRIPLE_SHOT]) { return false; } sample[SAMPLE_POWERUP] = al_load_sample("data/powerup.ogg"); if(!sample[SAMPLE_POWERUP]) { return false; } sample[SAMPLE_SHOOT] = al_load_sample("data/shoot.ogg"); if(!sample[SAMPLE_SHOOT]) { return false; } sample[SAMPLE_HIT] = al_load_sample("data/hit.ogg"); if(!sample[SAMPLE_HIT]) { return false; } sample[SAMPLE_DIE] = al_load_sample("data/die.ogg"); if(!sample[SAMPLE_DIE]) { return false; } sample[SAMPLE_MULTIPLIER] = al_load_sample("data/multiplier.ogg"); if(!sample[SAMPLE_MULTIPLIER]) { return false; } cinema = load_cinema("data/intro.cin", 0); if(!cinema) { return false; } ending_cinema = load_cinema("data/ending.cin", 0); if(!ending_cinema) { return false; } level_color[0] = al_map_rgba(131, 0, 0, 255); level_color[1] = al_map_rgba(131, 22, 0, 255); level_color[2] = al_map_rgba(131, 46, 0, 255); level_color[3] = al_map_rgba(131, 68, 0, 255); level_color[4] = al_map_rgba(131, 99, 0, 255); level_color[5] = al_map_rgba(131, 126, 0, 255); level_color[6] = al_map_rgba(101, 131, 0, 255); level_color[7] = al_map_rgba(77, 131, 0, 255); level_color[8] = al_map_rgba(0, 131, 73, 255); level_color[9] = al_map_rgba(0, 105, 131, 255); level_color[10] = al_map_rgba(0, 135, 254, 255); hyperlink_set_driver(NULL); val = al_get_config_value(t3f_config, "Save Data", "High Score"); if(val) { high_score = atoi(val); } t3f_play_music("data/title.xm", 0.0, 0.0); state = STATE_LOGO; return true; }
void dot_intro_logic(void * data) { APP_INSTANCE * app = (APP_INSTANCE *)data; int r; if(app->entering_name) { r = dot_text_entry_logic(); if(r != 0) { app->entering_name = false; } if(r == 1) { al_set_config_value(t3f_config, "Game Data", "User Name", app->user_name); } } dot_game_emo_logic(data); dot_bg_objects_logic(data, DOT_GAME_LEVEL_BASE_SPEED); switch(app->intro_state) { case DOT_INTRO_STATE_LOGO: { if(app->tick >= 900) { app->intro_state = DOT_INTRO_STATE_LOGO_OUT; } break; } case DOT_INTRO_STATE_LOGO_OUT: { app->logo_ox -= 4.0; app->credits_ox -= 4.0; if(app->logo_ox < -t3f_virtual_display_width) { app->credits.state = DOT_CREDITS_STATE_IN; app->intro_state = DOT_INTRO_STATE_CREDITS; } break; } case DOT_INTRO_STATE_CREDITS: { dot_credits_logic(&app->credits); if(app->credits.current_credit >= app->credits.credits) { app->credits.state = DOT_CREDITS_STATE_WAIT; app->intro_state = DOT_INTRO_STATE_CREDITS_OUT; } break; } case DOT_INTRO_STATE_CREDITS_OUT: { app->logo_ox += 4.0; app->credits_ox += 4.0; if(app->logo_ox >= 0.0) { app->credits.current_credit = 0; app->tick = 0; app->intro_state = DOT_INTRO_STATE_LOGO; } break; } } app->tick++; if(!app->entering_name && app->menu_showing) { t3f_process_gui(app->menu[app->current_menu], app); } if(!app->menu_showing) { if(t3f_mouse_button[0]) { app->menu_showing = true; t3f_mouse_button[0] = false; } } if(t3f_key[ALLEGRO_KEY_ESCAPE] || t3f_key[ALLEGRO_KEY_BACK]) { if(app->desktop_mode) { if(app->menu_showing) { if(app->current_menu == DOT_MENU_MAIN) { dot_intro_setup(data); app->menu_showing = false; } else { if(app->current_menu == DOT_MENU_LEADERBOARD_2) { t3f_play_music(DOT_MUSIC_TITLE); } app->current_menu = DOT_MENU_MAIN; } } else { t3f_exit(); } } else { if(app->current_menu == DOT_MENU_MAIN) { t3f_exit(); } else { app->current_menu = DOT_MENU_MAIN; } } t3f_key[ALLEGRO_KEY_ESCAPE] = 0; t3f_key[ALLEGRO_KEY_BACK] = 0; } }