예제 #1
0
        /**
         * Check if the given tile is a wall.
         * If it is, add it to the given graph reference.
         */
        private static void ComputeWall(String name, int x, int y, ref Graph.Graph graph)
        {
            // Prepare the regex matcher.
            RegEx rgx = new RegEx();

            rgx.Compile("^Wall([SOW])_([TLBR]{1})(Door)?.*$");

            // Get and check the result of the regex.
            RegExMatch result = rgx.Search(name);

            if (result != null)
            {
                // Get the type of wall.
                Tile.WallType type = Tile.WallType.WOOD;
                switch (result.GetString(1))
                {
                case "S": type = Tile.WallType.STONE;    break;

                case "O": type = Tile.WallType.OBSIDIAN; break;

                case "W": type = Tile.WallType.WOOD;     break;
                }

                Tile.Orientation dir = Tile.Orientation.OTHER;
                switch (result.GetString(2))
                {
                case "T": dir = Tile.Orientation.TOP; break;

                case "B": dir = Tile.Orientation.BOTTOM; break;

                case "L": dir = Tile.Orientation.LEFT; break;

                case "R": dir = Tile.Orientation.RIGHT; break;
                }



                // Check if the given wall is a door.
                bool bIsDoor = result.GetString(3).Equals("Door");

                // Create a new Wall instance.
                Tile.Wall wall = new Tile.Wall(type, bIsDoor, dir);
                wall.Position = new Vector2(x, y);

                // Add it to the graph object.
                graph.AddWall(wall, x, y);
            }
        }
예제 #2
0
        /**
         * Check if the given tile is a vertex.
         * If it is, add it to the given graph reference.
         */
        private static void ComputeVertex(String name, int x, int y, ref Graph.Graph graph)
        {
            // Prepare the regex matcher.
            RegEx rgx = new RegEx();

            rgx.Compile("^Wall._[TBLR]{2}$|^(Tower)");

            // Get and check the result of the regex.
            RegExMatch result = rgx.Search(name);

            if (result != null)
            {
                // Check wether a tower was selected.
                bool bIsTower = result.GetString(1).Equals("Tower");

                // Create a new Vertex instance.
                Graph.Vertex vtx = new Graph.Vertex(x, y, graph.GetWallAt(new Vector2(x, y)));

                // Add the instance to the graph.
                graph.AddVertex(vtx);
            }
        }
예제 #3
0
        /**
         * Computes the cost of a given tile.
         */
        private static void ComputeCost(int x, int y, TileMap map)
        {
            // Get the tile id.
            int tileID = map.GetCell(x, y);

            if (tileID > -1)
            {
                // Get the name of the tile.
                String tileName = map.TileSet.TileGetName(tileID);

                // Prepare the weight counter.
                float weight = 1;

                // Check the name of the tile.
                RegEx rgx = new RegEx();
                rgx.Compile("(Road|Wall|Tower|House|Well|Tree|Objective|Barrier)");
                RegExMatch result = rgx.Search(tileName);
                if (result != null)
                {
                    switch (result.GetString(1))
                    {
                    case "Wall":
                    case "Tower":
                    case "Well":
                    case "Tree":
                    case "House":
                    case "Barrier":
                    case "Objective":
                        weight = float.PositiveInfinity;
                        break;
                    }
                }

                // Add the weight.
                Pathfinder.AStar.AddCost(x, y, weight);
            }
        }
예제 #4
0
        /**
         * Computes the resource on the given tile.
         */
        private static void ComputeResource(int x, int y, TileMap map, ref Graph.Graph graph)
        {
            // Get the face of the given resource.
            Graph.Face face = graph.GetFaceFromPoint(new Vector2(x, y));
            if (face != null)
            {
                // Prepare the regex of the tile name.
                RegEx rgx = new RegEx();
                rgx.Compile(".*(House|Well|Grass|Cow|Start|Objective).*");

                // Check the result.
                String     tileName = map.TileSet.TileGetName(map.GetCell(x, y));
                RegExMatch result   = rgx.Search(tileName);
                if (result != null)
                {
                    switch (result.GetString(1))
                    {
                    case "House":
                        face.zone.addHouse();
                        break;

                    case "Well":
                        face.zone.AddWell();
                        break;

                    case "Grass":
                        // Check the value of the grass.
                        rgx.Compile("([0-9])");
                        result = rgx.Search(tileName);
                        if (result != null)
                        {
                            face.zone.AddGrass(new Vector2(x, y), result.GetString(1).ToInt());
                        }
                        break;

                    case "Objective":
                        face.zone.IsObjective = true;
                        break;

                    case "Cow":
                        // Add a cow to the zone.
                        Tile.Cow cow = Tile.Cow.Instance();
                        cow.Position = new Vector2(x, y);
                        World.Instance.AddChild(cow);
                        face.zone.AddCow(cow);

                        // Remove the cow.
                        map.SetCell(x, y, -1);
                        break;

                    case "Start":
                        // Take the zone.
                        face.zone.TakeOver();

                        // Remove the start point.
                        map.SetCell(x, y, -1);
                        break;
                    }
                }
            }
        }
예제 #5
0
    public override void _Process(float delta)
    {
        Offset += speed * delta;
        if (UnitOffset == 1 && GetParent().Name == "MainPath")
        {
            EmitSignal(nameof(endMainPath), this);
        }
        else if (UnitOffset == 1 && GetParent().Name == "MainPathLeft")
        {
            EmitSignal(nameof(endMainPathLeft), this);
        }
        else if (UnitOffset == 1 && GetParent().Name == "MainPathRight")
        {
            EmitSignal(nameof(endMainPathRight), this);
        }

        if (global.setCount == 2)
        {
            speed = 180f;
        }
        else if (global.setCount >= 3)
        {
            speed = 200f;
        }

        if (global.mode == "Easy")
        {
            regex.Compile("@?Easy@?\\d*");
            resPath = regex.Search(GetPath());
            newPath = resPath.GetString();
            if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/EndPosition_y").GlobalPosition.y&& GetParent().Name == "LeftPath")
            {
                EmitSignal(nameof(reachEnd), "Left", colors, this, newPath);
            }
            else if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/EndPosition_y").GlobalPosition.y&& GetParent().Name == "RightPath")
            {
                EmitSignal(nameof(reachEnd), "Right", colors, this, newPath);
            }
        }
        else if (global.mode == "Hard")
        {
            regex.Compile("@?Hard@?\\d*");
            resPath = regex.Search(GetPath());
            newPath = resPath.GetString();
            if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/LeftEndPosition").GlobalPosition.y&& GetParent().Name == "LeftPath")
            {
                EmitSignal(nameof(reachEnd), "Left", colors, this, newPath);
            }
            else if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/MidEndPosition").GlobalPosition.y&& (GetParent().Name == "MiddlePath1" || GetParent().Name == "MiddlePath2"))
            {
                EmitSignal(nameof(reachEnd), "Middle", colors, this, newPath);
            }
            else if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/RightEndPosition").GlobalPosition.y&& GetParent().Name == "RightPath")
            {
                EmitSignal(nameof(reachEnd), "Right", colors, this, newPath);
            }
        }

        if (Modulate.a < 0.3f)
        {
            QueueFree();
        }
    }