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)); }
protected override void updateLocation(float elapsed) { if (!this.Hiding) { if (this.direction != Direction.None) { float moveDistance = (this.movementSpeed * elapsed); Vector2 newPos = this.activeSprite.Position; if (this.direction == Direction.Up) { newPos = new Vector2(this.activeSprite.Position.X, this.activeSprite.Position.Y - moveDistance); } else if (this.direction == Direction.Right) { newPos = new Vector2(this.activeSprite.Position.X + moveDistance, this.activeSprite.Position.Y); } else if (this.direction == Direction.Down) { newPos = new Vector2(this.activeSprite.Position.X, this.activeSprite.Position.Y + moveDistance); } else if (this.direction == Direction.Left) { newPos = new Vector2(this.activeSprite.Position.X - moveDistance, this.activeSprite.Position.Y); } // check if the new position would result in a collision, if not, assign the sprite the position if (!CollisionManager.getInstance().wallCollisionFound(Helper.getPersonBBox(newPos))) { this.activeSprite.Position = newPos; } } } // call the generic code before continuing base.updateLocation(elapsed); if (AIManager.getInstance().PlayerDetected) // if we aren't moving we still need to report where we are if we are detected // if we have been detected we need to tell the AI where we are { AIManager.getInstance().Board[base.Placement.index.Y, base.Placement.index.X] = BasePathFinder.TypeOfSpace.End; } }
public override void render(SpriteBatch spriteBatch) { // render the floor, treasure, than walls this.mapFloor.render(spriteBatch); this.treasureText.render(spriteBatch); this.treasure.render(spriteBatch); foreach (Treasure treasure in this.treasures) { treasure.render(spriteBatch); } this.mapWalls.render(spriteBatch); foreach (Dumpster dumpster in this.dumpsters) { dumpster.render(spriteBatch); } this.player.render(spriteBatch); foreach (Guard guard in this.guards) { guard.render(spriteBatch); } this.timer.render(spriteBatch); if (StateManager.getInstance().CurrentGameState == StateManager.GameState.Reset || StateManager.getInstance().CurrentGameState == StateManager.GameState.Waiting || (StateManager.getInstance().CurrentGameState == StateManager.GameState.InGameMenu && StateManager.getInstance().PreviousGameState == StateManager.GameState.Waiting)) { this.startButton.render(spriteBatch); } this.dustEmitter.render(spriteBatch); #if DEBUG if (this.showCD) { Color debugColour = Color.Green; DebugUtils.drawBoundingBox(spriteBatch, this.player.BoundingBox, debugColour, ResourceManager.getInstance().ButtonLineTexture); foreach (Guard guard in this.guards) { DebugUtils.drawBoundingBox(spriteBatch, guard.BoundingBox, debugColour, ResourceManager.getInstance().ButtonLineTexture); DebugUtils.drawBoundingSphere(spriteBatch, guard.Ring.BoundingSphere, debugColour, ResourceManager.getInstance().DebugRing); } foreach (BoundingBox box in CollisionManager.getInstance().MapBoundingBoxes) { DebugUtils.drawBoundingBox(spriteBatch, box, debugColour, ResourceManager.getInstance().ButtonLineTexture); } foreach (Treasure treasure in this.treasures) { DebugUtils.drawBoundingBox(spriteBatch, treasure.BoundingBox, debugColour, ResourceManager.getInstance().ButtonLineTexture); } foreach (Dumpster dumpster in this.dumpsters) { DebugUtils.drawBoundingBox(spriteBatch, dumpster.BoundingBox, debugColour, ResourceManager.getInstance().ButtonLineTexture); } } if (this.showWayPoints) { List <Point> wayPoints = AIManager.getInstance().WayPoints; foreach (Point wayPoint in wayPoints) { spriteBatch.Draw(ResourceManager.getInstance().DebugChip, new Placement(wayPoint).worldPosition, Color.Purple); } } if (this.showAI) { // draw where we cannot walk for (int y = 0; y < 18; y++) { for (int x = 0; x < 21; x++) { if (AIManager.getInstance().Board[y, x] == BasePathFinder.TypeOfSpace.Unwalkable) { spriteBatch.Draw(ResourceManager.getInstance().DebugChip, new Placement(new Point(x, y)).worldPosition, Color.Red); } } } } #endif }