Пример #1
0
void DemoShooting::run_a_step(int time)
{
	static double rad = 0.0;
	static clan::Vec2f current_pos(460, 360);
	static clan::Vec2f prev_pos;

	rad -= 0.002*time;

	if( rad < L_2PI )
		rad += L_2PI;

	prev_pos = current_pos;
	current_pos.x = 140*cos(rad)+320;
	current_pos.y = 140*sin(rad)+360;

	L_Vector vel;
	vel.set( (current_pos.x-prev_pos.x)/time,
				(current_pos.y-prev_pos.y)/time );

	effect->trigger();

	/* it's recommended to use L_ParticleEffect::set_velocity() than just
	to use L_ParticleEffect::set_position() if the desired position of effect
	is not static or jumping. */
	effect->set_velocity(vel);
	effect->run(time);

	/* set position(although velocity has been set before) to avoid error
	being accumulated.*/
	effect->set_position(current_pos.x, current_pos.y);
}
Пример #2
0
bool DemoMSmall::update()
{
	canvas.clear();
	clan::InputDevice &keyboard = window.get_keyboard();
	static L_REAL x_pos = 320;
	static L_REAL y_pos = 240;

	L_REAL x_vel = 0;
	L_REAL y_vel = 0;
	if( keyboard.get_keycode(clan::keycode_up) )
		y_vel = -0.2;

	else if( keyboard.get_keycode(clan::keycode_down))
		y_vel = 0.2;

	if( keyboard.get_keycode(clan::keycode_left))
		x_vel = -0.2;

	else if( keyboard.get_keycode(clan::keycode_right))
		x_vel = 0.2;

	L_Vector vel;
	vel.set( x_vel, y_vel );

	uint64_t current_time = clan::System::get_time();
	int time_run = current_time - last_time;
	last_time = current_time;

	x_pos += x_vel*time_run;
	y_pos += y_vel*time_run;

	effect->trigger();
	effect->set_velocity(vel);
	effect->run(time_run);
	effect->set_position(x_pos, y_pos);
	L_DrawParticle(canvas, effect.get());

	if( show_menu )
	{
		frameratecounter.show_fps(canvas, font);

		font.draw_text(canvas, 10, 30, clan::string_format("#Particle : %1", effect->get_particle_num()));

		font.draw_text(canvas,10,410,"F1 : hide/show menu");
		font.draw_text(canvas,10,425,"Space : trigger random sleep");
		font.draw_text(canvas,10,440,"Arrow keys : move the effect");
	}


	window.flip(0);	// Set to "1" to lock to screen refresh rate
	frameratecounter.frame_shown();

	if (quit)
	{
		// deinitialize LinearParticle
		L_ParticleSystem::deinit();
	}

	return !quit;
}
Пример #3
0
void L_Particle::motion_process(void)
{
	if( motion_controller != NULL )
	{
		if( motion_controller->motion_type == L_1D_ACCELERATION )
			vec = vec + accel_vec_1d_to_2d.get_scaled_vector(time_elapesed);

		else if( motion_controller->motion_type == L_2D_ACCELERATION )
			vec = vec + motion_controller->acceleration_2d.get_scaled_vector(time_elapesed);

		else if( motion_controller->motion_type == L_POINT_ACCELERATION )
		{
			L_Vector acc = motion_controller->acceleration_point_pos - L_Vector(x_pos, y_pos);
			acc.set_magnitude(motion_controller->acceleration_point_mag);

			vec = vec + acc.get_scaled_vector(time_elapesed);
		}

		if( vec.get_sqr_magnitude() > motion_controller->speed_limit_sqr )
			vec.set_magnitude(motion_controller->speed_limit);
	}

	x_pos += vec.x*time_elapesed;
	y_pos += vec.y*time_elapesed;
}
Пример #4
0
int DemoMSmall::run(clan::DisplayWindow &window)
{
    clan::SlotContainer cc;
	window.set_title("LinearParticle Example - MSmall ");
	cc.connect(window.sig_window_close(), clan::bind_member(this, &DemoMSmall::on_window_close));
	clan::Canvas canvas(window);
	cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &DemoMSmall::on_key_up));

	// initialize LinearParticle
	L_ParticleSystem::init();

	// create surface to be used for particle and set the alignment
	clan::Sprite surface(canvas, "Resources/small.png");
	surface.set_alignment(clan::origin_center);

	motion_ctrl.set_speed_limit(0.1); // set max speed of particle
	motion_ctrl.set_1d_acceleration(-0.0003); // set deceleration

	// create sample of particle
	L_Particle particle(&surface,2000);
	particle.set_color(L_Color(255,110,60,255));
	particle.coloring2(L_Color(255,110,60,255),L_Color(0,200,100,255),0.6);
	particle.set_motion_controller(&motion_ctrl); // assign motion cotroller


	// create explosion effect
	effect = new L_ExplosionEffect(320,240,16,10,12,0.1);
	effect->add(&particle);

	// apply random life distortion for each emitted particle
	effect->set_life_distortion(700);
	effect->initialize();

	char str[32];
	quit = false;
	show_menu = true;

	clan::Font font(canvas, "Arial", 16 );
	FramerateCounter frameratecounter;
	clan::ubyte64 last_time = clan::System::get_time();

	clan::InputDevice &keyboard = window.get_ic().get_keyboard();
	while(!quit)
	{
		canvas.clear();


		static L_REAL x_pos = 320;
		static L_REAL y_pos = 240;

		L_REAL x_vel = 0;
		L_REAL y_vel = 0;
		if( keyboard.get_keycode(clan::keycode_up) )
			y_vel = -0.2;

		else if( keyboard.get_keycode(clan::keycode_down))
			y_vel = 0.2;

		if( keyboard.get_keycode(clan::keycode_left))
			x_vel = -0.2;

		else if( keyboard.get_keycode(clan::keycode_right))
			x_vel = 0.2;

		L_Vector vel;
		vel.set( x_vel, y_vel );

		clan::ubyte64 current_time = clan::System::get_time();
		int time_run = current_time - last_time;
		last_time = current_time;

		x_pos += x_vel*time_run;
		y_pos += y_vel*time_run;

		effect->trigger();
		effect->set_velocity(vel);
		effect->run(time_run);
		effect->set_position(x_pos, y_pos);
		L_DrawParticle(canvas, effect);

		if( show_menu )
		{
			frameratecounter.show_fps(canvas, font);

			sprintf(str,"#Particle : %d", effect->get_particle_num());
			font.draw_text(canvas,10,30,str);

			font.draw_text(canvas,10,410,"F1 : hide/show menu");
			font.draw_text(canvas,10,425,"Space : trigger random sleep");
			font.draw_text(canvas,10,440,"Arrow keys : move the effect");
		}


		window.flip(0);	// Set to "1" to lock to screen refresh rate
		frameratecounter.frame_shown();

		clan::KeepAlive::process(0);
	}

	delete effect;

	// deinitialize LinearParticle
	L_ParticleSystem::deinit();

	return 0;
}