Example #1
0
 public RailController(string id,
                       ControllerType controllerType,
                       Actor3D target, RailParameters railParameters) : base(id, controllerType)
 {
     this.target         = target;
     this.railParameters = railParameters;
 }
Example #2
0
        private void LaunchProjectiles(Actor3D actor)
        {
            //Only shoot if the player is within activation range
            if (playerTransform == null || Vector3.Distance(parentTransform.Translation, playerTransform.Translation) >
                GameConstants.Projectile_ActivationDistance)
            {
                return;
            }

            //Launch a projectile in each direction
            for (int i = 0; i < launchDirections.Count; i++)
            {
                CollidableProjectile projectile = projectileArchetype.Clone() as CollidableProjectile;
                projectile.Transform3D.Translation       = parentTransform.Translation;
                projectile.EffectParameters.DiffuseColor = Color.Red;

                //Rotate the direction
                launchDirections[i] = Vector3.Transform(launchDirections[i], Quaternion.CreateFromAxisAngle(Vector3.Up, 45));

                //Add the projectile to the ObjectManager and start its movement animation
                EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnAddActor, new[] { projectile }));
                EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new[]
                {
                    new TranslationTween(projectile, (int)MathF.Round(maxDistance * unitSpeedInMs),
                                         launchDirections[i] * maxDistance, true, actor3D =>
                    {
                        EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnRemoveActor, new[] { actor3D }));
                    }, LoopType.PlayOnce, EasingType.easeIn)
                }));
            }

            //Play a shooting sound
            EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay3D, new object[] { "shoot", parentTransform }));
        }
        private void HandleKeyboardInput(GameTime gameTime, Actor3D parent)
        {
            Vector3 moveVector = Vector3.Zero;

            if (keyboardManager.IsKeyDown(Keys.U))
            {
                moveVector = parent.Transform3D.Look * moveSpeed;
            }
            else if (keyboardManager.IsKeyDown(Keys.J))
            {
                moveVector = -1 * parent.Transform3D.Look * moveSpeed;
            }

            if (keyboardManager.IsKeyDown(Keys.H))
            {
                parent.Transform3D.RotateAroundUpBy(this.rotationSpeed * gameTime.ElapsedGameTime.Milliseconds);
                //parent.Transform3D.RotateBy(new Vector3(0, 45, 0));
            }
            else if (keyboardManager.IsKeyDown(Keys.K))
            {
                parent.Transform3D.RotateAroundUpBy(-1 * this.rotationSpeed * gameTime.ElapsedGameTime.Milliseconds);
                //parent.Transform3D.RotateBy(new Vector3(0, -45, 0));
            }

            //constrain movement in Y-axis to stop object moving up/down in space
            moveVector.Y = 0;

            //apply the forward/backward movement
            parent.Transform3D.TranslateBy(moveVector * gameTime.ElapsedGameTime.Milliseconds);
        }
