Example #1
0
bool App::update()
{
	game_time.update();
	
	canvas_center.clear(clan::Colorf(0.0f,0.0f,0.0f, 1.0f));
	rock.draw(canvas_center, 0.0f, 0.0f);

	// Move tux
	for (int cnt=0; cnt<num_tuxballs; cnt++)
	{
		tuxballs[cnt].move(tuxballs, game_time.get_time_elapsed() * 1000.0f);
	}

	// Draw tux
	for (int cnt=0; cnt<num_tuxballs; cnt++)
	{
		tuxballs[cnt].draw(canvas_center);
	}

	std::string fps = clan::string_format("%1 fps", clan::StringHelp::float_to_text(game_time.get_updates_per_second(), 1));
	font.draw_text(canvas_center, 150-2, 150-2, fps, clan::Colorf(0.0f, 0.0f, 0.0f, 1.0f));
	font.draw_text(canvas_center, 150, 150, fps, clan::Colorf(1.0f, 1.0f, 1.0f, 1.0f));

	window_center.flip(0);

	return !quit;
}
Example #2
0
bool App::update()
{
	game_time.update();

	canvas.clear(clan::Colorf(0.0f,0.0f,0.0f, 0.0f));
	rock.set_color(clan::Colorf(1.0f, 1.0f, 1.0f, 0.8f));
	rock.draw(canvas, 0.0f, 0.0f);

	// Rotate tux
	rotation += game_time.get_time_elapsed() * 100.0f;
	clan::Angle angle;
	angle.set_degrees(rotation);
	tux.set_angle(angle);

	// Caculate tux position
	clan::Pointf circle_center(  (float) (canvas.get_width()/2), (float) (canvas.get_height()/2) );
	const float radius = 210.0f;
	int tux_circle = 12;
	tux_position.x = -(radius - tux_radius - tux_circle)  * cos( angle.to_radians() / 2.0f );
	tux_position.y = (radius - tux_radius - tux_circle) * sin( angle.to_radians()/ 2.0f );
	tux_position += circle_center;
	tux_position.x -= tux.get_width()/2;
	tux_position.y -= tux.get_height()/2;

	// Give tux circle blue outer outline, because it looks nice
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Make see through border
	canvas.set_blend_state(blend_state_off);
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle-2, clan::Colorf(0.0f, 0.0f, 0.0f, 0.0f));
	canvas.reset_blend_state();

	// Give tux circle blue outline, to mask the alpha channel
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+2, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Draw tux
	tux.draw(canvas, tux_position.x, tux_position.y);

	// Draw text
	font_large.draw_text(canvas, 10-2, 50-2, "ClanLib Layered Window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_large.draw_text(canvas, 10, 50, "ClanLib Layered Window", clan::Colorf::green);
	font_small.draw_text(canvas, 60-2, 80-2, "Click mouse on the penguin to exit", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 60, 80, "Click mouse on the penguin to exit", clan::Colorf::green);
	font_small.draw_text(canvas, 110-2, 110-2, "Drag rock to move window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 110, 110, "Drag rock to move window", clan::Colorf::green);

	window.flip(1);

	return !quit;
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}
Example #6
0
	bool update()
	{
		if (window.get_keyboard().get_keycode(keycode_escape))
			quit = true;

		canvas.clear(Colorf(0.5f,0.5f,0.5f));

		small_font.draw_text(canvas, 10, 40, "Image From Texture (10,60)");
		image_texture.draw(canvas, 10, 60);

		small_font.draw_text(canvas, 150, 40, "Image From Load (150,60)");
		image_loaded.draw(canvas, 150, 60);

		small_font.draw_text(canvas, 300, 40, "Image From Resources (300,60)");
		image_resources.draw(canvas, 300, 60);

		small_font.draw_text(canvas, 450, 40, "Image Copied (450,60)");
		image_copy.draw(canvas, 450, 60);

		small_font.draw_text(canvas, 10, 190, "Image - Top Right (10,200)");
		image_top_right.draw(canvas, 10, 200);

		small_font.draw_text(canvas, 150, 190, "Image - Top Right (150,200)");
		image_texture.draw(canvas, Rect(32, 0, Size(32, 32)), Rect(150, 200, Size(32, 32)));

		small_font.draw_text(canvas, 300, 190, "Image - Bottom Right (300,200)");
		image_bottom_right.draw(canvas, 300, 200);

		small_font.draw_text(canvas, 450, 190, "Image - Bottom Right (450,200)");
		image_texture.draw(canvas, Rect(32, 32, Size(32, 32)), Rect(450, 200, Size(32, 32)));

		small_font.draw_text(canvas, 10, 290, "700 Images (10,300)");
		for(int i=0;i<700;i++)
			image_texture.draw(canvas, 10, 300);

		small_font.draw_text(canvas, 150, 290, "br image (150,400) Size(128,256)");
		image_bottom_right.draw(canvas, Rect(150, 300, Size(128, 256)));

		small_font.draw_text(canvas, 300, 290, "Image - black");
		image_black.draw(canvas, 300, 300);

		small_font.draw_text(canvas, 300, 490, "Image - Scale (1.5, 2.5)");
		image_texture.set_scale(1.5f, 2.5f);
		image_texture.draw(canvas, 300, 500);
		image_texture.set_scale(1.0f, 1.0f);

		small_font.draw_text(canvas, 450, 460, "Image - Alignment (4 images with 8 pixel offset)");
		small_font.draw_text(canvas, 450, 475, "(top left, top right, bottom left, bottom right)");
		small_font.draw_text(canvas, 450, 490, "(Circle denotes the draw origin)");
		const int offset = 96;

		image_texture.set_alignment(origin_top_left, 8, 8);
		image_texture.draw(canvas, 450+offset, 500+offset);
		image_texture.set_alignment(origin_top_right, -8, 8);
		image_texture.draw(canvas, 450+offset, 500+offset);

		image_texture.set_alignment(origin_bottom_left, 8, -8);
		image_texture.draw(canvas, 450+offset, 500+offset);
		image_texture.set_alignment(origin_bottom_right, -8, -8);
		image_texture.draw(canvas, 450+offset, 500+offset);

		canvas.fill_circle(450+offset, 500+offset, 4, Colorf(1.0f, 1.0f, 1.0f, 0.9f));

		small_font.draw_text(canvas, 700, 460, "Image - Center Alignment (4 images with 8 pixel offset)");
		small_font.draw_text(canvas, 700, 475, "(top center, right center, bottom center, left center)");
		small_font.draw_text(canvas, 700, 490, "(Circle denotes the draw origin)");
				
		image_texture.set_alignment(origin_top_center, 0, 8);
		image_texture.draw(canvas, 700+offset, 500+offset);
		image_texture.set_alignment(origin_bottom_center, 0, -8);
		image_texture.draw(canvas, 700+offset, 500+offset);

		image_texture.set_alignment(origin_center_left, 8, 0);
		image_texture.draw(canvas, 700+offset, 500+offset);
		image_texture.set_alignment(origin_center_right, -8, 0);
		image_texture.draw(canvas, 700+offset, 500+offset);

		canvas.fill_circle(700+offset, 500+offset, 4, Colorf(1.0f, 1.0f, 1.0f, 0.9f));

		small_font.draw_text(canvas, 700, 160, "Image - Center Align (4 images with 64 pixel offset)");
		small_font.draw_text(canvas, 700, 175, "Also Includes a centered image (Without offset)");
		small_font.draw_text(canvas, 700, 190, "(Circle denotes the draw origin)");

		const int center_image_offset = 64;

		image_texture.set_alignment(origin_center, 0, 0);
		image_texture.draw(canvas, 700+offset, 200+offset);

		image_texture.set_alignment(origin_center, 0, center_image_offset);
		image_texture.draw(canvas, 700+offset, 200+offset);
		image_texture.set_alignment(origin_center, 0, -center_image_offset);
		image_texture.draw(canvas, 700+offset, 200+offset);

		image_texture.set_alignment(origin_center, center_image_offset, 0);
		image_texture.draw(canvas, 700+offset, 200+offset);
		image_texture.set_alignment(origin_center, -center_image_offset, 0);
		image_texture.draw(canvas, 700+offset, 200+offset);

		canvas.fill_circle(700+offset, 200+offset, 4, Colorf(1.0f, 1.0f, 1.0f, 0.9f));

		// Restore alignment
		image_texture.set_alignment(origin_top_left, 0, 0);

		dump_fps();

		window.flip(1);

		return !quit;
	}