public bool ContainsTags(Collider collider, T attributes)
        {
            var canCollide = collider != null &&
                             collider != this &&
                             IsCollidable &&
                             collider.IsCollidable;

            if (canCollide)
            {
                if (collider is ShapeCollider)
                {
                    var shape  = (collider as ShapeCollider).Shape;
                    var region = shape.Bounds
                                 .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                    foreach (var location in PlotRegion(region))
                    {
                        if (HasTags(location, attributes))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        public bool CastRay(
            Vector2 origin,
            Vector2 normal,
            float distance,
            T attributes,
            out Raycast hit)
        {
            hit = default;

            if (IsCollidable)
            {
                var tileSize = TileSize.ToVector2();
                var gStart   = origin.ToGrid(tileSize, AbsolutePosition);
                var gEnd     = (origin + normal * distance).ToGrid(tileSize, AbsolutePosition);

                foreach (var location in PlotLine(gStart, gEnd))
                {
                    var tile        = GetTileShape(location);
                    var hitDetected = tile?.CastRay(origin, normal, distance, out hit) ?? false;
                    if (hitDetected && HasTags(location, attributes))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool Overlaps(Shape shape, T attributes, out CollisionResult result)
        {
            result = new CollisionResult(this);

            var collide = false;

            if (IsCollidable && shape != null)
            {
                var region = shape.Bounds
                             .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                foreach (var location in PlotRegion(region))
                {
                    Manifold hit      = default;
                    var      tile     = GetTileShape(location);
                    var      overlaps = tile?.Overlaps(shape, out hit) ?? false;

                    if (overlaps && HasTags(location, attributes))
                    {
                        hit.Normal = -hit.Normal;
                        result.Add(hit);
                        collide = true;
                    }
                }
            }

            return(collide);
        }
Exemple #4
0
        public bool Overlaps(Collider collider, T attributes)
        {
            var canCollide = collider != null &&
                             collider != this &&
                             IsCollidable &&
                             collider.IsCollidable;

            if (canCollide)
            {
                if (collider is ShapeCollider)
                {
                    var shape  = (collider as ShapeCollider).Shape;
                    var region = shape.Bounds
                                 .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                    foreach (var location in PlotRegion(region))
                    {
                        var tile     = GetTileShape(location);
                        var overlaps = tile?.Overlaps(shape) ?? false;
                        if (overlaps && HasAttributes(location, attributes))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemple #5
0
        public sealed override bool Overlaps(Collider collider, out CollisionResult result)
        {
            if (base.Overlaps(collider, out result))
            {
                if (collider is ShapeCollider)
                {
                    var collide = false;
                    var shape   = (collider as ShapeCollider).Shape;
                    var region  = shape.Bounds
                                  .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                    foreach (var location in PlotRegion(region))
                    {
                        Manifold hit      = default;
                        var      tile     = GetTileShape(location);
                        var      overlaps = tile?.Overlaps(shape, out hit) ?? false;

                        if (overlaps)
                        {
                            hit.Normal = -hit.Normal;
                            result.Add(hit);
                            collide = true;
                        }
                    }

                    if (collide)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public SimpleTile GetTile(Vector2 point)
        {
            var location = point
                           .ToGrid(TileSize.ToVector2(), AbsolutePosition)
                           .ToPoint();

            return(new SimpleTile(location, Map[location]));
        }
Exemple #7
0
        public TaggedTile <T> GetTile(Vector2 point)
        {
            var location = point
                           .ToGrid(TileSize.ToVector2(), AbsolutePosition)
                           .ToPoint();

            return(new TaggedTile <T>(location, Map[location]));
        }
        public IEnumerable <SimpleTile> GetTiles(Shape shape)
        {
            var region = shape.Bounds
                         .ToGrid(TileSize.ToVector2(), AbsolutePosition);

            foreach (var location in PlotRegion(region))
            {
                yield return(new SimpleTile(location, Map[location]));
            }
        }
        public ComplexTile <T> GetTile(Vector2 point)
        {
            var location = point
                           .ToGrid(TileSize.ToVector2(), AbsolutePosition)
                           .ToPoint();

            return(new ComplexTile <T>(
                       location,
                       GetTileShape(location),
                       AttributeMap[location]));
        }
Exemple #10
0
        public sealed override bool Contains(Vector2 point, out Vector2 depth)
        {
            if (base.Contains(point, out depth))
            {
                var location = point.ToGrid(TileSize.ToVector2(), AbsolutePosition).ToPoint();
                var tile     = GetTileShape(location);
                return(tile?.Contains(point, out depth) ?? false);
            }

            return(false);
        }
        public IEnumerable <SimpleTile> GetTiles(Vector2 start, Vector2 end)
        {
            var tileSize = TileSize.ToVector2();

            start = start.ToGrid(tileSize, AbsolutePosition);
            end   = end.ToGrid(tileSize, AbsolutePosition);

            foreach (var location in PlotLine(start, end))
            {
                yield return(new SimpleTile(location, Map[location]));
            }
        }
        public bool Contains(Vector2 point, T attributes)
        {
            if (IsCollidable)
            {
                var location = point.ToGrid(TileSize.ToVector2(), AbsolutePosition).ToPoint();
                var tile     = GetTileShape(location);
                var collide  = tile?.Contains(point) ?? false;
                return(collide && HasTags(location, attributes));
            }

            return(false);
        }
Exemple #13
0
        protected override Shape GetTileShape(Point position)
        {
            var index = Map[position];

            if (index != Map.Empty)
            {
                var tileSize = TileSize.ToVector2();
                var location = AbsolutePosition + position.ToVector2() * tileSize;
                return(new Box(location, tileSize - Vector2.One));
            }

            return(null);
        }
        protected override Shape GetTileShape(Point position)
        {
            var isSolid = Convert.ToBoolean(Map[position]);

            if (isSolid)
            {
                var tileSize = TileSize.ToVector2();
                var location = AbsolutePosition + position.ToVector2() * tileSize;
                return(new Box(location, tileSize - Vector2.One));
            }

            return(null);
        }
        public IEnumerable <ComplexTile <T> > GetTiles(Shape shape)
        {
            var region = shape.Bounds
                         .ToGrid(TileSize.ToVector2(), AbsolutePosition);

            foreach (var location in PlotRegion(region))
            {
                yield return(new ComplexTile <T>(
                                 location,
                                 GetTileShape(location),
                                 AttributeMap[location]));
            }
        }
        public bool ContainsTags(Vector2 point, T attributes)
        {
            if (IsCollidable)
            {
                var location = point
                               .ToGrid(TileSize.ToVector2(), AbsolutePosition)
                               .ToPoint();

                return(HasTags(location, attributes));
            }

            return(false);
        }
        public IEnumerable <ComplexTile <T> > GetTiles(Vector2 start, Vector2 end)
        {
            var tileSize = TileSize.ToVector2();

            start = start.ToGrid(tileSize, AbsolutePosition);
            end   = end.ToGrid(tileSize, AbsolutePosition);

            foreach (var location in PlotLine(start, end))
            {
                yield return(new ComplexTile <T>(
                                 location,
                                 GetTileShape(location),
                                 AttributeMap[location]));
            }
        }
        public IEnumerable <SimpleTile> GetTiles(Collider collider)
        {
            if (collider != null && collider != this)
            {
                if (collider is ShapeCollider)
                {
                    var region = collider.Bounds
                                 .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                    foreach (var location in PlotRegion(region))
                    {
                        yield return(new SimpleTile(location, Map[location]));
                    }
                }
            }
        }
        public bool ContainsTags(Shape shape, T attributes)
        {
            if (IsCollidable && shape != null)
            {
                var region = shape.Bounds
                             .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                foreach (var location in PlotRegion(region))
                {
                    if (HasTags(location, attributes))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool ContainsTags(Vector2 start, Vector2 end, T attributes)
        {
            if (IsCollidable)
            {
                var tileSize = TileSize.ToVector2();
                var gStart   = start.ToGrid(tileSize, AbsolutePosition);
                var gEnd     = end.ToGrid(tileSize, AbsolutePosition);

                foreach (var location in PlotLine(gStart, gEnd))
                {
                    if (HasTags(location, attributes))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected override Shape GetTileShape(Point position)
        {
            var index = Map[position];

            if (index != Map.Empty)
            {
                Tile tile;

                if (Tiles.TryGetValue(index, out tile))
                {
                    var tileSize = TileSize.ToVector2();
                    var offset   = AbsolutePosition + position.ToVector2() * tileSize;
                    var vertices = tile.Vertices.Transform(scale: tileSize - Vector2.One);

                    return(new Polygon(offset, vertices));
                }
            }

            return(null);
        }
Exemple #22
0
        public sealed override bool Overlaps(Shape shape)
        {
            if (base.Overlaps(shape))
            {
                var region = shape.Bounds
                             .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                foreach (var location in PlotRegion(region))
                {
                    var tile     = GetTileShape(location);
                    var overlaps = tile?.Overlaps(shape) ?? false;
                    if (overlaps)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool Overlaps(Shape shape, T attributes)
        {
            if (IsCollidable && shape != null)
            {
                var region = shape.Bounds
                             .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                foreach (var location in PlotRegion(region))
                {
                    var tile     = GetTileShape(location);
                    var overlaps = tile?.Overlaps(shape) ?? false;
                    if (overlaps && HasTags(location, attributes))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #24
0
        public bool Overlaps(Collider collider, T attributes, out CollisionResult result)
        {
            result = new CollisionResult(this);

            var canCollide = collider != null &&
                             collider != this &&
                             IsCollidable &&
                             collider.IsCollidable;

            if (canCollide)
            {
                if (collider is ShapeCollider)
                {
                    var collide = false;
                    var shape   = (collider as ShapeCollider).Shape;
                    var region  = shape.Bounds
                                  .ToGrid(TileSize.ToVector2(), AbsolutePosition);

                    foreach (var location in PlotRegion(region))
                    {
                        Manifold hit      = default;
                        var      tile     = GetTileShape(location);
                        var      overlaps = tile?.Overlaps(shape, out hit) ?? false;

                        if (overlaps && HasAttributes(location, attributes))
                        {
                            hit.Normal = -hit.Normal;
                            result.Add(hit);
                            collide = true;
                        }
                    }

                    if (collide)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #25
0
        public sealed override bool CastRay(Vector2 origin, Vector2 normal, float distance, out Raycast hit)
        {
            if (base.CastRay(origin, normal, distance, out hit))
            {
                var tileSize = TileSize.ToVector2();
                var gStart   = origin.ToGrid(tileSize, AbsolutePosition);
                var gEnd     = (origin + normal * distance).ToGrid(tileSize, AbsolutePosition);

                foreach (var location in PlotLine(gStart, gEnd))
                {
                    var tile        = GetTileShape(location);
                    var hitDetected = tile?.CastRay(origin, normal, distance, out hit) ?? false;
                    if (hitDetected)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #26
0
        public void Draw(float deltaTime)
        {
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    sprite.DrawFrame(new Vector2(x, y) * TileSize.ToVector2(), floortiles[data[x, y].Frame]);
                    switch (data[x, y].Type)
                    {
                    case TileType.Wall:
                        sprite.DrawFrame(new Vector2(x, y) * TileSize.ToVector2(), "Wall");
                        break;

                    case TileType.Movable:
                        sprite.DrawFrame(new Vector2(x, y) * TileSize.ToVector2(), "Movable");
                        break;

                    case TileType.Destructible:
                        sprite.DrawFrame(new Vector2(x, y) * TileSize.ToVector2(), "BreakableWall");
                        break;

                    case TileType.MoveDestructible:
                        sprite.DrawFrame(new Vector2(x, y) * TileSize.ToVector2(), "MoveBreakable");
                        break;
                    }

                    if (GameCore.Instance.DebugEnabled && data[x, y].Distance != -1)
                    {
                        GameCore.Instance.SpriteBatch.Draw(GameCore.Instance.Pixel, new Rectangle(x * DEFAULT_TILE_WIDTH, y * DEFAULT_TILE_HEIGHT, DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT), new Color(Color.Green, data[x, y].Distance / 30.0f));
                    }
                }
            }

            Diamonds.ForEach(d => d?.Draw());
            Player?.Draw();
            Tower?.Draw();
        }
 public void DefineTile(int index, Vector2[] vertices, Color?color = null)
 {
     DefineTile(index, vertices, TileSize.ToVector2(), color);
 }