Пример #1
0
        private static bool CheckCollisionWall(Wall source, Entity target)
        {
            if (source.col_rect.Intersects(target.col_rect))
            {
                if (target is ProjectileParticle) { target.remove = true; return true; }

                Vector2 distance = new Vector2(Math.Abs(source.col_rect.Center.X - target.col_rect.Center.X), Math.Abs(source.col_rect.Center.Y - target.col_rect.Center.Y));
                Vector2 i_distance = new Vector2(Math.Abs(source.col_rect.Width / 2 + target.col_rect.Width / 2 - distance.X), Math.Abs(source.col_rect.Height / 2 + target.col_rect.Height / 2 - distance.Y));

                if (i_distance.Y > i_distance.X)
                {
                    target.velocity.X = 0;
                    target.pos.X = (target.col_rect.Center.X < source.col_rect.Center.X) ?
                        source.col_rect.X - target.col_rect.Width :
                        source.col_rect.X + source.col_rect.Width;
                }
                else if (i_distance.Y < i_distance.X)
                {
                    target.velocity.Y = 0;
                    target.pos.Y = (target.col_rect.Center.Y < source.col_rect.Center.Y) ?
                        source.col_rect.Y - target.col_rect.Height :
                        source.col_rect.Y + source.col_rect.Height;
                }
            }
            return false;
        }
Пример #2
0
 public Level()
 {
     for (int y = 0; y < walls.GetUpperBound(1) + 1; y++)
         for (int x = 0; x < walls.GetUpperBound(0) + 1; x++)
             if (x == 0 || x == walls.GetUpperBound(0) || y == 0 || y == walls.GetUpperBound(1))
                 walls[x, y] = new Wall(Global.wallManager.Get("wall1"), (int)(x * Constants.wallSize), (int)(y * Constants.wallSize));
             else walls[x, y] = null;
 }
Пример #3
0
 public Wall(Wall wall, int x, int y)
     : base(wall)
 {
     sprite = Global.spriteManager.dict["wall"].Get(key);
     pos = new Vector2(x, y);
     col_rect = new Rectangle(x, y, Constants.wallSize, Constants.wallSize);
     imgpos = new Vector2(x, col_rect.Bottom - sprite.rect.Height);
     depth = col_rect.Bottom * 0.0001f;
 }