Esempio n. 1
0
 public static void check(Entity ent, Player player)
 {
     if (ent.position.X + ent.texture.Width / 2  < player.position.X - player.imageDimension().X / 2 ||
         ent.position.Y + ent.texture.Height / 2 < player.position.Y - player.imageDimension().Y / 2 ||
         ent.position.X - ent.texture.Width / 2  > player.position.X + player.imageDimension().X / 2 ||
         ent.position.Y - ent.texture.Height / 2 > player.position.Y + player.imageDimension().Y / 2)
     {
         // No Collision
     }
     else
     {
         ent.doCollision(player);
         player.doCollision(ent);
     }
 }
Esempio n. 2
0
 public void checkPlayerCollisions(Player e)
 {
     foreach (Bullet b in bullets)
     {
         if ((b.shotBy is Entity))
         {
             if (b.position.X > e.position.X - e.imageDimension().X / 2 &&
                 b.position.X < e.position.X + e.imageDimension().X / 2 &&
                 b.position.Y > e.position.Y - e.imageDimension().Y / 2 &&
                 b.position.Y < e.position.Y + e.imageDimension().Y / 2)
             {
                 if (!e.shielding)
                     e.health -= 1;
                 b.alive = false;
             }
         }
     }
 }
Esempio n. 3
0
        public bool teleportCheck2(Player p, Vector2 result)
        {
            int xmin = (int)(result.X + 1 - p.imageDimension().X / 2) / tileWidth;
            int xmax = (int)(result.X - 1 + p.imageDimension().X / 2) / tileWidth;
            int ymin = (int)(result.Y + 1 - p.imageDimension().Y / 2) / tileWidth;
            int ymax = (int)(result.Y - 1 + p.imageDimension().Y / 2) / tileWidth;

            int x = (int)(result.X) / tileWidth;
            int y = (int)(result.Y) / tileWidth;

            if (m_tiles[x, ymin] != null)
            {
                return false;
                //p.velocity.Y = 0;
            }

            if (m_tiles[x, ymax] != null)
            {
                return false;
                //p.jump = false;
            }
            else
            {
                //p.jump = true;
            }

            if (m_tiles[xmin, y] != null)
            {
                return false;
            }
            if (m_tiles[xmax, y] != null)
            {
                return false;
            }
            return true;
        }
Esempio n. 4
0
        public Vector2 teleportCheck(Player p, Vector2 displaced)
        {
            Vector2 result = p.position + displaced;
            int xmin = (int)(result.X - p.imageDimension().X / 2) / tileWidth;
            int xmax = (int)(result.X + p.imageDimension().X / 2) / tileWidth;
            int ymin = (int)(result.Y - p.imageDimension().Y / 2) / tileWidth;
            int ymax = (int)(result.Y + p.imageDimension().Y / 2) / tileWidth;

            int x = (int)(result.X) / tileWidth;

            if (m_tiles[x, ymin] != null)
            {
                result.Y = ymax * tileWidth + p.imageDimension().Y / 2;
                //p.velocity.Y = 0;
            }

            if (m_tiles[x, ymax] != null)
            {
                result.Y = ymax * tileWidth - p.imageDimension().Y / 2;
                //p.jump = false;
            }
            else
            {
                //p.jump = true;
            }

            int y = (int)(result.Y) / tileWidth;

            if (m_tiles[xmin, y] != null)
            {
                result.X = (xmax) * tileWidth + p.imageDimension().X / 2;
            }
            if (m_tiles[xmax, y] != null)
            {
                result.X = xmax * tileWidth - p.imageDimension().X / 2;
            }
            if (teleportCheck2(p, result))
            {
                return result;
            }
            else
            {
                p.health = 0;
                return result;
            }
        }
Esempio n. 5
0
        public void checkPlayerCollisionRev(Player p)
        {
            int xmin = (int)(p.position.X - p.imageDimension().X / 2) / tileWidth;
            int xmax = (int)(p.position.X + p.imageDimension().X / 2) / tileWidth;
            int ymin = (int)(p.position.Y - p.imageDimension().Y / 2) / tileWidth;
            int ymax = (int)(p.position.Y + p.imageDimension().Y / 2) / tileWidth;

            int x = (int)(p.position.X) / tileWidth;

            if (m_tiles[x, ymin] != null)
            {
                p.position.Y = ymax * tileWidth + p.imageDimension().Y / 2;
                p.jump = false;
                p.velocity.Y = 0;
                if (m_tiles[x, ymin].getType() == 1)
                {
                    p.health = 0;
                }
            }

            if (m_tiles[x, ymax] != null)
            {
                p.position.Y = ymax * tileWidth - p.imageDimension().Y / 2;
                p.velocity.Y = 0;
                if (m_tiles[x, ymax].getType() == 1)
                {
                    p.health = 0;
                }
            }
            else
            {
                p.jump = true;
            }

            int y = (int)(p.position.Y) / tileWidth;

            if (m_tiles[xmin, y] != null)
            {
                p.position.X = (xmax) * tileWidth + p.imageDimension().X / 2;
                if (m_tiles[xmin, y].getType() == 1)
                {
                    p.health = 0;
                }
            }
            if (m_tiles[xmax, y] != null)
            {
                p.position.X = xmax * tileWidth - p.imageDimension().X / 2;
                if (m_tiles[xmax, y].getType() == 1)
                {
                    p.health = 0;
                }
            }
        }