public void Create_MapCreatedWithRandomRoomsMapCreationStrategy_ExpectedMap() { int expectedWidth = 17; int expectedHeight = 10; IRandom random = new DotNetRandom(13); IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(expectedWidth, expectedHeight, 30, 5, 3, random); string expectedMapRepresentation = @"################# ################# ##...#######...## ##.............## ###.###....#...## ###...##.#####.## ###...##...###..# ####............# ##############..# #################"; IMap actualMap = Map.Create(mapCreationStrategy); Trace.Write(actualMap); Assert.AreEqual(expectedWidth, actualMap.Width); Assert.AreEqual(expectedHeight, actualMap.Height); Assert.AreEqual(RemoveWhiteSpace(expectedMapRepresentation), RemoveWhiteSpace(actualMap.ToString())); }
private Map CreateMap(int mapWidth, int mapHeight, int roomCount, int roomWidth, int roomHeight) { IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(mapWidth, mapHeight, roomCount, roomWidth, roomHeight); Map map = Map.Create(mapCreationStrategy); return(map); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(50, 30, 100, 7, 3); _map = Map.Create(mapCreationStrategy); base.Initialize(); }
public MapConsole(int width, int height) : base(width, height) { // Create the map IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(width, height, 100, 15, 4); map = Map.Create(mapCreationStrategy); mapData = new SadConsole.CellAppearance[width, height]; foreach (var cell in map.GetAllCells()) { if (cell.IsWalkable) { // Our local information about each map square mapData[cell.X, cell.Y] = new MapObjects.Floor(); // Copy the appearance we've defined for Floor or Wall or whatever, to the actual console data that is rendered mapData[cell.X, cell.Y].CopyAppearanceTo(this[cell.X, cell.Y]); } else { mapData[cell.X, cell.Y] = new MapObjects.Wall(); mapData[cell.X, cell.Y].CopyAppearanceTo(this[cell.X, cell.Y]); } } // Create map effects explored = new SadConsole.Effects.Recolor(); explored.Background = Color.White * 0.3f; explored.Foreground = Color.White * 0.3f; explored.Update(10d); // Trickery to force the fade to complete to the destination color. // Entities entities = new List <SadConsole.Game.GameObject>(); // Create the player player = new Entities.Player(); var tempCell = GetRandomEmptyCell(); player.Position = new Microsoft.Xna.Framework.Point(tempCell.X, tempCell.Y); player.RenderOffset = this.Position; entities.Add(player); // Create a hound GenerateHound(); GenerateHound(); GenerateHound(); // Initial view UpdatePlayerView(); // Keyboard setup SadConsole.Engine.Keyboard.RepeatDelay = 0.07f; SadConsole.Engine.Keyboard.InitialRepeatDelay = 0.1f; }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(50, 30, 100, 7, 3); _map = Map.Create(mapCreationStrategy); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Global.Camera.ViewportWidth = graphics.GraphicsDevice.Viewport.Width; Global.Camera.ViewportHeight = graphics.GraphicsDevice.Viewport.Height; IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(Global.MapWidth, Global.MapHeight, 100, 7, 3); _map = Map.Create(mapCreationStrategy); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IMapCreationStrategy <Map> _mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(Statics.MapWidth, Statics.MapHeight, 100, 7, 3); map = Map.Create(_mapCreationStrategy); Statics.GameState = GameStates.PlayerTurn; Statics.Camera.ViewportHeight = graphics.GraphicsDevice.Viewport.Height; Statics.Camera.ViewportWidth = graphics.GraphicsDevice.Viewport.Width; Window.AllowUserResizing = true; base.Initialize(); }
public MapConsole(int width, int height) : base(width, height) { // Create the map IMapCreationStrategy<Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy<Map>(width, height, 100, 15, 4); map = Map.Create(mapCreationStrategy); mapData = new SadConsole.CellAppearance[width, height]; foreach (var cell in map.GetAllCells()) { if (cell.IsWalkable) { // Our local information about each map square mapData[cell.X, cell.Y] = new MapObjects.Floor(); // Copy the appearance we've defined for Floor or Wall or whatever, to the actual console data that is rendered mapData[cell.X, cell.Y].CopyAppearanceTo(this[cell.X, cell.Y]); } else { mapData[cell.X, cell.Y] = new MapObjects.Wall(); mapData[cell.X, cell.Y].CopyAppearanceTo(this[cell.X, cell.Y]); } } // Create map effects explored = new SadConsole.Effects.Recolor(); explored.Background = Color.White * 0.3f; explored.Foreground = Color.White * 0.3f; explored.Update(10d); // Trickery to force the fade to complete to the destination color. // Entities entities = new List<SadConsole.Game.GameObject>(); // Create the player player = new Entities.Player(); var tempCell = GetRandomEmptyCell(); player.Position = new Microsoft.Xna.Framework.Point(tempCell.X, tempCell.Y); player.RenderOffset = this.Position; entities.Add(player); // Create a hound GenerateHound(); GenerateHound(); GenerateHound(); // Initial view UpdatePlayerView(); // Keyboard setup SadConsole.Engine.Keyboard.RepeatDelay = 0.07f; SadConsole.Engine.Keyboard.InitialRepeatDelay = 0.1f; }
// Use this for initialization void OnEnable() { int width = 300, height = 100; IRandom random = new DotNetRandom(12); IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(width, height, 30, 30, 10, random); // mapCreationStrategy = new CaveMapCreationStrategy<Map>(width, height, 30, 20, 5, random); IMap actualMap = Map.Create(mapCreationStrategy); Color[] colors = new Color[width * height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { var cell = actualMap.GetCell(j, i); if (cell.IsWalkable) { colors[width * i + j] = Color.red; } else { colors[width * i + j] = Color.blue; } } } Texture2D tex = new Texture2D(width, height); tex.SetPixels(colors); tex.Apply(); var bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/randomtxt.png", bytes); //var str = actualMap.ToString(); //str = str.Replace(".", "<color=#C5C1407B>#</color>"); //DLog.Log(str); //int[,] map = MapGenerate(20, 20, 3, 5, 3, 8); //string s = ""; //for (int i = 0; i < map.GetLength(0); i++) //{ // for (int j = 0; j < map.GetLength(1); j++) // { // if(map[i,j] == 0) // { // s += "#"; // } // else // { // s += "<color=#111111>#</color>"; // } // } // s += "\r\n"; //} // DLog.Log(s); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { int maxRooms = 100; int roomMaxSize = 7; int roomMinSize = 3; // TODO: Add your initialization logic here IMapCreationStrategy<Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy<Map>(width, height, maxRooms, roomMaxSize, roomMinSize); _map = Map.Create(mapCreationStrategy); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IMapCreationStrategy<Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy<Map>(Global.MapWidth, Global.MapHeight, 100, 7, 3); _map = Map.Create(mapCreationStrategy); Global.GameState = GameStates.PlayerTurn; Global.Camera.ViewportWidth = graphics.GraphicsDevice.Viewport.Width; Global.Camera.ViewportHeight = graphics.GraphicsDevice.Viewport.Height; base.Initialize(); }
public DungeonMap CreateRooms() { map.Initialize(width, heigth); IMapCreationStrategy <Map> strategy = new RandomRoomsMapCreationStrategy <Map>(width, heigth, 35, 20, 5); map.Copy(strategy.CreateMap()); foreach (Cell cell in map.GetAllCells()) { map.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true); } return(map); }
public static void Main(string[] args) { IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(50, 50, 150, 7, 3); _map = Map.Create(mapCreationStrategy); // Path to Font img, width of window in tiles, height of window in tiles, width of tile in pixels, height of tile in pixels _rootConsole = new RLRootConsole("assets/terminal8x8.png", 60, 60, 8, 8) { Title = "Spelunker" }; var engine = new Engine(_rootConsole, _map); _rootConsole.Run(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(Global.MapWidth, Global.MapHeight, 100, 7, 3); map = Map.Create(mapCreationStrategy); Global.camera.ViewportWidth = graphics.GraphicsDevice.Viewport.Width; Global.camera.ViewportHeight = graphics.GraphicsDevice.Viewport.Height; jogador = new Jogador(Global.camera); Cell rndpos = GetRandomEmptyCell(); jogador.X = rndpos.X; jogador.Y = rndpos.Y; m = Mouse.GetState(); base.Initialize(); }
private void CreateDefaultMap() { _map.ClearAllTiles(); var mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>( _mapWidth, _mapHeight, _maxRooms, _maxRoomSize, _minRoomSize, _random); Map = mapCreationStrategy.CreateMap(); var tilePosition = new Vector3Int(); for (var x = 0; x < _mapWidth; x++) { for (var y = 0; y < _mapHeight; y++) { var cell = Map.GetCell(x, y); tilePosition.Set(x, y, 0); if (cell.IsWalkable) { _map.SetTile(tilePosition, _wallTile); _map.SetColor(tilePosition, Visibility.Invisible); _map.RefreshTile(tilePosition); } else { if (y >= _mapHeight - 1) { continue; } var cellAbove = Map.GetCell(x, y + 1); if (cellAbove != null && cellAbove.IsWalkable) { _map.SetTile(tilePosition, _bottomTile); _map.SetColor(tilePosition, Visibility.Invisible); _map.RefreshTile(tilePosition); } } } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { var mapStrat = new RandomRoomsMapCreationStrategy <Map>(40, 40, 50, 20, 4); _camera = new Camera(GraphicsDevice.Viewport); ServiceLocator <ICamera> .Provide(_camera); _dungeonMap = new DungeonMap(mapStrat); ServiceLocator <IDungeonMap> .Provide(_dungeonMap); _spawner = new EnemySpawner(20); ServiceLocator <IEnemySpawner> .Provide(_spawner); _gameObjs = new List <IGameObject> { _dungeonMap, new Player(), Player.EquippedWeapon, _spawner }; base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(Global.MapWidth, Global.MapHeight, Global.MaxRooms, Global.MaxRoomBigness, Global.MinRoomBigness); _map = Map.Create(mapCreationStrategy); //matches the window to the screen resolution and put it in fullscreen graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width; graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height; graphics.IsFullScreen = true; //graphics.ToggleFullScreen(); graphics.ApplyChanges(); //centres the camera Global.Camera.ViewPortWidth = graphics.GraphicsDevice.Viewport.Width; Global.Camera.ViewPortHeight = graphics.GraphicsDevice.Viewport.Height; this.IsMouseVisible = true; base.Initialize(); }
public void Create_MapCreatedWithRandomRoomsMapCreationStrategy_ExpectedMap() { int expectedWidth = 17; int expectedHeight = 10; IRandom random = new DotNetRandom( 13 ); IMapCreationStrategy<LibtcodMap> mapCreationStrategy = new RandomRoomsMapCreationStrategy<LibtcodMap>( expectedWidth, expectedHeight, 30, 5, 3, random ); string expectedMapRepresentation = @"################# ################# ##...#######...## ##.............## ###.###....#...## ###...##.#####.## ###...##...###..# ####............# ##############..# #################"; IMap actualMap = LibtcodMap.Create( mapCreationStrategy ); Trace.Write( actualMap ); Assert.AreEqual( expectedWidth, actualMap.Width ); Assert.AreEqual( expectedHeight, actualMap.Height ); Assert.AreEqual( expectedMapRepresentation.Replace( " ", string.Empty ), actualMap.ToString() ); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { Vector2 prev_pos = new Vector2(jogador.sqX, jogador.sqY), new_pos; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } else { if (jogador.morreu == false) { startingCell = GetRandomEmptyCell(); en1.Respawn(startingCell, jogador, map, Content); startingCell = GetRandomEmptyCell(); en2.Respawn(startingCell, jogador, map, Content); startingCell = GetRandomEmptyCell(); en3.Respawn(startingCell, jogador, map, Content); startingCell = GetRandomEmptyCell(); en4.Respawn(startingCell, jogador, map, Content); startingCell = GetRandomEmptyCell(); en5.Respawn(startingCell, jogador, map, Content); if (Keyboard.GetState().IsKeyDown(Keys.R)) { IMapCreationStrategy <Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy <Map>(Global.MapWidth, Global.MapHeight, 100, 7, 3); map = Map.Create(mapCreationStrategy); Cell rndpos = GetRandomEmptyCell(); jogador.X = rndpos.X; jogador.Y = rndpos.Y; } else { if (Keyboard.GetState().IsKeyDown(Keys.A) && CanGo_LEFT(jogador)) { jogador.X -= 0.05f; } if (Keyboard.GetState().IsKeyDown(Keys.D) && CanGo_RIGHT(jogador)) { jogador.X += 0.05f; } if (Keyboard.GetState().IsKeyDown(Keys.W) && CanGo_UP(jogador)) { jogador.Y -= 0.05f; } if (Keyboard.GetState().IsKeyDown(Keys.S) && CanGo_DOWN(jogador)) { jogador.Y += 0.05f; } } // TODO: Add your update logic here jogador.Actualizar_Pos_Sprite(); jogador.Actualizar_Posição_na_Grelha(jogador.X, jogador.Y); m = Mouse.GetState(); Vector2 PosRato = new Vector2(m.X, m.Y); Vector2 PosRato2 = Global.camera.ScreenToWorld(PosRato) / 64; jogador.mira = PosRato; if (m.LeftButton == ButtonState.Pressed && !Shoot_Counter) { jogador.Disparo(PosRato2, en1); jogador.Disparo(PosRato2, en2); jogador.Disparo(PosRato2, en3); jogador.Disparo(PosRato2, en4); jogador.Disparo(PosRato2, en5); shot.Play(); Shoot_Counter = true; } if (m.LeftButton == ButtonState.Released) { Shoot_Counter = false; } jogador.Actualizar_Rotação(); new_pos = new Vector2(jogador.sqX, jogador.sqY); Cell jog = map.GetCell(jogador.sqX, jogador.sqY); if (enemy_move_delay == 15) { en1.Has_Detected_Player(map, jog); en1.Attack_Player(map, jogador); if (en1.IsAgressive && !en1.IsDestroyed) { en1.Update(); } en1.sprite.SetPosition(new Vector2(en1.X, en1.Y)); en2.Attack_Player(map, jogador); en2.Has_Detected_Player(map, jog); if (en2.IsAgressive && !en2.IsDestroyed) { en2.Update(); } en2.sprite.SetPosition(new Vector2(en2.X, en2.Y)); en3.Attack_Player(map, jogador); en3.Has_Detected_Player(map, jog); if (en3.IsAgressive && !en3.IsDestroyed) { en3.Update(); } en3.sprite.SetPosition(new Vector2(en3.X, en3.Y)); en4.Attack_Player(map, jogador); en4.Has_Detected_Player(map, jog); if (en4.IsAgressive && !en4.IsDestroyed) { en4.Update(); } en4.sprite.SetPosition(new Vector2(en4.X, en4.Y)); en5.Attack_Player(map, jogador); en5.Has_Detected_Player(map, jog); if (en5.IsAgressive && !en5.IsDestroyed) { en5.Update(); } en5.sprite.SetPosition(new Vector2(en5.X, en5.Y)); enemy_move_delay = 0; } else { enemy_move_delay++; } Global.camera.CenterOn(new Vector2(jogador.X * 64, jogador.Y * 64)); } base.Update(gameTime); } }