public static MovementPath AStar(Point start, Point end, Stage stage = null)
        {
            MovementPath newPath = new MovementPath(null);
            if (stage == null)
            {
                stage = Stage.CurrentStage;
            }

            // setup grid with walls
            //MyPathNode[,] grid = new MyPathNode[(int)stage.Width, (int)stage.Height];
            MyPathNode[][] grid = new MyPathNode[(int)stage.Width][];

            for (int x = 0; x < (int)stage.Width; x++)
            {
                grid[x] = new MyPathNode[(int) stage.Height];
                for (int y = 0; y < (int)stage.Height; y++)
                {

                    grid[x][y] = new MyPathNode()
                    {
                        IsWall = stage.GetTileAt(x, y).GetWalkable(),
                        X = x,
                        Y = y,
                    };
                }
            }

            SpatialAStar<MyPathNode, Object> aStar = new SpatialAStar<MyPathNode, Object>(grid);

            LinkedList<MyPathNode> path = aStar.Search(new Point(0, 0),
               new Point(stage.Width - 2, stage.Height - 2), null);
            return null;
        }
Exemple #2
0
        //sets up all of the variables for the stage
        public Stage(string stageName, StageType stageType)
        {
            this.SetName(stageName);
            this.StageType = stageType;
            this.AmbientLightLevel = Color.White;

            if (CurrentStage == null)
            {
                CurrentStage = this;
            }
        }
        public static List<LightSource> GetLocalLightSources(double xPos, double yPos, Stage stage, View view)
        {
            List<LightSource> returnLights = new List<LightSource>();
            foreach (LightSource light in stage.GetLights(view))
            {
                //if the light is brighter than, or as bright as it is far away
                if (light.GetPosition().Distance(new Point(xPos, yPos)) <= light.range)
                {
                    //it is a "local" light source, add it to the return list
                    returnLights.Add(light);
                }
            }

            return returnLights;
        }
        public static GuiLayer AsCollisionMap(Stage sourceStage)
        {
            Debug.log("Rendering collision map...");

            //So we need to reposition this so that it isn't at 0,0,
            //but rather at the position of the game board
            //technically, I think the view should be at that position, and this should be 0,0 within the view...

            //the size should be equal to the stage or stage's gui layer
            ///!/// so, fixing the size of this. Not an ideal situation. Wll have to address.
            GuiLayer collisionLayer = View.GetMainView().AddLayer("CollisionLayer", DOM_Renderer.GetRenderer().As<DOM_Renderer>().BoardArea());
            //GuiLayer collisionLayer = View.GetMainView().AddLayer("CollisionLayer", View.GetMainView().GetViewArea());
            //put the layer on top /  make it visible
            //collisionLayer.GetRenderElement().Style.ZIndex = 10;

            //get the size of the tiles in the stage so that we can offset the collision overlay
            Dimension TileSize = Stage.CurrentStage.GetTileSize();

            //loop through each of the tiles, and draw whether or not it collides to the layer
            foreach (Tile tile in sourceStage.GetVisibleTiles(collisionLayer.GetAttachedView()))
            {
                GuiElement gelm = collisionLayer.AddGUIElement("");
                //gelm.InitialRender();
                gelm.SetPosition(
                    (int)Helpah.Round(tile.GetPosition().x * TileSize.width),
                    (int)Helpah.Round(tile.GetPosition().y * TileSize.height));
                // Set the size to 0, 0 so that the renderer ignores the element.
                // The CSS stylesheet will give it size.
                gelm.SetSize(0, 0);
                gelm.AddStyle("collisionBlock");
                //gelm.GetRenderElement().ClassName = "collisionBlock";

                if (tile.GetBuildable())
                {
                    gelm.AddStyle("buildable");
                    //gelm.GetRenderElement().ClassName += " buildable";
                }
            }

            return collisionLayer;
        }
