Beispiel #1
0
 /// <summary>
 /// Collision detection for the block in the middle.
 /// </summary>
 /// <param name="e">The entity we want to check.</param>
 /// <returns></returns>
 public Blocker IsEntityCollidingBlocker(Entity e)
 {
     if (blocker.GetRecHit().Intersects(e.GetRecHit()))
     {
         return(blocker);
     }
     return(null);
 }
Beispiel #2
0
        /// <summary>
        /// Update the y axis movement.
        /// </summary>
        public void yAxisUpdate(float delta)
        {
            pos.Y   += velocity.Y * delta;
            recHit.Y = (int)(pos.Y - recHit.Height);
            Blocker blocker = world.IsEntityCollidingBlocker(this);

            if (blocker != null)
            {
                if (velocity.Y > 0)
                {
                    pos.Y       = blocker.GetRecHit().Y - 5;
                    velocity.Y *= -1f;
                }
                else
                {
                    pos.Y      = blocker.GetRecHit().Y + blocker.GetRecHit().Height + recHit.Height + 5;
                    velocity.Y = 0;
                }
                recHit.Y = (int)(pos.Y - recHit.Height);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Update the x axis movement.
        /// </summary>
        public void xAxisUpdate(float delta)
        {
            pos.X   += velocity.X * delta;
            recHit.X = (int)(pos.X - recHit.Width / 2);
            Blocker blocker = world.IsEntityCollidingBlocker(this);

            if (blocker != null)
            {
                if (velocity.X >= 0)
                {
                    pos.X = blocker.GetRecHit().X - recHit.Width / 2;
                }
                else
                {
                    pos.X = blocker.GetRecHit().X + blocker.GetRecHit().Width + recHit.Width / 2;
                }

                velocity.X = 0f;
                recHit.X   = (int)(pos.X - recHit.Width / 2);
            }
        }