Exemplo n.º 1
0
static void * t3f_fade_music_thread(void * arg)
{
    ALLEGRO_TIMER * timer;
    ALLEGRO_EVENT_QUEUE * queue;
    bool done = false;
    ALLEGRO_EVENT event;
    float s = t3f_music_fade_speed / 50.0;

    timer = al_create_timer(1.0 / s);
    if(!timer)
    {
        return NULL;
    }
    queue = al_create_event_queue();
    if(!queue)
    {
        return NULL;
    }
    al_register_event_source(queue, al_get_timer_event_source(timer));
    while(!done)
    {
        al_wait_for_event(queue, &event);
        al_set_audio_stream_gain(t3f_stream, t3f_music_target_volume);
        t3f_music_target_volume -= s;
        if(t3f_music_target_volume <= 0.0)
        {
            t3f_stop_music();
            done = true;
        }
    }
    return NULL;
}
Exemplo n.º 2
0
void pp2_stop_music(void)
{
	if(pp2_music_playing)
	{
		t3f_stop_music();
		pp2_music_playing = false;
	}
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
/* 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;
	}
}
Exemplo n.º 5
0
int dot_menu_proc_music_no(void * data, int i, void * pp)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;

	app->music_enabled = false;
	al_set_config_value(t3f_config, "Game Data", "Music Enabled", "false");
	if(t3f_get_music_state() == T3F_MUSIC_STATE_PLAYING)
	{
		al_stop_timer(t3f_timer);
		t3f_stop_music();
		al_resume_timer(t3f_timer);
	}
	app->current_menu = DOT_MENU_MAIN;
	dot_update_first_run();
	return 1;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
/* logic routines, passed to T^3 Framework */
void paddle_logic(void * data)
{
	/* logic switch, use different logic for each state */
	switch(paddle_state)
	{
		
		case EXAMPLE_STATE_TITLE:
		{
			t3f_process_gui(paddle_menu, data);
			break;
		}
		
		case EXAMPLE_STATE_GAME:
		{
			
			/* return to menu if Escape pressed */
			if(t3f_key[ALLEGRO_KEY_ESCAPE])
			{
				paddle_game_exit();
			}
			
			/* store old paddle positions */
			paddle[0].oy = paddle[0].y;
			paddle[1].oy = paddle[1].y;
			
			/* move paddle */
			paddle[0].y = t3f_mouse_y - 32;
			if(paddle[0].y < 0)
			{
				paddle[0].y = 0;
			}
			if(paddle[0].y > 480.0 - 64.0)
			{
				paddle[0].y = 480.0 - 64.0;
			}
			t3f_move_collision_object_xy(paddle[0].object, paddle[0].x, paddle[0].y);
			
			/* move CPU paddle */
			if(ball.vx > 0.0)
			{
				if(ball.x > paddle[1].x - 24)
				{
					paddle[1].y += paddle[1].dvy;
				}
				else
				{
					if(paddle[1].y < paddle[1].dy - 2.0)
					{
						paddle[1].y += 2.0;
						if(paddle[1].y > 480.0 - 64.0)
						{
							paddle[1].y = 480.0 - 64.0;
						}
					}
					else if(paddle[1].y > paddle[1].dy + 2.0)
					{
						paddle[1].y -= 2.0;
						if(paddle[1].y < 0.0)
						{
							paddle[1].y = 0.0;
						}
					}
				}
				/* correct paddle position so it doesn't go past edge */
				if(paddle[1].y > 480.0 - 64.0)
				{
					paddle[1].y = 480.0 - 64.0;
				}
				if(paddle[1].y < 0.0)
				{
					paddle[1].y = 0.0;
				}
			}
			t3f_move_collision_object_xy(paddle[1].object, paddle[1].x, paddle[1].y);
			
			/* move ball */
			ball.x += ball.vx;
			t3f_move_collision_object_xy(ball.object, ball.x, ball.y);
			if(ball.vx < 0 && t3f_check_object_collision(paddle[0].object, ball.object))
			{
				al_play_sample(paddle_sample[EXAMPLE_SAMPLE_HIT], 0.5, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
				ball.x = paddle[0].x + 16.0;
				ball.vx = -ball.vx;
				ball.vx += EXAMPLE_SPEED_INCREASE;
				ball.vy -= (paddle[0].oy - paddle[0].y) / 4.0;
				if(ball.vy < -3.0)
				{
					ball.vy = -3.0;
				}
				if(ball.vy > 3.0)
				{
					ball.vy = 3.0;
				}
				paddle[1].dy = paddle_ai_predict_y() - 32 + 8.0;
				paddle[1].dvy = t3f_drand(&rng_state) * 6.0 - 3.0;
			}
			else if(ball.vx > 0 && t3f_check_object_collision(paddle[1].object, ball.object))
			{
				al_play_sample(paddle_sample[EXAMPLE_SAMPLE_HIT], 0.5, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
				ball.x = paddle[1].x - 16.0 - 1.0;
				ball.vx = -ball.vx;
				ball.vx -= EXAMPLE_SPEED_INCREASE;
				ball.vy -= (paddle[1].oy - paddle[1].y) / 4.0;
				if(ball.vy < -3.0)
				{
					ball.vy = -3.0;
				}
				if(ball.vy > 3.0)
				{
					ball.vy = 3.0;
				}
			}
			if(ball.x < -16.0)
			{
				al_play_sample(paddle_sample[EXAMPLE_SAMPLE_SCORE], 0.5, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
				score[1]++;
				if(score[1] >= 5)
				{
					t3f_stop_music();
					paddle_state = EXAMPLE_STATE_GAME_OVER;
				}
				paddle_init_ball(1.0);
			}
			else if(ball.x > 640.0)
			{
				al_play_sample(paddle_sample[EXAMPLE_SAMPLE_SCORE], 0.5, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
				score[0]++;
				if(score[0] >= 5)
				{
					t3f_stop_music();
					paddle_state = EXAMPLE_STATE_GAME_OVER;
				}
				paddle_init_ball(-1.0);
			}
			ball.y += ball.vy;
			if(ball.y < 0.0)
			{
				ball.y = 0.0;
				ball.vy = -ball.vy;
			}
			else if(ball.y > 480.0 - 16.0)
			{
				ball.y = 480.0 - 16.0;
				ball.vy = -ball.vy;
			}
			break;
		}
		
		case EXAMPLE_STATE_GAME_OVER:
		{
			
			/* return to menu if Escape pressed */
			if(t3f_mouse_button[0] || t3f_key[ALLEGRO_KEY_ESCAPE])
			{
				paddle_game_exit();
			}
			
			break;
		}
	}
}
Exemplo n.º 8
0
static void * t3f_play_music_thread(void * arg)
{
    const char * ext = NULL;
    ALLEGRO_PATH * path = NULL;
    int loop_points = 0;
    float loop_start = -1;
    float loop_end = -1;
    bool loop_disabled = false;
    const char * val = NULL;
    ALLEGRO_CONFIG * config = NULL;

    ALLEGRO_DEBUG("music thread start\n");
    t3f_music_gain = 1.0;
    al_lock_mutex(t3f_music_mutex);
    if(t3f_stream)
    {
        t3f_stop_music();
    }
    ALLEGRO_DEBUG("setting file interface\n");
    al_set_new_file_interface(t3f_music_thread_file_interface);
    t3f_stream = al_load_audio_stream(t3f_music_thread_fn, 4, 4096);
    if(!t3f_stream)
    {
        al_unlock_mutex(t3f_music_mutex);
        t3f_set_music_state(T3F_MUSIC_STATE_OFF);
        return NULL;
    }

    ALLEGRO_DEBUG("configuring music\n");
    /* look for loop data */
    path = al_create_path(t3f_music_thread_fn);
    if(path)
    {
        al_set_path_extension(path, ".ini");
        config = al_load_config_file(al_path_cstr(path, '/'));
        if(config)
        {
            val = al_get_config_value(config, "loop", "disabled");
            if(val && !strcasecmp(val, "true"))
            {
                loop_disabled = true;
            }
            if(!loop_disabled)
            {
                val = al_get_config_value(config, "loop", "start");
                if(val)
                {
                    loop_start = atof(val);
                    loop_points++;
                }
                val = al_get_config_value(config, "loop", "end");
                if(val)
                {
                    loop_end = atof(val);
                    loop_points++;
                }
            }
            val = al_get_config_value(config, "settings", "gain");
            if(val)
            {
                t3f_music_gain = atof(val);
                if(t3f_music_gain < 0.0)
                {
                    t3f_music_gain = 0;
                }
                if(t3f_music_gain > 10.0)
                {
                    t3f_music_gain = 10.0;
                }
            }
            al_destroy_config(config);
        }
        al_destroy_path(path);
    }

    if(loop_disabled)
    {
        al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_ONCE);
    }
    else
    {
        if(loop_points != 2)
        {
            /* loop entire song unless audio is MOD music */
            ext = t3f_get_music_extension(t3f_music_thread_fn);
            if(strcmp(ext, ".xm") && strcmp(ext, ".it") && strcmp(ext, ".mod") && strcmp(ext, ".s3m"))
            {
                al_set_audio_stream_loop_secs(t3f_stream, 0.0, al_get_audio_stream_length_secs(t3f_stream));
                al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP);
            }
            else
            {
                al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP);
            }
        }
        else
        {
            al_set_audio_stream_loop_secs(t3f_stream, loop_start, loop_end);
            al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP);
        }
    }
    ALLEGRO_DEBUG("start the music\n");
    t3f_music_volume = t3f_new_music_volume;
    al_set_audio_stream_gain(t3f_stream, t3f_music_volume * t3f_music_gain);
    al_attach_audio_stream_to_mixer(t3f_stream, al_get_default_mixer());
    al_unlock_mutex(t3f_music_mutex);
    t3f_set_music_state(T3F_MUSIC_STATE_PLAYING);
    return NULL;
}