Пример #1
0
DemoMSmall::DemoMSmall(clan::DisplayWindow &window) : window(window)
{
	window.set_title("LinearParticle Example - MSmall ");
	sc.connect(window.sig_window_close(), clan::bind_member(this, &DemoMSmall::on_window_close));
	canvas = clan::Canvas(window);
	sc.connect(window.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
	surface = clan::Sprite(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
	particle = clan::make_unique<L_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 = clan::make_unique<L_ExplosionEffect>(320, 240, 16, 10, 12, 0.1);
	effect->add(particle.get());

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

	font = clan::Font("Arial", 16 );
	last_time = clan::System::get_time();

}
Пример #2
0
DemoCircle::DemoCircle(clan::DisplayWindow &window) : window(window)
{
	window.set_title("LinearParticle Example - Circle ");
	sc.connect(window.sig_window_close(), clan::bind_member(this, &DemoCircle::on_window_close));
	canvas = clan::Canvas(window);
	sc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &DemoCircle::on_key_up));

	// initialize LinearParticle
	L_ParticleSystem::init();

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

	// create a sample of particle with life of 2000
	particle = clan::make_unique<L_Particle>(&surface, 2000);
	particle->set_size(2.0);
	particle->coloring2( L_Color(255,130,255,20), L_Color(0,255,10,10) );

	dropping_period = 16;
	// create dropping effect with period of 16
	dropper = clan::make_unique<L_DroppingEffect>(480,240,dropping_period);

	// add the particle to dropper effect
	dropper->add(particle.get());

	// initialize particle effect
	dropper->initialize();

	font = clan::Font("tahoma", 16 );

	last_time = clan::System::get_time();

}
Пример #3
0
	App()
	{
		clan::OpenGLTarget::set_current();

		window = DisplayWindow("Image test", 1024, 768);

		canvas = Canvas(window);

		// Connect the Window close event
		sc.connect(window.sig_window_close(), this, &App::on_window_close);

		quit = false;

		ResourceManager resources = clan::XMLResourceManager::create(clan::XMLResourceDocument("resources.xml"));

		Texture2D texture(canvas, "Images/square.png");

		image_texture = Image(texture, Rect(0, 0, texture.get_size()));
		image_loaded = Image(canvas, "Images/square.png");
		image_resources = Image::resource(canvas, "entire_image", resources);
		image_copy = Image(image_texture);
		image_top_right = Image::resource(canvas, "image_top_right", resources);
		image_bottom_right = Image::resource(canvas, "image_bottom_right", resources);
		image_black = Image::resource(canvas, "image_black", resources);

		small_font = Font("Tahoma", 10);

		//Console::write_line("Color: %1,%2,%3,%4", image_resources.get_color().r, image_resources.get_color().g, image_resources.get_color().b, image_resources.get_color().a);
		//Console::write_line("Scale: %1,%2", image_resources.get_scale_x(), image_resources.get_scale_y());
		//Console::write_line("Translation: %1,%2,%3", image_resources.get_alignment());

	}
