/// <summary> /// Construct a GameEvent that will be fired after timeToSend has elapsed /// </summary> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="args"></param> /// <param name="timeToSend"></param> public GameEvent(GameObject src, GameObject dst, GameEventArgs args, float timeToSend) { this.src = src; this.dst = dst; this.args = args; this.timeToSend = timeToSend; HasFired = timeToSend < 0 ? true : false; }
/// <summary> /// Copy another Gameobject. Optionally fire a GameObjectCreatedEvent /// </summary> /// <param name="other"></param> /// <param name="fireOnCreateEvent"></param> public GameObject(GameObject other, bool fireOnCreateEvent=true) { ColorScheme = new ColorScheme<Hostility>(other.ColorScheme); GameEventManager = other.GameEventManager; PhysicsComponent = new PhysicsComponent(other.PhysicsComponent); Behaviors = new List<IBehavior>(other.Behaviors); Active = other.Active; Timescale = other.Timescale; Health = other.Health; if (fireOnCreateEvent && GameEventManager != null) GameEventManager.AddEvent(new GameObjectCreatedEvent(this)); }
/// <summary> /// Construct an event when a GameObject is created. /// It is not required that object creation fire an event /// </summary> /// <param name="src"></param> public GameObjectCreatedEvent(GameObject src) : base(src, null, null, 0) { GameObject = src; }
/// <summary> /// Touch the GameObject with another /// </summary> /// <param name="other"></param> /// <returns>True if the objects interact</returns> public virtual bool Touch(GameObject other) { return false; }
/// <summary> /// Handle a GameEvent from a GameObject (can be self) /// </summary> /// <param name="src"></param> /// <param name="args"></param> public virtual void OnGameEvent(GameObject src, GameEventArgs args) { }
/// <summary> /// Immediately finish any transition, and copy current target information /// to its equivalent 'old' field /// </summary> private void FinishTransition() { oldTarget = target; oldTargetPos = targetPos; transitionPos = Vector2.Zero; transitionRemaining = 0; }
/// <summary> /// Very much like LockTarget(target, immediate) except it allows a specification of duration. /// </summary> /// <param name="target">The GameplayObject to follow or "lock on" to</param> /// <param name="duration">Amount of time for the transition from last target or pos, or transition position (depending on last mode)</param> /// <param name="immediate">If the lock is not immediate, the last transition position is saved and the transition finishes from transition position to the new target</param> public void TransitionTo(GameObject target, float duration, bool immediate) { LockTarget(target, immediate); if (!immediate) transitionRemaining = transitionTime = duration; }
/// <summary> /// Lock the camera onto the specified target. /// </summary> /// <param name="target">The GameplayObject to follow or "lock on" to</param> /// <param name="immediate">If the lock is not immediate, the last transition position is saved and the transition finishes from transition position to the new target</param> public void LockTarget(GameObject target, bool immediate) { if (immediate) { // End the transition, set the pos as the current vector lock FinishTransition(); mode = CameraMode.LockedTarget; this.target = target; } else { switch (mode) { case CameraMode.LockedPos: oldTargetPos = targetPos; break; case CameraMode.LockedTarget: oldTargetPos = target.PhysicsComponent.Position; break; case CameraMode.TtTTransition: case CameraMode.TtVTransition: case CameraMode.VtTTransition: case CameraMode.VtVTransition: oldTargetPos = transitionPos; break; } //Complete the transition from its current position this.target = target; mode = CameraMode.VtTTransition; } isTransformDirty = true; }
/// <summary> /// Copy Constructor /// </summary> /// <param name="camera">The camera to copy</param> public Camera(Camera camera) { dt = camera.dt; mode = camera.mode; oldTarget = camera.oldTarget; target = camera.target; oldTargetPos = camera.oldTargetPos; targetPos = camera.targetPos; transitionPos = camera.transitionPos; transitionRemaining = camera.transitionRemaining; transitionTime = camera.transitionTime; lastFramePos = camera.lastFramePos; effects = new List<CameraEffect>(camera.effects); isTransformDirty = camera.isTransformDirty; transformMatrix = camera.transformMatrix; }