Exemplo n.º 1
0
        /// <summary>
        /// Gets if the values of this <see cref="WallEntityBase"/> equal the values of another, and if they are of the
        /// same type. Not all values need to be taken into consideration, just relevant ones to seeing if two walls are
        /// functionally the same.
        /// </summary>
        /// <param name="other">The <see cref="WallEntityBase"/> to compare to. Can be null.</param>
        /// <returns>True if this <see cref="WallEntityBase"/> has the same values and type as the <paramref name="other"/>;
        /// otherwise false. Also returns false when <paramref name="other"/> is null.</returns>
        public virtual bool AreValuesEqual(WallEntityBase other)
        {
            if (other == null)
            {
                return(false);
            }

            // Check if the same object instance
            if (this == other)
            {
                return(true);
            }

            // Check the values
            if (Position != other.Position || Size != other.Size || IsPlatform != other.IsPlatform || Weight != other.Weight ||
                Velocity != other.Velocity)
            {
                return(false);
            }

            // Check for the same type
            if (GetType() != other.GetType())
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Perform pre-collision velocity and position updating.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="deltaTime">The amount of that that has elapsed time since last update.</param>
        public virtual void UpdateVelocity(IMap map, int deltaTime)
        {
            _lastPosition = Position;

            // Only perform movement if moving
            if (IsOnGround && Velocity == Vector2.Zero)
            {
                return;
            }

#if !TOPDOWN
            Vector2 gravity;
            if (map == null)
            {
                gravity = _defaultGravity;
            }
            else
            {
                gravity = map.Gravity;
            }

            if (StandingOn != null)
            {
                if (!WallEntityBase.IsEntityStandingOn(StandingOn, this))
                {
                    StandingOn = null;
                }
            }

            if (StandingOn == null)
            {
                // Increase the velocity by the gravity
                var displacement = gravity * (Weight * deltaTime);
                Vector2.Add(ref _velocity, ref displacement, out _velocity);
            }
#endif

            // Check for surpassing the maximum velocity
            if (_velocity.X > _maxVelocity.X)
            {
                _velocity.X = _maxVelocity.X;
            }
            else if (_velocity.X < -_maxVelocity.X)
            {
                _velocity.X = -_maxVelocity.X;
            }

            if (_velocity.Y > _maxVelocity.Y)
            {
                _velocity.Y = _maxVelocity.Y;
            }
            else if (_velocity.Y < -_maxVelocity.Y)
            {
                _velocity.Y = -_maxVelocity.Y;
            }

            // Move according to the velocity
            Move(_velocity * deltaTime);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles updating this <see cref="Entity"/>.
        /// </summary>
        /// <param name="imap">The map the <see cref="Entity"/> is on.</param>
        /// <param name="deltaTime">The amount of time (in milliseconds) that has elapsed since the last update.</param>
        protected virtual void HandleUpdate(IMap imap, int deltaTime)
        {
            // If moving, perform collision detection
            if (Velocity != Vector2.Zero)
            {
                imap.CheckCollisions(this);
            }

#if !TOPDOWN
            // If the entity is standing on a wall, make sure they are still standing on it. If they aren't, check if they
            // are standing on top of something else.
            if (StandingOn != null)
            {
                if (!WallEntityBase.IsEntityStandingOn(StandingOn, this))
                {
                    StandingOn = imap.FindStandingOn(this);
                }
            }
#endif
        }
Exemplo n.º 4
0
 /// <summary>
 /// Draws a WallEntity.
 /// </summary>
 /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
 /// <param name="camera">The <see cref="ICamera2D"/> that describes the current view.</param>
 /// <param name="wall">WallEntity to draw.</param>
 public static void Draw(ISpriteBatch sb, ICamera2D camera, WallEntityBase wall)
 {
     Draw(sb, camera, wall, Vector2.Zero);
 }
Exemplo n.º 5
0
 public static void Draw(ISpriteBatch sb, ICamera2D camera, WallEntityBase wall, Vector2 offset)
 {
     Draw(sb, wall, _wallColor, border: false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Gets if the values of this <see cref="WallEntityBase"/> equal the values of another, and if they are of the
        /// same type. Not all values need to be taken into consideration, just relevant ones to seeing if two walls are
        /// functionally the same.
        /// </summary>
        /// <param name="other">The <see cref="WallEntityBase"/> to compare to. Can be null.</param>
        /// <returns>True if this <see cref="WallEntityBase"/> has the same values and type as the <paramref name="other"/>;
        /// otherwise false. Also returns false when <paramref name="other"/> is null.</returns>
        public virtual bool AreValuesEqual(WallEntityBase other)
        {
            if (other == null)
                return false;

            // Check if the same object instance
            if (this == other)
                return true;

            // Check the values
            if (Position != other.Position || Size != other.Size || IsPlatform != other.IsPlatform || Weight != other.Weight ||
                Velocity != other.Velocity)
                return false;

            // Check for the same type
            if (GetType() != other.GetType())
                return false;

            return true;
        }
Exemplo n.º 7
0
        public static void Draw(ISpriteBatch sb, ICamera2D camera, WallEntityBase wall, Vector2 offset)
        {
            // Find the positon to draw to
            var p = wall.Position + offset;
            var dest = new Rectangle(p.X, p.Y, wall.Size.X, wall.Size.Y);

            // Draw the collision area
            RenderRectangle.Draw(sb, dest, _wallColor);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets the string to display for an item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>The string to display.</returns>
 static string GetDrawString(WallEntityBase item)
 {
     return string.Format("({0},{1}) [{2}x{3}]{4}", item.Position.X, item.Position.Y, item.Size.X, item.Size.Y,
         item.IsPlatform ? " - Platform" : string.Empty);
 }