Ejemplo n.º 1
0
        private static CollisionInfo GetCollisionInfo(RigidAABB rectangle, RigidCircle circle)
        {
            var closestPoint = GetClosestPoint(circle.Center, rectangle);
            var v            = closestPoint - circle.Center;

            return(Vector.ScalarProduct(v, v) <= circle.Radius * circle.Radius
                ? new CollisionInfo(circle.Radius - v.Length, -v.Normalize(), closestPoint)
                : null);
        }
Ejemplo n.º 2
0
        public Level(LevelInfo levelInfo)
        {
            this.levelInfo   = levelInfo;
            LevelSizeInTiles = levelInfo.LevelSizeInTiles;
            Name             = levelInfo.Name;

            Exit            = levelInfo.Exit;
            StaticShapes    = levelInfo.StaticShapes;
            RaytracingEdges = levelInfo.RaytracingEdges;
            NavMesh         = levelInfo.NavMesh;
            BotSpawnPoints  = levelInfo.BotSpawnPoints;
            BotPatrolPoints = levelInfo.BotPatrolPoints;

            SetDynamicEntities();
        }
Ejemplo n.º 3
0
 public LevelInfo(
     Size levelSizeInTiles, string name, RigidAABB exit, List <RigidShape> staticShapes,
     Bitmap levelMap, List <Edge> raytracingEdges, NavMesh navMesh, List <Vector> botSpawnPoints,
     int wavesAmount, EntityFactory.PlayerInfo playerInfo, List <EntityFactory.BotInfo> botsInfo,
     List <CollectableWeaponInfo> collectableWeaponsInfo, List <Vector> botPatrolPoints)
 {
     LevelSizeInTiles       = levelSizeInTiles;
     Name                   = name;
     Exit                   = exit;
     StaticShapes           = staticShapes;
     LevelMap               = levelMap;
     RaytracingEdges        = raytracingEdges;
     NavMesh                = navMesh;
     BotSpawnPoints         = botSpawnPoints;
     BotPatrolPoints        = botPatrolPoints;
     WavesAmount            = wavesAmount;
     PlayerInfo             = playerInfo;
     BotsInfo               = botsInfo;
     CollectableWeaponsInfo = collectableWeaponsInfo;
 }
Ejemplo n.º 4
0
        private static Vector GetClosestPoint(Vector point, RigidAABB rectangle)
        {
            var result = Vector.ZeroVector;

            for (var i = 0; i < 2; i++)
            {
                var v = point[i];
                if (v < rectangle.MinPoint[i])
                {
                    v = rectangle.MinPoint[i];
                }
                if (v > rectangle.MaxPoint[i])
                {
                    v = rectangle.MaxPoint[i];
                }
                result[i] = v;
            }

            return(result);
        }
 private static void DrawAABB(RigidAABB shape, Pen strokePen, Graphics g)
 {
     g.DrawRectangle(strokePen, shape.MinPoint.X, shape.MinPoint.Y, shape.Width, shape.Height);
 }
        private static void DrawAABB(RigidAABB shape, Vector cameraPosition, Pen strokePen, Graphics g)
        {
            var inCameraPosition = shape.MinPoint.ConvertFromWorldToCamera(cameraPosition);

            g.DrawRectangle(strokePen, inCameraPosition.X, inCameraPosition.Y, shape.Width, shape.Height);
        }
