Esempio n. 1
0
        private void Tick(Location location, Entity entity)
        {
            if (Program.Engine.Location.GetEntities <DialogBox>().Any())
            {
                return;
            }

            if (sound == null)
            {
                Boom();
            }

            Description2D d2d = entity.Description as Description2D;

            d2d.ChangeCoordsDelta(Math.Cos(dir) * 8, Math.Sin(dir) * 8);
            foreach (T enemy in location.GetEntities <T>())
            {
                if (d2d.IsCollision(enemy))
                {
                    location.RemoveEntity(enemy.Id);
                }
            }

            if (Program.Collision(d2d, location.GetEntities <Wall>().Select(w => (Description2D)w).ToList()))
            {
                location.RemoveEntity(Id);
            }
        }
Esempio n. 2
0
        private bool IsCollision(List <WallDescription> walls, Description2D description)
        {
            foreach (WallDescription wall in walls)
            {
                if (description.IsCollision(wall))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
        public static bool Collision(Description2D d1, Description2D d2)
        {
            return(d1.IsCollision(d2));

            /*double d1Size = Math.Sqrt(d1.Width * d1.Width + d1.Height * d1.Height / 4);
             * double d2Size = Math.Sqrt(d2.Width * d2.Width + d2.Height * d2.Height / 4);
             *
             * double dist = d1.Distance(d2);
             *
             * if (dist <= (d1Size + d2Size) / 1.5)
             * {
             *  Bitmap bmp = BitmapExtensions.CreateBitmap((int)(d1Size + d2Size) + 20, (int)(d1Size + d2Size) + 20);
             *  Graphics gfx = Graphics.FromImage(bmp);
             *  float minX = (float)Math.Min(d1.X - d1.Sprite.X, d2.X - d2.Sprite.X);
             *  float minY = (float)Math.Min(d1.Y - d1.Sprite.X, d2.Y - d2.Sprite.X);
             *  gfx.TranslateTransform(-minX + 10, -minY + 10);
             *
             *  Bitmap b1 = (Bitmap)d1.Image();
             *  Bitmap b2 = (Bitmap)d2.Image();
             *
             *  gfx.DrawImage(b1, (float)d1.X - d1.Sprite.X, (float)d1.Y - d1.Sprite.X);
             *  gfx.DrawImage(b2, (float)d2.X - d2.Sprite.X, (float)d2.Y - d2.Sprite.Y);
             *
             *  int total = 0;
             *  for (int i = 0; i < b1.Width; i++)
             *  {
             *      for (int j = 0; j < b1.Height; j++)
             *      {
             *          if (b1.GetPixel(i, j).A != 0)
             *          {
             *              total++;
             *          }
             *      }
             *  }
             *
             *  for (int i = 0; i < b2.Width; i++)
             *  {
             *      for (int j = 0; j < b2.Height; j++)
             *      {
             *          if (b2.GetPixel(i, j).A != 0)
             *          {
             *              total++;
             *          }
             *      }
             *  }
             *
             *  int count = 0;
             *  for (int i = 0; i < bmp.Width; i++)
             *  {
             *      for (int j = 0; j < bmp.Height; j++)
             *      {
             *          Color c = bmp.GetPixel(i, j);
             *          if (c.A != 0)
             *          {
             *              count++;
             *          }
             *      }
             *  }
             *
             *  return count != total;
             * }
             *
             * return false;*/
        }