void ISpaceObject.OnAdditionToSpace(Space newSpace) { }
void ISpaceObject.OnRemovalFromSpace(Space oldSpace) { }
/// <summary> /// Called before an object is removed from its space. /// </summary> /// <param name="oldSpace">Space from which the object was removed.</param> public virtual void OnRemovalFromSpace(Space oldSpace) { }
/// <summary> /// Called after the object is added to a space. /// </summary> /// <param name="newSpace">Space to which the object was added.</param> public virtual void OnAdditionToSpace(Space newSpace) { }
public override void Update(float dt) { #region Kapow-Shooter Input //Update kapow-shooter if (!vehicle.IsActive) #if !WINDOWS { if (Game.GamePadInput.IsButtonDown(Buttons.RightTrigger)) #else { if (Game.MouseInput.LeftButton == ButtonState.Pressed) #endif { if (character.IsActive) //Keep the ball out of the character's body if its being used. { kapow.Position = Game.Camera.Position + Game.Camera.WorldMatrix.Forward * 3; } else { kapow.Position = Game.Camera.Position + Game.Camera.WorldMatrix.Forward; } kapow.AngularVelocity = Vector3.Zero; kapow.LinearVelocity = Game.Camera.WorldMatrix.Forward * 30; } } #endregion #region Grabber Input //Update grabber #if !WINDOWS if (Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && !grabber.IsUpdating) #else if (Game.MouseInput.RightButton == ButtonState.Pressed && !grabber.IsGrabbing) #endif { //Find the earliest ray hit RayCastResult raycastResult; if (Space.RayCast(new Ray(Game.Camera.Position, Game.Camera.WorldMatrix.Forward), 1000, rayCastFilter, out raycastResult)) { var entityCollision = raycastResult.HitObject as EntityCollidable; //If there's a valid ray hit, then grab the connected object! if (entityCollision != null && entityCollision.Entity.IsDynamic) { grabber.Setup(entityCollision.Entity, raycastResult.HitData.Location); grabberGraphic.IsDrawing = true; grabDistance = raycastResult.HitData.T; } } } #if !WINDOWS if (Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && grabber.IsUpdating) #else else if (Game.MouseInput.RightButton == ButtonState.Pressed && grabber.IsUpdating) #endif { grabber.GoalPosition = Game.Camera.Position + Game.Camera.WorldMatrix.Forward * grabDistance; } #if !WINDOWS if (!Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && grabber.IsUpdating) #else else if (Game.MouseInput.RightButton == ButtonState.Released && grabber.IsUpdating) #endif { grabber.Release(); grabberGraphic.IsDrawing = false; } #endregion #region Control State Input #if !WINDOWS if (!vehicle.IsActive && Game.WasButtonPressed(Buttons.LeftTrigger)) { kapowMaker.Position = kapow.Position; kapowMaker.Explode(); } if (Game.WasButtonPressed(Buttons.A)) {//Toggle character perspective. if (!character.IsActive) { vehicle.Deactivate(); character.Activate(); } else { character.Deactivate(); } } if (Game.WasButtonPressed(Buttons.B)) {//Toggle vehicle perspective. if (!vehicle.IsActive) { character.Deactivate(); vehicle.Activate(); } else { vehicle.Deactivate(); } } #else if (!vehicle.IsActive && Game.WasKeyPressed(Keys.Space)) { //Detonate the bomb kapowMaker.Position = kapow.Position; kapowMaker.Explode(); } if (Game.WasKeyPressed(Keys.C)) { //Toggle character perspective. if (!character.IsActive) { vehicle.Deactivate(); character.Activate(); } else { character.Deactivate(); } } if (Game.WasKeyPressed(Keys.V)) { //Toggle vehicle perspective. if (!vehicle.IsActive) { character.Deactivate(); vehicle.Activate(Game.Camera.Position); } else { vehicle.Deactivate(); } } #endif #endregion base.Update(dt); //Base.update updates the space, which needs to be done before the camera is updated. character.Update(dt, Game.PreviousKeyboardInput, Game.KeyboardInput, Game.PreviousGamePadInput, Game.GamePadInput); vehicle.Update(dt, Game.KeyboardInput, Game.GamePadInput); //If neither are active, just use the default camera movement style. if (!character.IsActive && !vehicle.IsActive) { freeCameraControlScheme.Update(dt); } }
/// <summary> /// Removes the motors from the space. Called automatically. /// </summary> public override void OnRemovalFromSpace(Space oldSpace) { oldSpace.Remove(LinearMotor); }
/// <summary> /// Adds the motors to the space. Called automatically. /// </summary> public override void OnAdditionToSpace(Space newSpace) { newSpace.Add(LinearMotor); }