private bool delete_signal; // if true - delete immediately /// <summary> /// initiates all basic particle features, additional functions will be created to allow “turning on” /// parameters such as color change or scale change because each one needs additional parameters and will clutter the basic constructor /// </summary> /// <param name="ptype">particle shape type</param> /// <param name="ttype">trajectory type - movement</param> /// <param name="origin">particle position for rendering and calculations</param> /// <param name="life">particle duration before deletion</param> /// <param name="max_distance">maximum travel distance before deldetion</param> /// <param name="ang_momentum">rotational speed</param> /// <param name="starting_speed">starting movement speed</param> /// <param name="acceleration">particle acceleration value in pixels per second squared</param> /// <param name="direction_angle">direction of movement</param> public Particle(particle_type ptype, trajectory_type ttype, Vector2 origin, int life, int max_distance, float ang_momentum, float starting_speed, float acceleration, float direction_angle) { particle_origin = origin; bounds = Rectangle.Empty; //calculate this like x,y, width,height particle_life = life; this.max_distance = max_distance; particle_creation_time = Engine.get_current_game_millisecond(); last_update_time = particle_creation_time; particle_angular_momentum = ang_momentum; particle_angle = 0f; this._particle_type = ptype; this.trajectory = ttype; this.acceleration = acceleration; // acceleration value in px/s^2 this.starting_speed = starting_speed; // initial speed of the particle in px/s has to be float but is truncated to int when object is rendered this.speed = starting_speed; this.direction_angle = direction_angle; current_scale = 1.0f; scale_minmax = Vector2.One; // scale limits for interpolation scale_fluc_period = 0; // scale fluctuation period in ms scale_interpolation_flag = false; // dynamic scale? transparency = 1.0f; transparency_minmax = Vector2.One; // min-max transparency transparency_fluc_period = 0; // scale fluctuation period in ms transparency_interpolation_flag = false; // change transparency for this particle? light_source_particle = false; // has a light sphere base_color_light_sphere = Color.White; secondary_color_light_sphere = Color.White; // what color does particle light sphere interpolate to? light_sphere_color_fluc_period = 0; // color fluctuation period in ms light_color_interpolation_flag = false; // dynamic light color? enables gradient of 2 colors light_sphere_size_minmax = new Int2(0, 0); // light radius in px min and max light_sphere_size_interpolation_flag = false; light_sphere_size_fluc_period = 0; // scale fluctuation period in ms tint_flag = false; // tinted or use original graphics current_color = Color.White; base_tint = Color.White; // base tint: in case our particle needs tint effect or if it's white and this is color source. secondary_tint = null; // a second tint color to which the base color can interpolate tint_interpolation_flag = false; color_fluc_period = 0; delete_signal = false; }
/// <summary> /// Emitter generator - send emitter for an enabled object to handle /// </summary> /// <param name="host">an object that is hosting the emitter</param> /// <param name="pos">emitter position in pixels</param> /// <param name="ptype">particle type being generated</param> /// <param name="random">are particles randomized?</param> /// <param name="emitter_life_duration">how long should this emitter exist</param> /// <param name="rate">number of ms between bursts</param> /// <param name="auto">is generation automatic?</param> /// <param name="ttype">particle trajectory type</param> /// <param name="particle_lifetime">how long should the particles exist - in ms?</param> /// <param name="number_of_particles_in_burst">number of particles generated at the same time</param> /// <param name="random_color">are colors randomized?</param> /// <param name="interpolate_color_flag">are colors interpolated?</param> /// <param name="area_radius">area of generation</param> public void create_emitter( IParticleCreating host, // emitter will be created inside this object Vector2[] pos, // create in these positions (allows creation of multiple emitters in one function call) particle_type ptype, // defines what shape the particle takes as well as multiple internal properties bool random, // int emitter_life_duration, // when is this emitter scheduled for deletion int rate, // number of milliseconds between particle bursts bool auto, // requires no manual input to create particles trajectory_type ttype, // trajectory type - defines particle movement after creation int particle_lifetime, // particle lifetime int number_of_particles_in_burst, // number of particles created in the same cycle bool random_color, // randomizes particle tint bool interpolate_color_flag, // change from current color to black int area_radius // all particles in one burst will be created in this radius (use 1 for point creation) ) { for (int i = 0; i < pos.Length; i++) { Emitter temp = new Emitter(pos[i], ptype, random, emitter_life_duration, particle_lifetime, rate, auto, ttype, number_of_particles_in_burst, random_color, interpolate_color_flag, area_radius); // call Emitter constructor using parameters supplied by Engine host.Add(temp); // function required by the interface } }
/// <summary> /// Emitter constructor /// </summary> /// <param name="pos">cell position vector</param> /// <param name="ptype">particle type</param> /// <param name="random">randomzied particles</param> /// <param name="emitter_life_duration">emitter life</param> /// <param name="particle_lifetime">particle lifetime</param> /// <param name="rate">number of milliseconds until next burst</param> /// <param name="auto">automatic generation - no signal needed</param> /// <param name="ttype">particle trajectory type</param> /// <param name="number_of_particles_in_burst">number of particles generated in one burst</param> /// <param name="random_color">randomized color</param> /// <param name="interpolate_color">change from one color to another over time</param> /// <param name="area_radius">emitter burst area</param> public Emitter(Vector2 pos, particle_type ptype, bool random, int emitter_life_duration, int particle_lifetime, int rate, bool auto, trajectory_type ttype, int number_of_particles_in_burst, bool random_color, bool interpolate_color, int area_radius) { position = pos; this._particle_type = ptype; random_type = random; emitter_duration = emitter_life_duration; last_burst = 0; this.rate = rate; automatic_generation = auto; this.trajectory = ttype; this.number_of_particles_in_burst = number_of_particles_in_burst; random_color_flag = random_color; // assigns a random color instead of a built in color value emitter_radius = area_radius; creation_time = Engine.get_current_game_millisecond(); // get ms value from Engine and assign as a beginning point particles_created = new List <Particle>(); acceleration = 0; scale = 1f; rotation_amount = 0f; particle_base_color = Color.White; particle_secondary_color = null; emit = false; this.particle_lifetime = particle_lifetime; interpolate_color_flag = interpolate_color; }
/// <summary> /// change the trajectory type of gengerated particles /// </summary> /// <param name="t_type">trajectory type</param> public void change_trajectory_type(trajectory_type t_type) { trajectory = t_type; }