Example #4
0
        protected override void HandleResponse(GameTime gameTime, Actor3D collidee)
        {
            //what objects are we interested in?
            if (collidee.ActorType == ActorType.CollidablePickup || collidee.ActorType == ActorType.Player)
            {
                //sends an event every minTimeBetweenSoundEventInMs seconds
                if (totalElapsedTimeInMs > minTimeBetweenSoundEventInMs)
                {
                    //object[] additionalParametersA = { "boing" };
                    //EventDispatcher.Publish(new EventData(EventActionType.OnPlay, EventCategoryType.Sound2D, additionalParametersA));
                    //totalElapsedTimeInMs = 0;

                    //or tell a UI mouse something
                    //float distanceToObject = (float)Math.Round(Vector3.Distance(this.ManagerParameters.CameraManager.ActiveCamera.Transform.Translation,
                    //                                                                        collidee.Transform.Translation), DefaultDistanceToTargetPrecision);
                    //object[] additionalParametersB = { collidee, distanceToObject };
                    //EventDispatcher.Publish(new EventData(EventActionType.OnObjectPicked, EventCategoryType.ObjectPicking, additionalParametersB));

                    //or do something directly like make the object rotate
                    //collidee.Transform.RotateAroundYBy(15f);
                }
                else
                {
                    totalElapsedTimeInMs += gameTime.ElapsedGameTime.Milliseconds;
                }

                //or we could remove the if..else code above and just remove the object - it all depends on how we want to handle mouse over events
                //or generate event to tell object manager and physics manager to remove the object
                //EventDispatcher.Publish(new EventData(collidee, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove));
            }
        }
 public static void RemoveAllAnimations(this Actor3D actor3D)
 {
     EventManager.FireEvent(
         new MovementEvent(new AnimationEventData {
         type = AnimationEventType.RemoveAllOfActor
     }));
 }
        private int sortComparator(Actor3D a, Actor3D b, Camera3D camera)
        {
            float distAToCamera = Vector3.Distance(a.Transform3D.Translation, camera.Transform3D.Translation);
            float distBToCamera = Vector3.Distance(b.Transform3D.Translation, camera.Transform3D.Translation);

            return(distBToCamera.CompareTo(distAToCamera));
        }
Example #7
0
        private void HandleKeyboardInput(GameTime gameTime, Actor3D parent)
        {
            Vector3 moveVector = Vector3.Zero;

            if (this.keyboardManager.IsKeyDown(moveKeys[0]))
            {
                moveVector = parent.Transform3D.Look * this.moveSpeed;
            }
            else if (this.keyboardManager.IsKeyDown(moveKeys[1]))
            {
                moveVector = -1 * parent.Transform3D.Look * this.moveSpeed;
            }

            if (this.keyboardManager.IsKeyDown(moveKeys[2]))
            {
                moveVector -= parent.Transform3D.Right * this.strafeSpeed;
            }
            else if (this.keyboardManager.IsKeyDown(moveKeys[3]))
            {
                moveVector += parent.Transform3D.Right * this.strafeSpeed;
            }

            //constrain movement in Y-axis
            moveVector.Y = 0;

            parent.Transform3D.TranslateBy(moveVector * gameTime.ElapsedGameTime.Milliseconds);
        }
        private void UpdateParent(GameTime gameTime, IActor actor)
        {
            Actor3D parent = actor as Actor3D;            //camera
            Actor3D target = this.TargetActor as Actor3D; //car

            if (parent != null)
            {
                //get target look and rotate around target right by elevationAngle
                Vector3 targetToCamera = Vector3.Transform(target.Transform3D.Look,
                                                           Matrix.CreateFromAxisAngle(target.Transform3D.Right,
                                                                                      MathHelper.ToRadians(this.elevationAngleInDegrees)));

                //want unit length
                targetToCamera.Normalize();

                //final camera position <- intermediate camera positions
                parent.Transform3D.Translation
                    = Vector3.Lerp(this.oldCameraTranslation, target.Transform3D.Translation
                                   + targetToCamera * this.distanceFromTarget, this.lerpSpeed);

                parent.Transform3D.Look = -targetToCamera;

                //store the old camera for the next round of lerp in next update(
                this.oldCameraTranslation = parent.Transform3D.Translation;
            }
        }