Exemple #5
0
        public Stage(string stageName, StageType stageType, Dimension stageSize)
        {
            this.SetName(stageName);
            this.StageType = stageType;
            this.AmbientLightLevel = Color.White;

            if (CurrentStage == null)
            {
                CurrentStage = this;
            }

            this.size = stageSize;

            //return;

            // Create a set of empty tiles.
            for (double w = 0; w < this.size.width; w++)
            {
                for (double h = 0; h < this.size.height; h++)
                {
                    this.AddTile("", true, true, new Point(w, h));
                }
            }
        }
        // Resolve the map's path legs for a given dimension
        private static void resolvePathLegs(Stage stage, bool vertical, ref Dictionary<short, List<PathLeg>> returnVals)
        {
            short col = 0;
            short row = 0;
            short legStart = -1;
            short legEnd = -1;

            if (vertical)
            {
                // Loop through all of the rows
                while (col < stage.Width)
                {
                    returnVals[col] = new List<PathLeg>();

                    // Loop through all of the columns in this row ...
                    while (row < stage.Height)
                    {
                        // If the tile is passable by entities.
                        if (stage.GetTileAt(col, row).GetWalkable())
                        {
                            // If we're in a leg, extend it
                            if (legStart != -1)
                            {
                                legEnd = row;
                            }
                            // Start a new leg
                            else
                            {
                                legStart = row;
                            }
                        }
                        else
                        {
                            // If we had a leg going, store it.
                            if (legStart != -1 && legEnd != -1)
                            {
                                returnVals[col].Add(new PathLeg(new Point(col, legStart), new Point(col, legEnd), vertical));
                            }

                            legStart = -1;
                            legEnd = -1;
                        }

                        row++;
                    }

                    row = 0;
                    col++;
                }
            }
            else
            {
                // Loop through all of the rows
                while (row < stage.Height)
                {
                    returnVals[row] = new List<PathLeg>();

                    // Loop through all of the columns in this row ...
                    while (col < stage.Width)
                    {
                        // If the tile is passable by entities.
                        if (stage.GetTileAt(col, row).GetWalkable())
                        {
                            // If we're in a leg, extend it
                            if (legStart != -1)
                            {
                                legEnd = col;
                            }
                            // Start a new leg
                            else
                            {
                                legStart = col;
                            }
                        }
                        else
                        {
                            // If we had a leg going, store it.
                            if (legStart != -1 && legEnd != -1)
                            {
                                returnVals[row].Add(new PathLeg(new Point(legStart, row), new Point(legEnd, row), vertical));
                            }

                            legStart = -1;
                            legEnd = -1;
                        }

                        col++;
                    }

                    col = 0;
                    row++;
                }
            }
        }
        // Resolve a single (horizontal or vertical) leg of a path between two points.
        private static List<Point> resolveLeg(Point start, Point end, Stage stage, bool vertical)
        {
            List<Point> resultPath = new List<Point>();
            Point currentPoint = start;

            resultPath.Add(start);

            if (vertical)
            {
                // Positive movement
                if (end.y > start.y)
                {
                    while (stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y + 1) != null &&
                        stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y + 1).GetWalkable())
                    {
                        currentPoint = new Point(currentPoint.x, currentPoint.y + 1);
                        resultPath.Add(currentPoint);
                    }
                }
                // Negative movement
                else
                {
                    while (stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y - 1) != null &&
                        stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y - 1).GetWalkable())
                    {
                        currentPoint = new Point(currentPoint.x, currentPoint.y - 1);
                        resultPath.Add(currentPoint);
                    }
                }
            }
            // Horizontal
            else
            {
                // Positive movement
                if (end.x > start.x)
                {
                    while (stage.GetTileAt((int)currentPoint.x + 1, (int)currentPoint.y) != null &&
                        stage.GetTileAt((int)currentPoint.x + 1, (int)currentPoint.y).GetWalkable())
                    {
                        currentPoint = new Point(currentPoint.x + 1, currentPoint.y);
                        resultPath.Add(currentPoint);
                    }
                }
                // Negative movement
                else
                {
                    while (stage.GetTileAt((int)currentPoint.x - 1, (int)currentPoint.y) != null &&
                        stage.GetTileAt((int)currentPoint.x - 1, (int)currentPoint.y).GetWalkable())
                    {
                        currentPoint = new Point(currentPoint.x - 1, currentPoint.y);
                        resultPath.Add(currentPoint);
                    }
                }
            }

            // Check the point at the end of the path to make sure it's accessible from two directions
            // Remove points from the end until the last point is accessible from two directions.

            return resultPath;
        }
        // Get the longest passage connected to a point
        private static MovementDirection longestPassage(Point point, Stage stage)
        {
            short longestPassage = 0;
            MovementDirection longestDirection = MovementDirection.None;
            Point currentPoint = point;
            short passageLength = 0;

            // Check Right
            while (stage.GetTileAt((int) currentPoint.x + 1, (int) currentPoint.y) != null &&
                stage.GetTileAt((int) currentPoint.x + 1, (int) currentPoint.y).GetWalkable())
            {
                currentPoint = new Point(currentPoint.x + 1, currentPoint.y);
                passageLength++;
            }
            if (passageLength > longestPassage)
            {
                longestDirection = MovementDirection.Right;
            }
            passageLength = 0;
            currentPoint = point;

            // Check Left
            while (stage.GetTileAt((int)currentPoint.x - 1, (int)currentPoint.y) != null &&
                stage.GetTileAt((int)currentPoint.x - 1, (int)currentPoint.y).GetWalkable())
            {
                currentPoint = new Point(currentPoint.x - 1, currentPoint.y);
                passageLength++;
            }
            if (passageLength > longestPassage)
            {
                longestDirection = MovementDirection.Left;
            }
            passageLength = 0;
            currentPoint = point;

            // Check Up
            while (stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y + 1) != null &&
                stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y + 1).GetWalkable())
            {
                currentPoint = new Point(currentPoint.x, currentPoint.y + 1);
                passageLength++;
            }
            if (passageLength > longestPassage)
            {
                longestDirection = MovementDirection.Up;
            }
            passageLength = 0;
            currentPoint = point;

            // Check Down
            while (stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y - 1) != null &&
                stage.GetTileAt((int)currentPoint.x, (int)currentPoint.y - 1).GetWalkable())
            {
                currentPoint = new Point(currentPoint.x, currentPoint.y - 1);
                passageLength++;
            }
            if (passageLength > longestPassage)
            {
                longestDirection = MovementDirection.Down;
            }

            return longestDirection;
        }
        //resolve the shortest path between two given points
        public static MovementPath ResolvePath2(Point start, Point end, Stage stage = null)
        {
            MovementPath newPath = new MovementPath(null);
            if (stage == null)
            {
                stage = Stage.CurrentStage;
            }
            // The last point added
            Point currentPoint = start;

            //need better pathfinding and collision detection later

            // Add the beginning
            newPath.AddPoint(start);

            // List all of the avenues we've explored
            List<PathLeg> pathLegs = new List<PathLeg>();

            // Start from the start and explore the legs
            // March repeatedly through each path, until reaching the exit or a dead end

            //if there's horizontal distance to cover between the points, cover it first
            while(currentPoint.x != end.x)
            {
                // If we can move to the next tile, do so
                if (stage.GetTileAt((int)currentPoint.x + 1, (int)currentPoint.y).GetWalkable())
                {
                    currentPoint = new Point(currentPoint.x + 1, currentPoint.y);
                    newPath.AddPoint(currentPoint);
                }
                // If not, switch to vertical differencing ...
                else
                {

                }
            }

            return newPath;
        }
        //resolve the shortest path between two given points
        public static MovementPath ResolvePath(Point start, Point end, Stage stage = null)
        {
            MovementPath newPath = new MovementPath(null);
            if (stage == null)
            {
                stage = Stage.CurrentStage;
            }
            // The last point added
            Point currentPoint = start;

            // A list of all path legs on the horizontal plane of the map, indexed by map row.
            Dictionary<short, List<PathLeg>> horizontalPathLegs = new Dictionary<short, List<PathLeg>>();
            // A list of all path legs on the vertical plane of the map, indexed by map column.
            Dictionary<short, List<PathLeg>> verticalPathLegs = new Dictionary<short, List<PathLeg>>();
            // Resolve the legs in the map
            MovementPath.resolvePathLegs(stage, false, ref horizontalPathLegs);
            MovementPath.resolvePathLegs(stage, true, ref verticalPathLegs);

            // Prioritize the side with more long paths (horizontal or vertical)

            // Determine which paths to attempt to join together, and calculate the cost of traveling between those paths

            // If the travel cost is significant (exceeds the difference with the next-shortest path), try the next path

            return newPath;
        }
