Ejemplo n.º 1
0
        public static float MoveAlongVector(MovingObject entity, TimeStamp p1, TimeStamp p2, float timeStep)
        {
            Vector3 direction = Vector3.Subtract(p2.Vector3, entity.TimePosition);

            double distance = direction.Length();

            Vector3 movement = Vector3.Normalize(direction);

            //Note: This doesn't really work. Different objects travel at different speeds, so having a constant speed here breaks the whole thing. Change the algorithm so that it takes the speeds of different objects into accoutn.
            entity.TimePosition += movement*(entity.Acceleration*timeStep)*5;

            Vector3 checkVector =  Vector3.Subtract(p2.Vector3, entity.TimePosition);

            double checkDistance = checkVector.Length();

            if(checkDistance > distance )
            {

                entity.TimePosition = p2.Vector3;

                int navigation = (int) (p2.Time - p1.Time);

                entity.TimeStamps.Navigate(navigation);

                return (float)(checkDistance - distance);
            }

            return 0;
        }
Ejemplo n.º 2
0
        //TODO: Implement a collision detection between moving objects
        /// <summary>
        /// Handels Collision between a moving object (i.e. the player or an npc) and the level structure
        /// </summary>
        /// <param name="levelBlock">The levelBlock which the object could collide with</param>
        /// <param name="moveableObject">the animatedobject that needs to be checked</param>
        public void HandleLevelCollisions(LevelBlock levelBlock, MovingObject moveableObject)
        {
            if (levelBlock.IntersectRectangle.Intersects(moveableObject.IntersectRectangle))
            {
                if (moveableObject.PrevPosition.Y > levelBlock.IntersectRectangle.Bottom)
                {
                    moveableObject.Position = moveableObject.PrevPosition;
                    if (moveableObject is Player)
                    {
                        ((Player)moveableObject).AbortJump();
                    }

                }
                else if (levelBlock.IsAboveLevelObject(moveableObject))
                {

                    moveableObject.Position = new Vector2(moveableObject.Position.X,
                                                          levelBlock.Position.Y - moveableObject.Size.Y);
                }
                else if (levelBlock.Position.X > moveableObject.Position.X)
                {
                    moveableObject.Position = new Vector2(moveableObject.PrevPosition.X, moveableObject.Position.Y);
                }
                else if (levelBlock.Position.X < moveableObject.Position.X)
                {
                    moveableObject.Position = new Vector2(moveableObject.PrevPosition.X, moveableObject.Position.Y);
                }
            }
        }
Ejemplo n.º 3
0
        private void SpoolMovingObject(MovingObject movingObject, KeyboardState keyboardState, GameTime gameTime)
        {
            float carry = 0;
            TimeStamp p2 = new TimeStamp();

            if(keyboardState.IsKeyDown(Keys.Left))
            {
                if(movingObject.TimeStamps.Index.Next != null)
                {
                    p2 = movingObject.TimeStamps.Index.Next.Value;
                    carry = TimeStampHelper.MoveAlongVector( movingObject, movingObject.TimeStamps.Index.Value, p2, 5);

                    if(carry != 0)
                    {
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
                        if(movingObject.TimeStamps.Index.Next != null)
                        {
                            TimeStampHelper.MoveAlongVector(movingObject, movingObject.TimeStamps.Index.Value, movingObject.TimeStamps.Index.Next.Value, carry);
                        }
            // ReSharper restore ConditionIsAlwaysTrueOrFalse

                    }
                }

            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                if(movingObject.TimeStamps.Index.Previous != null)
                {
                    p2 = movingObject.TimeStamps.Index.Previous.Value;
                    carry = TimeStampHelper.MoveAlongVector(movingObject, movingObject.TimeStamps.Index.Value, p2, 5);

                    if(carry != 0)
                    {
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
                        if(movingObject.TimeStamps.Index.Previous != null)
            // ReSharper restore ConditionIsAlwaysTrueOrFalse
                        {
                            TimeStampHelper.MoveAlongVector(movingObject, movingObject.TimeStamps.Index.Value, movingObject.TimeStamps.Index.Previous.Value, carry);
                        }

                    }
                }

            }
        }
Ejemplo n.º 4
0
 public KeyPressedEventArgs(MovingObject sender, double time,KeyboardState keyboardState)
 {
     this.sender = sender;
     this.time = time;
     this.keyboardState = keyboardState;
 }
Ejemplo n.º 5
0
 public ActionEventArgs(MovingObject caller, FRect queryRect)
     : base(EventType.Action)
 {
     this.caller = caller;
     this.queryRect = queryRect;
 }
Ejemplo n.º 6
0
 private void HitWall(MovingObject collider, LevelBlock levelBlock)
 {
 }