Esempio n. 1
0
        private List <Point> findPath(Point start, Point end)
        {
            //List<Point> path = null;
            List <Point> path = new List <Point>();
            int          maxY = this.Board.GetUpperBound(0);
            int          maxX = this.Board.GetUpperBound(1);

            if (end.X >= 0 && end.Y >= 0 && end.X < maxX && end.Y < maxY)
            {
                // backup the board first
                BasePathFinder.TypeOfSpace previousStartSpot = this.Board[start.Y, start.X];
                BasePathFinder.TypeOfSpace previousEndSpot   = this.Board[end.Y, end.X];
                this.Board[start.Y, start.X] = BasePathFinder.TypeOfSpace.Start;
                this.Board[end.Y, end.X]     = BasePathFinder.TypeOfSpace.End;
                this.pathFinder.findPath(this.Board);

                path = this.pathFinder.Path;
                // reset our pieces back
                this.Board[start.Y, start.X] = previousStartSpot;
                this.Board[end.Y, end.X]     = previousEndSpot;
                if (this.Board[end.Y, end.X] == BasePathFinder.TypeOfSpace.Unwalkable)
                {
                    if (this.pathFinder.LowestCost != null)
                    {
                        path = findPath(start, this.pathFinder.LowestCost.Position);
                    }
                }
            }
            return(path);
        }
        private static MapWalls loadMapWalls(Color wallColour, LoadResult loadResult)
        {
            int height    = loadResult.Height;
            int width     = loadResult.Width;
            int wallLayer = 1;

            MapTile[,] mapWallTiles = loadResult.Layers[wallLayer].Tiles;
            // load visual aspect of the walls
            Tile[,] wallTiles = GWNorthEngine.Tools.TilePlacer.MapLoader.initTiles <Tile>(mapWallTiles, delegate(MapTile tile) {
                if (Tile.COLOUR_OVERRIDE_TILES.Contains <string>(tile.Texture.Name))
                {
                    return(new Tile(tile.Texture, tile.Index, Color.White, tile.TileValue));
                }
                else
                {
                    return(new Tile(tile.Texture, tile.Index, wallColour, tile.TileValue));
                }
            });

            // load the AI for the map
            BasePathFinder.TypeOfSpace[,] aiSpaceTypes = new BasePathFinder.TypeOfSpace[height, width];
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // override so the AI can walk the outter wall
                    if (wallTiles[y, x] != null && mapAsUnwalkable(wallTiles[y, x].Texture.Name, y, x, height, width))
                    {
                        aiSpaceTypes[y, x] = Translator.translateTileValueToAStarType(wallTiles[y, x].TileValue);
                    }
                    else
                    {
                        aiSpaceTypes[y, x] = BasePathFinder.TypeOfSpace.Walkable;
                    }
                }
            }

            AIManager.getInstance().init(height, width);
            AIManager.getInstance().Board = aiSpaceTypes;

            // generate the collision detection
            Placement          tilesPlacement;
            List <BoundingBox> tileBBoxes = new List <BoundingBox>();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (mapWallTiles[y, x] != null)
                    {
                        tilesPlacement = new Placement(new Point(x, y));
                        tileBBoxes.AddRange(CollisionDetectionGenerator.generateBoundingBoxesForTexture(mapWallTiles[tilesPlacement.index.Y, tilesPlacement.index.X].Texture, tilesPlacement));
                    }
                }
            }
            CollisionManager.getInstance().MapBoundingBoxes = tileBBoxes;
            return(new MapWalls(wallTiles, wallColour));
        }
Esempio n. 3
0
        protected virtual void updateLocation(float elapsed)
        {
            // update our placement and bounding box
            this.Placement   = new Placement(Placement.getIndex(this.activeSprite.Position));
            this.BoundingBox = Helper.getPersonBBox(this.activeSprite.Position);

            if (this.previousPlacement.index != this.Placement.index)
            {
                AIManager.getInstance().Board[this.previousPlacement.index.Y, this.previousPlacement.index.X] = this.previousTypeOfSpace;
                this.previousTypeOfSpace = AIManager.getInstance().Board[this.Placement.index.Y, this.Placement.index.X];
            }
        }
Esempio n. 4
0
        private List <Point> findPath(Point start, Point end)
        {
            // backup the board first
            BasePathFinder.TypeOfSpace previousStartSpot = this.Board[start.Y, start.X];
            BasePathFinder.TypeOfSpace previousEndSpot   = this.Board[end.Y, end.X];
            this.Board[start.Y, start.X] = BasePathFinder.TypeOfSpace.Start;
            this.Board[end.Y, end.X]     = BasePathFinder.TypeOfSpace.End;
            List <Point> path = new List <Point>();

            this.pathFinder.findPath(this.Board);
            path = this.pathFinder.Path;
            // reset our pieces back
            this.Board[start.Y, start.X] = previousStartSpot;
            this.Board[end.Y, end.X]     = previousEndSpot;
            return(path);
        }