Example #9
0
 public RotationTween(Actor3D actor, int timeInMs, Vector3 destination, bool relative, Action <Actor3D> callback = null, LoopType loopType = LoopType.PlayOnce, EasingType easingType = EasingType.linear)
     : base(actor, timeInMs, destination, relative, callback, loopType, easingType)
 {
     if (relative)
     {
         base.destination += actor.Transform3D.RotationInDegrees;
     }
 }
 public static void ScaleTo(this Actor3D actor3D, AnimationEventData animationEventData)
 {
     if (animationEventData.actor == null)
     {
         animationEventData.actor = actor3D;
     }
     EventManager.FireEvent(new ScaleEvent(animationEventData));
 }
 /// <summary>
 /// Starts moving the obstacle
 /// </summary>
 /// <param name="obstacle">The obstacle to move</param>
 private void MoveObstacle(Actor3D obstacle)
 {
     EventDispatcher.Publish(new EventData(
                                 EventCategoryType.Tween, EventActionType.OnAdd,
                                 new object[] { new TranslationTween(
                                                    obstacle, 1000 * (int)(destination - obstacle.Transform3D.Translation).Length(),
                                                    destination, false, ResetObstacle) })
                             );
 }
 private void RemoveActorTweens(Actor3D actor)
 {
     foreach (Tween tween in tweens)
     {
         if (tween.Actor.Equals(actor))
         {
             tweensToRemove.Add(tween);
         }
     }
 }
Example #13
0
        public void Update(GameTime gameTime, IActor actor)
        {
            Actor3D parent = actor as Actor3D;

            if (parent != null)
            {
                HandleInput(gameTime, parent);
                HandleCameraFollow(gameTime, parent);
            }
        }
        public override void Update(GameTime gameTime, IActor actor)
        {
            Actor3D parent = actor as Actor3D;

            if (parent != null)
            {
                HandleKeyboardInput(gameTime, parent);
                HandleMouseInput(gameTime, parent);
            }
        }
        public override void HandleMouseInput(GameTime gameTime, Actor3D parent)
        {
            Vector2 mouseDelta = this.MouseManager.GetDeltaFromCentre(new Vector2(512, 384)); //REFACTOR - NMCG

            mouseDelta *= this.RotationSpeed * gameTime.ElapsedGameTime.Milliseconds;

            if (mouseDelta.Length() != 0)
            {
                parent.Transform3D.RotateBy(new Vector3(-1 * mouseDelta, 0));
            }
        }
Example #16
0
        public static HitResult Raycast(this Actor3D callingDrawnActor3D, OurObjectManager objectManager,
                                        Vector3 position, Vector3 direction, bool ignoreSelf,
                                        float maxDist = float.MaxValue, bool onlyCheckBlocking = true)
        {
            List <HitResult> all = RaycastAll(callingDrawnActor3D, objectManager, position, direction, ignoreSelf,
                                              maxDist, onlyCheckBlocking);

            all.Sort();

            return(all.Count == 0 ? null : all[0]);
        }
Example #17
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            Actor3D parent = actor as Actor3D;

            if (parent != null)
            {
                parent.Transform3D.RotationInDegrees += rotationSpeed * rotationAxis;
            }

            base.Update(gameTime, actor);
        }
 public InterpolatingProjectile(Actor3D owner, Actor3D target, HierarchyObject3D missile)
     : base(owner.Position)
 {
     elapsedTime    = 0;
     Owner          = owner;
     Target         = target;
     Position       = Owner.Position;
     Orientation    = Quaternion.CreateLookAt(Owner.Position, Target.Position, Vector3D.UnitZ);
     timeTillImpact = Owner.Position.DistanceSquared(Target.Position) / ProjectileSpeed;
     AddChild(missile);
 }
Example #19
0
 protected AnimationEvent(AnimationEventData animationEventData)
 {
     actor          = animationEventData.actor;
     destination    = animationEventData.destination;
     maxTime        = animationEventData.maxTime;
     smoothing      = animationEventData.smoothing;
     loopMethod     = animationEventData.loopMethod;
     isRelative     = animationEventData.isRelative;
     body           = animationEventData.body;
     callback       = animationEventData.callback;
     resetAfterDone = animationEventData.resetAferDone;
 }
