private static void Init() { // Generate map CurrentMap = TestGameMap.CreateDungeonMap(100, 100); // Entity to test layering var testItem = new Entity(Color.White, Color.Transparent, 'i', (2, 2), 1, true, true); CurrentMap.AddEntity(testItem); Player = new Player(CurrentMap.WalkabilityView.RandomPosition(true)); CurrentMap.AddEntity(Player); MapConsole = new ScrollingConsole(width: CurrentMap.Width, height: CurrentMap.Height, font: SadConsole.Global.FontDefault, viewPort: new XnaRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), initialCells: CurrentMap.RenderingCellData); MapConsole.CenterViewPortOnPoint(Player.Position); CurrentMap.ConfigureAsRenderer(MapConsole); // Set our new console as the main object SadConsole processes, and set up keyboard input SadConsole.Global.CurrentScreen = MapConsole; SadConsole.Global.FocusedConsoles.Push(Player); }
//Generate a map and display it. Could just as easily pass it into public MapScreen(int mapWidth, int mapHeight, int viewportWidth, int viewportHeight) { Map = GenerateDungeon(mapWidth, mapHeight); // Get a console that's set up to render the map, and add it as a child of this container so it renders MapRenderer = Map.CreateRenderer(new XnaRect(0, 0, viewportWidth, viewportHeight), SadConsole.Global.FontDefault); Children.Add(MapRenderer); Map.ControlledGameObject.IsFocused = true; // Set player to receive input, since in this example the player handles movement // Set up to recalculate FOV and set camera position appropriately when the player moves. Also make sure we hook the new // Player if that object is reassigned. Map.ControlledGameObject.Moved += Player_Moved; Map.ControlledGameObjectChanged += ControlledGameObjectChanged; // Calculate initial FOV and center camera Map.CalculateFOV(Map.ControlledGameObject.Position, Map.ControlledGameObject.FOVRadius, Radius.SQUARE); MapRenderer.CenterViewPortOnPoint(Map.ControlledGameObject.Position); }
// MAP public void CreateMapWindow(int width, int height, string title) { MapWindow = new Window(width, height) { CanDrag = false, Title = title.Align(HorizontalAlignment.Center, width) }; MapConsole.ViewPort = new Rectangle(0, 0, width - 2, height - 2); MapConsole.Position = new Point(1, 1); Button inventoryButton = new Button(15, 3) { Position = new Point(0, MapWindow.Height - 3), Text = "Inventory" }; MapWindow.Add(inventoryButton); Button anatomyButton = new Button(15, 3) { Position = new Point(15, MapWindow.Height - 3), Text = "Anatomy" }; MapWindow.Add(anatomyButton); MapWindow.Children.Add(MapConsole); Children.Add(MapWindow); MapWindow.Show(); MapConsole.MouseMove += Console_MouseMove; MapConsole.MouseButtonClicked += Console_MouseClicked; MapConsole.CenterViewPortOnPoint(GameLoop.World.Player.Position); }
public void KeepCameraOnHero(Hero hero) { MapConsole.CenterViewPortOnPoint(hero.Position); }
// This centres the viewport camera on an actor. public void CenterOnActor(Actor actor) { MapConsole.CenterViewPortOnPoint(actor.Position); }
private void CenterOnObject(Mobile m) { mapCons.CenterViewPortOnPoint(m.Position); }
public void CenterOnActor(Entities.Actor actor) { // Centers the viewport/screen on the actor MapConsole.CenterViewPortOnPoint(actor.Position); }