Esempio n. 5
0
        /// <summary>
        /// Determines the cost of a tile based on its type
        /// </summary>
        /// <param name="space"></param>
        /// <returns></returns>
        public virtual int getCost(BasePathFinder.TypeOfSpace space)
        {
            int cost = StandardCost;

            if (space == BasePathFinder.TypeOfSpace.VariableTerrainLowCost)
            {
                cost = VariableTerrainLowCost;
            }
            else if (space == BasePathFinder.TypeOfSpace.VariableTerrainMediumCost)
            {
                cost = VariableTerrainMediumCost;
            }
            else if (space == BasePathFinder.TypeOfSpace.VariableTerrainHighCost)
            {
                cost = VariableTerrainHighCost;
            }
            return(cost);
        }
Esempio n. 6
0
        public static void loadMap(ContentManager content, string mapName, out Model.Map map)
        {
            LoadResult loadResult        = loader.load(content, mapName);
            int        height            = loadResult.Height;
            int        width             = loadResult.Width;
            int        wallLayerLocation = 0;

            // generate walls
            Layer wallLayer = loadResult.Layers[wallLayerLocation];

            MapTile[,] layerTiles = wallLayer.Tiles;
            List <Wall> walls = new List <Wall>();

            BasePathFinder.TypeOfSpace[,] aiSpaceTypes = new BasePathFinder.TypeOfSpace[height, width];
            foreach (var mapTile in layerTiles)
            {
                if (mapTile != null)
                {
                    Vector2     newPosition = Vector2.Add(mapTile.WorldPosition, new Vector2(Constants.TILE_SIZE) / 2);
                    BoundingBox boundingBox = CollisionGenerationUtils.generateBoundingBoxesForTexture(mapTile.Texture, newPosition);
                    walls.Add(new Wall(content, newPosition, mapTile.Texture, boundingBox));
                    aiSpaceTypes[mapTile.Index.Y, mapTile.Index.X] = BasePathFinder.TypeOfSpace.Unwalkable;
                }
            }

            // load the AI for the map
            BasePathFinder.TypeOfSpace defaultSpaceType = (BasePathFinder.TypeOfSpace)Activator.CreateInstance(typeof(BasePathFinder.TypeOfSpace));
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (aiSpaceTypes[y, x] == defaultSpaceType)
                    {
                        aiSpaceTypes[y, x] = BasePathFinder.TypeOfSpace.Walkable;
                    }
                }
            }

            AIManager.getInstance().init(height, width);
            AIManager.getInstance().Board = aiSpaceTypes;

            map = new Model.Map(walls);
        }
Esempio n. 7
0
        public Person(ContentManager content, string fileStartsWith, Placement startingLocation, float movementSpeed)
        {
            BaseAnimationManagerParams animationParams = new BaseAnimationManagerParams();

            animationParams.AnimationState  = AnimationState.PlayForward;
            animationParams.FrameRate       = FRAME_RATE;
            animationParams.TotalFrameCount = 4;
            BaseAnimated2DSpriteParams spriteParams = new Animated2DSpriteLoadSingleRowBasedOnTexture();

            spriteParams.Origin          = new Vector2(ResourceManager.TILE_SIZE / 2, ResourceManager.TILE_SIZE / 2);
            spriteParams.Texture         = LoadingUtils.load <Texture2D>(content, fileStartsWith + "Right");
            spriteParams.AnimationParams = animationParams;;
            // we actually want his feet in the middle, not his chest which is where the origin is
            spriteParams.Position     = new Vector2(startingLocation.worldPosition.X + spriteParams.Origin.X, startingLocation.worldPosition.Y);
            this.rightSprite          = new Animated2DSprite(spriteParams);
            spriteParams.SpriteEffect = SpriteEffects.FlipHorizontally;
            this.leftSprite           = new Animated2DSprite(spriteParams);
            this.Placement            = startingLocation;
            this.direction            = Direction.None;
            this.movementSpeed        = movementSpeed;
            this.activeSprite         = this.rightSprite;
            this.BoundingBox          = Helper.getPersonBBox(this.activeSprite.Position);
            this.previousTypeOfSpace  = AIManager.getInstance().Board[this.Placement.index.Y, this.Placement.index.X];
        }