Ejemplo n.º 7
0
        public static LevelInfo LoadLevel(string sourcePath, Dictionary <string, TileSet> tileSets)
        {
            var separators = new[] { "\r\n", ",", "\n" };
            var doc        = new XmlDocument();

            doc.Load(sourcePath);
            var root = doc.DocumentElement;

            var levelSizeInTiles = new Size(
                int.Parse(root.GetAttribute("width")),
                int.Parse(root.GetAttribute("height")));

            var               name = root.GetAttribute("name");
            var               tilesInLayerAmount = 0;
            TileSet           tileSet            = null;
            var               layers             = new List <Layer>();
            List <RigidShape> staticShapes       = null;
            List <Edge>       raytracingEdges    = null;
            var               collectableWeapons = new List <CollectableWeaponInfo> {
                Capacity = 8
            };

            EntityFactory.PlayerInfo     playerInfo = null;
            List <EntityFactory.BotInfo> botsInfo   = null;
            List <Vector> botSpawnPoints            = null;
            List <Vector> botPatrolPoints           = null;
            int           wavesAmount = 0;
            RigidAABB     exit        = null;

            foreach (XmlNode node in root.ChildNodes)
            {
                switch (node.Name)
                {
                case "properties":
                {
                    foreach (XmlNode property in node.ChildNodes)
                    {
                        if (property.Name == "exit")
                        {
                            exit = LoadRigidAABB(property);
                        }
                        if (property.Name == "collectables")
                        {
                            foreach (XmlNode collectable in property.ChildNodes)
                            {
                                if (collectable.Name == "collectableWeapon")
                                {
                                    collectableWeapons.Add(LoadCollectableWeapon(collectable));
                                }
                            }
                        }

                        if (property.Name == "playerInfo")
                        {
                            playerInfo = LoadPlayerInfo(property);
                        }
                        if (property.Name == "bots")
                        {
                            botsInfo = loadBots(property);
                        }
                        if (property.Name == "botSpawnPoints")
                        {
                            wavesAmount    = int.Parse(property.Attributes.GetNamedItem("wavesAmount").Value);
                            botSpawnPoints = LoadPoints(property);
                        }

                        if (property.Name == "botPatrolPoints")
                        {
                            botPatrolPoints = LoadPoints(property);
                        }
                    }

                    break;
                }

                case "tileset":
                    tileSet            = tileSets[node.Attributes.GetNamedItem("source").Value];
                    tilesInLayerAmount = levelSizeInTiles.Width * levelSizeInTiles.Height;
                    break;

                case "layer":
                    layers.Add(LoadLayer(node, separators, tilesInLayerAmount));
                    break;

                case "objectgroup":
                {
                    var nodeContentName = node.Attributes.GetNamedItem("name").Value;
                    if (nodeContentName == "StaticShapes")
                    {
                        staticShapes = LoadStaticShapes(node);
                    }
                    if (nodeContentName == "RaytracingPolygons")
                    {
                        raytracingEdges = LoadRaytracingEdges(node);
                    }
                    break;
                }
                }
            }

            var navMesh  = new NavMesh(levelSizeInTiles, staticShapes);
            var levelMap = RenderPipeline.RenderLevelMap(layers, tileSet, tileSet.TileSize, levelSizeInTiles);

            return(new LevelInfo(
                       levelSizeInTiles, name, exit, staticShapes,
                       levelMap, raytracingEdges, navMesh, botSpawnPoints,
                       wavesAmount, playerInfo, botsInfo, collectableWeapons, botPatrolPoints));
        }
Ejemplo n.º 8
0
        private static float[] AreCollide(Vector objectPosition, Vector objectVelocity, RigidAABB rectangle)
        {
            var tMin = 0f;
            var tMax = float.PositiveInfinity;

            for (var i = 0; i < 2; i++)
            {
                if (Math.Abs(objectVelocity[i]) < 0.01 &&
                    (objectPosition[i] < rectangle.MinPoint[i] ||
                     objectPosition[i] > rectangle.MaxPoint[i]))
                {
                    return(null);
                }

                var ood = 1.0f / objectVelocity[i];
                var t1  = (rectangle.MinPoint[i] - objectPosition[i]) * ood;
                var t2  = (rectangle.MaxPoint[i] - objectPosition[i]) * ood;
                if (t1 > t2)
                {
                    var buf = t1;
                    t1 = t2;
                    t2 = buf;
                }

                tMin = Math.Max(tMin, t1);
                tMax = Math.Min(tMax, t2);
                if (tMin > tMax)
                {
                    return(null);
                }
            }

            return(new[] { tMin, tMax });
        }