void DemoCMotion::on_key_up(const clan::InputEvent& key, clan::Canvas canvas) { if( key.id == clan::keycode_escape ) quit = true; else if( key.id == clan::keycode_z) { current_style = (current_style+1)%2; set_style(canvas); } else if( key.id == clan::keycode_x) { random_ini_rotation = !random_ini_rotation; if( random_ini_rotation ) effect->set_rotation_distortion(L_DEGREE_TO_RADIAN(200)); else effect->set_rotation_distortion(0); } else if( key.id == clan::keycode_f1) show_menu = !show_menu; else if( key.id == clan::keycode_space) clan::System::sleep(rand()%200+50); }
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(); }
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; }