Exemple #11
0
        //depending on available stage types, maybe this function should infer stagetype from game context?
        public static Stage CreateStage(string stageName, StageType stageType, Dimension stageSize = null)
        {
            Stage newStage;
            if (stageSize != null)
            {
                newStage = new Stage(stageName, stageType, stageSize);
            }
            else
            {
                newStage = new Stage(stageName, stageType);
            }

            //if there is a main view with no stage, make this the attached stage
            if (View.GetMainView() != null && View.GetMainView().GetAttachedStage() == null)
            {
                View.GetMainView().AttachStage(newStage);
            }

            gameStages.Add(newStage);

            return newStage;
        }
Exemple #12
0
        public static void LoadStage(Stage stageToLoad)
        {
            //unload the current stage
            if (Stage.CurrentStage != null)
            {
                Game.UnloadStage();
            }

            //load the new stage
            Stage.CurrentStage = stageToLoad;
            View.GetMainView().AttachStage(stageToLoad);
        }
Exemple #13
0
 public void SetParentStage(Stage newStage)
 {
     this.parentStage = newStage;
 }
Exemple #14
0
 public void AttachStage(Stage newStage)
 {
     this.stgAttached = newStage;
 }
Exemple #15
0
        public void Activate()
        {
            this.active = true;

            if (this.stgAttached == null && Stage.CurrentStage != null)
            {
                this.stgAttached = Stage.CurrentStage;
            }

            if (View.activeViews.Contains(this) == false)
            {
                View.activeViews.Add(this);
            }
        }