public SinusoidalMovement(IMoving baseMovement, AxesDirections axis) { this.baseMovement = baseMovement; switch (axis) { case AxesDirections.north: this.axis = Vector3.right; break; case AxesDirections.south: this.axis = Vector3.left; break; case AxesDirections.east: this.axis = Vector3.up; break; case AxesDirections.west: this.axis = Vector3.down; break; } }
private Vector3 border_from_screen_center(AxesDirections border_direction) { switch (border_direction) { case AxesDirections.north: return(new Vector3(0, border_distance_from_center, 0)); case AxesDirections.east: return(new Vector3(border_distance_from_center, 0, 0)); case AxesDirections.south: return(new Vector3(0, -border_distance_from_center, 0)); case AxesDirections.west: return(new Vector3(-border_distance_from_center, 0, 0)); default: return(new Vector3(0, 0, 0)); // Unmanaged case: make it fail (TODO) } }
private const float half_border_distance_from_center = border_distance_from_center; // TODO: replace by something deduced from actual data, not a guess private Vector3 random_position(AxesDirections wall) { var wall_position = border_from_screen_center(wall); var random_side_step = Random.Range(-half_border_distance_from_center, half_border_distance_from_center); switch (wall) { case AxesDirections.north: return(wall_position + new Vector3(random_side_step, 0, 0)); case AxesDirections.east: return(wall_position + new Vector3(0, random_side_step, 0)); case AxesDirections.south: return(wall_position + new Vector3(random_side_step, 0, 0)); case AxesDirections.west: return(wall_position + new Vector3(0, random_side_step, 0)); default: return(new Vector3(0, 0, 0)); // Unmanaged case: make it fail (TODO) } }
private static float angle(AxesDirections direction) { switch (direction) { case AxesDirections.north: return(0.0f); case AxesDirections.east: return(GUNS_DEGREES_PER_DIRECTION); case AxesDirections.south: return(GUNS_DEGREES_PER_DIRECTION * 2); case AxesDirections.west: return(GUNS_DEGREES_PER_DIRECTION * 3); default: Assert.IsTrue(false); return(0.0f); } }
private Shield get_shield(AxesDirections direction) { return(shields[(int)direction]); }
// Note that these are functions because the gun on each direction will change while playing. private Gun get_gun(AxesDirections direction) { return(guns[(int)direction]); }
private void rotate_guns(GunsRotation rotation_from_commands) { // We want rotations to always happen in lock-steps of axis, // that is, rotation can only change/start when guns are aligned with the axis. // If the player maintain a rotation direction, we should seemlessly continue // rotating until they don't, then we stop rotation once reaching an axis orientation. if (current_guns_rotation == GunsRotation.none) // If we are already in locked position, take any command, otherwise ignore commands until next lock position. { current_guns_rotation = rotation_from_commands; if (rotation_from_commands != GunsRotation.none) { start_rotation_sound(); } } float rotation_factor = gun_rotation_factor(current_guns_rotation); float next_orientation = (current_guns_angle + rotation_speed * Time.deltaTime * rotation_factor); while (next_orientation > MAX_GUNS_ORIENTATION_DEGREES) { next_orientation -= MAX_GUNS_ORIENTATION_DEGREES; } while (next_orientation < 0) { next_orientation += MAX_GUNS_ORIENTATION_DEGREES; } var new_rotation_direction = direction(next_orientation); var new_target_axis = next_axis(next_orientation, current_guns_rotation); var current_target_axis = next_axis(current_guns_angle, current_guns_rotation); if (new_target_axis != current_target_axis) { // We are passing over/through a lock position. // We either stop here or change direction following commands. // It all depends on what is the command from input. var previous_gun_rotation = current_guns_rotation; current_guns_rotation = rotation_from_commands; if (current_guns_rotation == GunsRotation.none || current_guns_rotation != previous_gun_rotation) // TODO: check if the second test isn't enough for both cases { // We need to stop: lock the position to align with axis. next_orientation = angle(current_target_axis); stop_rotation_sound(); play_rotation_stop_sound(); } } // Handle gun firing rotation: the firing direction gives the closest gun to that direction to fire. if (new_rotation_direction != current_guns_directions) { // We will change of gun direction. rotate_guns_directions((int)rotation_factor); current_guns_directions = new_rotation_direction; } // Apply guns rotation. current_guns_angle = next_orientation; transform.rotation = Quaternion.Euler(0.0f, 0.0f, -current_guns_angle); // Because of Z being oriented this way in Unity, we need negative values to rotate clockwise. }
private void activate_shield(AxesDirections direction) { get_shield(direction).activate(); overload_system.add_load(); }
private void fire_gun(AxesDirections direction) { get_gun(direction).fire(); overload_system.add_load(); }