protected Sprite _sprite; // Sprite for the object

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">Parent of the object</param>
        /// <param name="name">Name of the object</param>
        /// <param name="sprite">Sprite representing the object</param>
        public WorldObject(SceneNode parent, String name, Sprite sprite)
            : base(parent, name)
        {
            _sprite = sprite;
            _position = Vector2.Zero;
            _aabb = new AABB(Centre, new Vector2(sprite.Width / 2.0f, sprite.Height / 2.0f));
        }
Exemple #2
0
        /// <summary>
        /// Checks for a collision between 2 AABBs
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public bool DoesCollide(AABB box)
        {
            // If there is no overlap in either the x or the y direction, there can't possible be a collision
            if (Math.Abs(_centre.X - box.Centre.X) > (_halfWidths.X + box.HalfWidths.X))
            {
                return false;
            }

            if (Math.Abs(_centre.Y - box.Centre.Y) > (_halfWidths.Y + box.HalfWidths.Y)) {
                return false;
            }

            // Overlaps were detected in both directions, there must be a collision
            return true;
        }
        /// <summary>
        /// Updates the world object
        /// </summary>
        /// <param name="gameTime">Game Time</param>
        public override void Update(GameTime gameTime)
        {
            _previousPosition = _position;
            _previousAABB = _aabb;

            _sprite.Update(gameTime);

            base.Update(gameTime);
        }