Пример #4
0
Particle::Particle(clan::DisplayWindow &window) : window(window)
{
	window.set_title("LinearParticle Example - Main Menu");

	// Connect the Window close event
	sc.connect(window.sig_window_close(), clan::bind_member(this, &Particle::on_window_close));

	// Get the graphic context
	canvas = clan::Canvas(window);
	font = clan::Font("tahoma", 20);

}
Пример #5
0
DemoCMotion::DemoCMotion(clan::DisplayWindow &window) : window(window), fontColor(255.0f, 255.0f, 255.0f), blendingMode(L_ADDITIVE_BLENDING)
{
	window.set_title("LinearParticle Example - CMotion ");
	sc.connect(window.sig_window_close(), clan::bind_member(this, &DemoCMotion::on_window_close));
	canvas = clan::Canvas(window);

	sc.connect(window.get_keyboard().sig_key_up(), [&](const clan::InputEvent &input){on_key_up(input, canvas); });

	// initialize LinearParticle
	L_ParticleSystem::init();

	// create surface to be used for particle and set the alignment
	surface = clan::Sprite(canvas,"Resources/sketch.png");
	surface.set_alignment(clan::origin_center);
	font = clan::Font("Arial", 16);

	motion_ctrl.set_speed_limit(0.65f);
	motion_ctrl.set_point_acceleration( 320, 240, 0.001f );

	particle = clan::make_unique<L_Particle>(&surface, 3000);
	particle->rotating4();
	particle->set_motion_controller(&motion_ctrl);


	L_Vector shooting_vector;
	shooting_vector.set2( 0.4, L_DEGREE_TO_RADIAN(-90) );
	effect = clan::make_unique<L_ShootingEffect>(460, 360, shooting_vector, 16, 6);
	effect->add(particle.get());
	effect->set_width_interval(20);
	effect->set_angle_interval(L_DEGREE_TO_RADIAN(40));
	effect->set_life_distortion(600);
	effect->set_size_distortion(0.4f);
	effect->set_speed_distortion(0.06f);
	effect->initialize();

	bg_color = clan::Colorf(0.0f,0.0f,0.0f);

	set_style(canvas);

	last_time = clan::System::get_time();

}
Пример #6
0
int DemoShooting::run(clan::DisplayWindow &window)
{
    clan::SlotContainer cc;
	window.set_title("LinearParticle Example - Shooting ");

	cc.connect(window.sig_window_close(), clan::bind_member(this, &DemoShooting::on_window_close));
	clan::Canvas canvas(window);
	cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &DemoShooting::on_key_up));

	// initialize LinearParticle
	L_ParticleSystem::init();

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

	motion_ctrl.set_1d_acceleration(-0.0003);

	L_Particle particle(&surface,3000);
	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.rotating2(L_2PI);
	particle.set_motion_controller(&motion_ctrl);

	L_Vector shooting_vector;
	shooting_vector.set2( 0.4, L_DEGREE_TO_RADIAN(-90) );
	effect = new L_ShootingEffect(460,360,shooting_vector,16,4);
	effect->add(&particle);
	effect->set_width_interval(100);
	effect->set_angle_interval(L_DEGREE_TO_RADIAN(45));
	effect->set_life_distortion(600);
	effect->set_size_distortion(0.4f);
	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();

	while(!quit)
	{
		canvas.clear();

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

		/* the maximum time step is set to 50milisecs to avoid artifacts
		and errors caused by low frame rate to be less noticeable. */
		while( time_run > 50 )
		{
			run_a_step(50);
			time_run -= 50;
		}

		if( time_run > 0 )
			run_a_step(time_run);


		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,425,"F1 : hide/show menu");
			font.draw_text(canvas,10,440,"Space : trigger random sleep");
		}


		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;
}
Пример #7
0
int DemoSimple::run(clan::DisplayWindow &window)
{
	quit = false;

	// Set the window
	window.set_title("LinearParticle Example - Simple ");

    clan::SlotContainer cc;
	// Connect the Window close event
	cc.connect(window.sig_window_close(), clan::bind_member(this, &DemoSimple::on_window_close));

	// Connect a keyboard handler to on_key_up()
	cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &DemoSimple::on_input_up));

	// Get the graphic context
	clan::Canvas canvas(window);

	// initialize LinearParticle
	L_ParticleSystem::init();

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

	// create a sample of particle with life of 5000
	L_Particle particle(&surface,5000);

	// create dropping effect with period of 16
	L_DroppingEffect dropper(0,0,16);

	// add the particle to dropper effect
	dropper.add(&particle);

	// initialize particle effect
	dropper.initialize();

	float x_pos = 320;
	float y_pos = 240;
	float x_vel = 3.0f;
	float y_vel = 3.0f;

	clan::Font font(canvas, "tahoma", 16 );

	FramerateCounter frameratecounter;

	// Run until someone presses escape
	while (!quit)
	{
		canvas.clear();

		x_pos += x_vel;
		y_pos += y_vel;

		if( x_pos > 640 || x_pos < 0 )
			x_vel = -x_vel;

		if( y_pos > 480 || y_pos < 0 )
			y_vel = -y_vel;

		dropper.set_position(x_pos, y_pos);
			dropper.trigger();

		/* pass frame time to L_ParticleEffect::run(int) for time based system,
			a constant number would be a reference time unit for frame based system. */
		dropper.run(16);

		// draw dropping effect
		L_DrawParticle(canvas,dropper);

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

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

	// deinitialize LinearParticle
	L_ParticleSystem::deinit();

	return 0;
}
Пример #8
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;
}