Example #20
0
        private static List <HitResult> RaycastAll(this Actor3D callingDrawnActor3D, OurObjectManager objectManager,
                                                   Vector3 position, Vector3 direction, bool ignoreSelf,
                                                   float maxDist = float.MaxValue, bool onlyCheckBlocking = true)
        {
            List <Actor3D> ignoreList = new List <Actor3D>();

            if (ignoreSelf)
            {
                ignoreList.Add(callingDrawnActor3D);
            }

            return(RaycastAll(objectManager, position, direction, maxDist, ignoreList, onlyCheckBlocking));
        }
        private List <Tween> GetActorTweens(Actor3D actor)
        {
            List <Tween> tweens = new List <Tween>();

            foreach (Tween tween in this.tweens)
            {
                if (tween.Actor.Equals(actor))
                {
                    tweens.Add(tween);
                }
            }

            return(tweens);
        }
Example #22
0
        protected Tween(Actor3D actor, int timeInMs, Vector3 destination, bool relative, Action <Actor3D> callback = null,
                        LoopType loopType = LoopType.PlayOnce, EasingType easingType = EasingType.linear)
        {
            Actor      = actor;
            TimeInMs   = timeInMs;
            EasingType = easingType;
            LoopType   = loopType;
            Relative   = relative;
            Callback   = callback;

            this.destination = relativeDestination = destination;
            childActors      = new List <Actor3D>();
            currentTimeInMs  = timeInMs;

            Init();
        }
        private void EventDispatcher_ObjectPickChanged(EventData eventData)
        {
            if (eventData.EventType == EventActionType.OnObjectPicked)
            {
                SetAppearance();

                Actor3D collidee         = eventData.AdditionalParameters[0] as Actor3D;
                float   distanceToObject = (float)eventData.AdditionalParameters[1];
                this.Text = collidee.ID + "[" + distanceToObject + "]";
            }
            else if (eventData.EventType == EventActionType.OnNonePicked)
            {
                ResetAppearance();

                this.Text = eventData.AdditionalParameters[0] as string;
            }
        }
        public override void Update(GameTime gameTime, IActor actor)
        {
            Actor3D parent = actor as Actor3D;

            if (parent != null)
            {
                elapsedTimeInMs += gameTime.ElapsedGameTime.Milliseconds;
                ///for a discussion of "out" see https://www.c-sharpcorner.com/article/out-parameter-in-c-sharp-7/
                transform3DCurve.Evalulate(elapsedTimeInMs, EVALUATE_PRECISION, out translation, out look, out up);

                parent.Transform3D.Translation = translation;
                parent.Transform3D.Look        = look;
                parent.Transform3D.Up          = up;
            }

            //does nothing so comment out
            //base.Update(gameTime, actor);
        }
Example #25
0
        public override void HandleEvent(EventData eventData)
        {
            if (eventData.EventCategoryType == EventCategoryType.GameState)
            {
                switch (eventData.EventActionType)
                {
                case EventActionType.OnLose:
                    EndGame(EventActionType.OnLose);
                    break;

                case EventActionType.OnWin:
                    EndGame(EventActionType.OnWin);
                    break;

                case EventActionType.OnLeaveGame:
                    hasGameStarted = false;
                    break;

                case EventActionType.OnStart:
                    StartGame(eventData.Parameters[0] as string);
                    break;

                case EventActionType.OnRestart:
                    StartGame(currentLevelId);
                    break;

                case EventActionType.OnSpawn:
                    player = eventData.Parameters[0] as Actor3D;
                    EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnSetListener, new[] { player.Transform3D }));
                    (cameraManager[1].ControllerList.Find(c => c is PlayerFollowCameraController) as PlayerFollowCameraController).SetTargetTransform(player.Transform3D);
                    break;

                case EventActionType.OnStarPickup:
                    EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay2D, new object[] { "star" }));
                    EventDispatcher.Publish(new EventData(EventCategoryType.UI, EventActionType.OnStarPickup, new object[] { ++stars }));
                    break;
                }
            }

            //remember to pass the eventData down so the parent class can process pause/unpause
            base.HandleEvent(eventData);
        }
