Changes to the constructor function

There are two changes to be made to the constructor function. First, we'll add some initialization at the top that initializes all of the new pointers to NULL. We do not need these pointers in every emitter, so we can check against NULL to see when they are or are not used. Further down, we will modify the values that are passed into the constructors from degrees to radians. Here is what the function looks like:

Emitter::Emitter(char* sprite_file, int max_particles, float min_angle, 
float max_angle,
Uint32 particle_lifetime, float acceleration, bool
alpha_fade,
float min_starting_velocity, float max_starting_velocity,
Uint32 emission_rate, int x_pos, int y_pos, float radius,
float min_start_scale, float max_start_scale,
float min_end_scale, float max_end_scale,
Uint32 start_color, Uint32 end_color,
float burst_time_pct, Uint32 burst_particles,
bool loop, bool align_rotation, Uint32 emit_time_ms, Uint32
animation_frames ) {
// added -----------------------------
m_parent_rotation_ptr = NULL;
m_parent_x_ptr = NULL;
m_parent_y_ptr = NULL;
// -----------------------------------
m_start_color = start_color;
m_end_color = end_color;
m_active = true;

if( min_starting_velocity > max_starting_velocity ) {
m_min_starting_velocity = max_starting_velocity;
m_max_starting_velocity = min_starting_velocity;
}
else {
m_min_starting_velocity = min_starting_velocity;
m_max_starting_velocity = max_starting_velocity;
}
SDL_Surface *temp_surface = IMG_Load( sprite_file );

if( !temp_surface ) {
printf("failed to load image: %s\n", IMG_GetError() );
printf("failed sprite file: %s\n", sprite_file );
return;
}
m_sprite_texture = SDL_CreateTextureFromSurface( renderer, temp_surface
);
SDL_FreeSurface( temp_surface );
SDL_QueryTexture( m_sprite_texture,
NULL, NULL,
&m_sprite_width, &m_sprite_height );
m_max_particles = max_particles;

for( int i = 0; i < m_max_particles; i++ ) {
m_particle_pool.push_back(
new Particle( m_sprite_texture, particle_lifetime,
acceleration,
alpha_fade, m_sprite_width, m_sprite_height,
align_rotation,
m_start_color, m_end_color, animation_frames )
);
}

// modified -----------------------------
m_min_angle = (min_angle+90) / 180 * 3.14159;
m_max_angle = (max_angle+90) / 180 * 3.14159;
// --------------------------------------

m_radius = radius;
m_position.x = (float)x_pos;
m_position.y = (float)y_pos;
m_emission_rate = emission_rate;
m_emission_time_ms = 1000 / m_emission_rate;
m_next_emission = 0;
m_min_start_scale = min_start_scale;
m_max_start_scale = max_start_scale;
m_min_end_scale = min_end_scale;
m_max_end_scale = max_end_scale;

m_loop = loop;
m_align_rotation = align_rotation;
m_emit_loop_ms = emit_time_ms;
m_ttl = m_emit_loop_ms;

m_animation_frames = animation_frames;
m_burst_time_pct = burst_time_pct;
m_burst_particles = burst_particles;
m_has_burst = false;
}

The first changes are at the very top of this function, and set our new pointer attributes to NULL:

m_parent_rotation_ptr = NULL;
m_parent_x_ptr = NULL;
m_parent_y_ptr = NULL;

Later, we will check to see if these pointers are NULL, and if not, we will use m_parent_rotation_ptr to adjust the rotation angle of this emitter. We will use m_parent_x_ptr to change the x coordinate of the emitter, and we will use m_parent_y_ptr to adjust the y coordinate of this emitter. After that, we have the code that modifies the passed in minimum and maximum angles from degrees to radians:

m_min_angle = (min_angle+90) / 180 * 3.14159;
m_max_angle = (max_angle+90) / 180 * 3.14159;

The real reason we need to do this is that we are hardcoding the values we pass into the emitter. If we created a data loader, we could have done this conversion when the data loaded up. But, because we are taking these values straight out of our particle emitter configuration tool and hardcoding the values right into the call to the new emitter, we will either have to remember to do the conversion ourselves every time we change these values, or we will have to do it from within the constructor and the Update function.