private void prioritizeSpriteInteraction(IClientSprite sprite1, IClientSprite sprite2, out IClientSprite primary_sprite, out IClientSprite secondary_sprite) { // @@@ Temp prioritizeSpriteInteraction - do logic here yet. primary_sprite = sprite1; secondary_sprite = sprite2; }
/// <summary> /// Constructor /// </summary> /// <param name="position"></param> /// <param name="heading"></param> /// <param name="speed"></param> /// <param name="acceleration"></param> public BasicBogeySprite(KeeperTime ktime, IPilotControllerRequest controller_request, Vector position, double heading, double speed, double acceleration = 0.0, IClientSprite tracked_target = null) : base(ktime, controller_request, position, heading, speed, acceleration) { fuel = _BASIC_BOGEY_STARTING_FUEL; fuel_burn_rate = _BASIC_BOGEY_BURN_RATE_PER_SEC; }
/// <summary> /// Handler when actor is moved due to game logic. /// </summary> /// <param name="sender"></param> protected void Actor_MovedHandler(object sender) { if (sender is BasicBogeyActor) { ClientActor actor = sender as ClientActor; // If this actor is the bogey we are tracking ... if (actor == TrackingBogey) { // If it off the radar scope stop tracking it. if (!actor.IsRadarScopeVisible) { actor.RadarTrackingMarkVisibility = Visibility.Hidden; TrackingBogey = null; BogeyHeading = Double.NaN; BogeyRange = Double.NaN; BogeyInterceptHeading = Double.NaN; } else { // Update the bogey tracking display IClientSprite sprite = actor.Sprite as IClientSprite; BogeyHeading = sprite.Heading; // Calculate intercept heading from pilot to bogey (by first calculating the delta distance). Vector intercept_delta = Vector.Subtract(sprite.Position, _view_translator.RadarWorldPosition); BogeyRange = intercept_delta.Length; BogeyInterceptHeading = MathHelper.headingFromVector(intercept_delta); } } } }
/// <summary> /// Method to support AddedSprite events. /// </summary> protected void onAddedSprite(IClientSprite sprite) { // Callback to clients that registered event handlers if (this.AddedSprite != null) { this.AddedSprite(this, new AddSpriteArgs(sprite)); } }
/// <summary> /// Constructor /// </summary> /// <param name="position"></param> /// <param name="heading"></param> /// <param name="speed"></param> /// <param name="acceleration"></param> public AresMissileSprite(KeeperTime ktime, IPilotControllerRequest controller_request, Vector position, double heading, double speed, double acceleration, IClientSprite tracked_target) : base(ktime, controller_request, position, heading, speed, acceleration) { startTrackingTarget(tracked_target); fuel = _ARES_MISSILE_STARTING_FUEL; fuel_burn_rate = _ARES_MISSILE_BURN_RATE_PER_SEC; }
/// <summary> /// End the tracking of the current target. /// </summary> protected void endTrackingTarget() { if (_tracked_target != null) { // Remove our handlers from the sprite we were tarcking. _tracked_target.Removed -= _tracked_target_on_removed_handler_ref; _tracked_target_on_removed_handler_ref = null; _tracked_target = null; } }
/// <summary> /// Return a reference to a sprite given the controller id. /// </summary> /// <param name="controller_id"></param> /// <returns></returns> public IClientSprite getSprite(long controller_id) { IClientSprite result = null; if (!_active_sprites.TryGetValue(controller_id, out result)) { result = null; } return(result); }
protected IClientSprite _tracked_target = null; // Target the missile is tracking. /// <summary> /// Start tracking the given target. /// </summary> /// <param name="tracked_target"></param> protected void startTrackingTarget(IClientSprite tracked_target) { // Check if we are already tracking a target. if (_tracked_target != null) { throw new InvalidOperationException("startTrackingTarget: need to end tracking before tracking a new target."); } if (tracked_target != null) { _tracked_target = tracked_target; _tracked_target_on_removed_handler_ref = new RemoveHandler(tracked_targeted_SpriteRemoveHandler); _tracked_target.Removed += _tracked_target_on_removed_handler_ref; } }
/// <summary> /// Add a sprite to the controller. /// </summary> /// <param name="ktime"></param> /// <param name="sprite"></param> /// <returns>controler id for the sprite</returns> public long AddSprite(KeeperTime ktime, IClientSprite sprite) { long controller_id = createControllerId(); // Assign the sprite a controller id. sprite.ControllerId = controller_id; // Assign the sprite a controller id. _active_sprites.Add(controller_id, sprite); // Add the sprite to the list of moving sprites. sprite.Removed += new RemoveHandler(SpriteRemoveHandler); sprite.Move(ktime); // Inform observers a new sprite was made (so they can create elements that display the sprite.) onAddedSprite(sprite); // Support the AddedSprite event. return(controller_id); }
/// <summary> /// Have all standard sprites interact. /// </summary> private void InteractSprites(KeeperTime ktime, List <IClientSprite> sprites) { for (var sprite_index = 0; sprite_index < sprites.Count - 1; ++sprite_index) { for (var other_index = sprite_index + 1; other_index < sprites.Count; ++other_index) { IClientSprite sprite1 = sprites[sprite_index]; IClientSprite sprite2 = sprites[other_index]; bool interact = interactCheck(ktime, sprite1, sprite2); if (interact == true) { IClientSprite primary_sprite = null; IClientSprite secondary_sprite = null; prioritizeSpriteInteraction(sprite1, sprite2, out primary_sprite, out secondary_sprite); primary_sprite.Interact(ktime, secondary_sprite, true /* is_primary_interation */); secondary_sprite.Interact(ktime, primary_sprite, false /* is_primary_interation */); } } } }
/// <summary> /// Interact with another sprite. /// </summary> /// <param name="other_sprite"></param> /// <param name="is_primary_interation"> True if this is the primary/first interaction betweeen the two for this pass /// through the update loop. </param> public virtual void Interact(KeeperTime ktime, IClientSprite other_sprite, bool is_primary_interation) { }
private long _controller_id_count = 0; // For creating controller ids. /// <summary> /// Callback handler when a sprite says its being removed from the game. /// </summary> /// <param name="sender"></param> void SpriteRemoveHandler(object sender) { IClientSprite sprite = sender as IClientSprite; _active_sprites.Remove(sprite.ControllerId); // Remove the sprite from the list of moving sprites. }
private bool interactCheck(KeeperTime ktime, IClientSprite sprite, IClientSprite other_sprite) { // @@@ Temp interactCheck - do logic here yet. return(true); }
public AddSpriteArgs(IClientSprite _sprite) { sprite = _sprite; }
/// <summary> /// Callback handler when a targeted sprite says its being removed from the game. /// </summary> /// <param name="sender"></param> void tracked_targeted_SpriteRemoveHandler(object sender) { IClientSprite sprite = sender as IClientSprite; endTrackingTarget(); }