Example #26
0
        private void HandleKeyboardInput(GameTime gameTime, Actor3D parent)
        {
            if (moveParameters.KeyboardManager.IsKeyDown(Keys.W))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Look * moveParameters.MoveSpeed);
            }
            else if (moveParameters.KeyboardManager.IsKeyDown(Keys.S))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Look * -moveParameters.MoveSpeed);
            }

            if (moveParameters.KeyboardManager.IsKeyDown(Keys.A))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Right * -moveParameters.StrafeSpeed);
            }
            else if (moveParameters.KeyboardManager.IsKeyDown(Keys.D))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Right * moveParameters.StrafeSpeed);
            }
        }
Example #27
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            Actor3D parent = actor as Actor3D;

            if (parent != null)
            {
                //get the total elapsed time and mod with 360 since a sine wave will only need input from 0-359 degrees
                float time = (float)gameTime.TotalGameTime.TotalSeconds % 360;

                // y = A * Sin(wT + phaseAngle)
                float rotAngle = trigonometricParameters.MaxAmplitude * (float)Math.Sin(
                    MathHelper.ToRadians(trigonometricParameters.AngularSpeed * time + trigonometricParameters.PhaseAngleInDegrees));

                //apply rotation to the parent
                parent.Transform3D.RotateBy(rotationAxis * rotAngle);
            }

            //always check if its necessary to call the base method i.e. does the base method have any code?
            //base.Update(gameTime, actor);
        }
        public override void HandleKeyboardInput(GameTime gameTime, Actor3D parent)
        {
            if (this.KeyboardManager.IsKeyDown(Keys.W))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Look * this.MoveSpeed);
            }
            else if (this.KeyboardManager.IsKeyDown(Keys.S))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Look * -this.MoveSpeed);
            }

            if (this.KeyboardManager.IsKeyDown(Keys.A))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Right * -this.StrafeSpeed);
            }
            else if (this.KeyboardManager.IsKeyDown(Keys.D))
            {
                parent.Transform3D.TranslateBy(parent.Transform3D.Right * this.StrafeSpeed);
            }
        }
Example #29
0
        private void Initialize(Actor3D parent)
        {
            if (parent == null)
            {
                throw new ArgumentException("parent is null!");
            }

            parentTransform  = parent.Transform3D;
            launchDirections = new List <Vector3> {
                parentTransform.Right, -parentTransform.Right, parentTransform.Look, -parentTransform.Look
            };

            //Start the rotation and scaling animation (Projectiles are launched at each iteration)
            EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new object[]
            {
                new RotationTween(parent, GameConstants.Projectile_CooldownInMs,
                                  new Vector3(0, 45, 0), true, LaunchProjectiles, LoopType.Repeat),
                new ScaleTween(parent, GameConstants.Projectile_CooldownInMs / 2,
                               Vector3.One * 1.2f, false, null, LoopType.ReverseAndRepeat)
            }));
        }
Example #30
0
        private void HandleMouseInput(GameTime gameTime, Actor3D parent)
        {
            Vector2 mouseDelta =
                mouseManager.GetDeltaFromCentre(new Vector2(GameConstants.ScreenWidth / 2f,
                                                            GameConstants.ScreenHeight / 2f));

            mouseDelta *= rotationSpeed * gameTime.ElapsedGameTime.Milliseconds * rotationSpeed;

            if (!(mouseManager.Position.X < GameConstants.ScreenWidth / 2f + GameConstants.ScreenWidth * 0.1f &&
                  mouseManager.Position.X > GameConstants.ScreenWidth / 2f - GameConstants.ScreenWidth * 0.1f &&
                  mouseManager.Position.Y < GameConstants.ScreenHeight / 2f + GameConstants.ScreenHeight * 0.1f &&
                  mouseManager.Position.Y > GameConstants.ScreenHeight / 2f - GameConstants.ScreenHeight * 0.1f))
            {
                move += new Vector3(-1 * mouseDelta.X, mouseDelta.Y, 0);
            }

            if (move.Length() != 0)
            {
                parent.Transform3D.RotateBy(move);
            }
        }