public ArtitectTester() { // Initialise state, map and stage: int mapX = 24; int mapY = 24; // Room templates: var stdRoom = new RoomTemplate(); var largeRoom = new RoomTemplate(RoomType.Room, 3, 6, 4, 6); var corridor = new RoomTemplate(RoomType.Circulation, 1, 1, 4, 8); var exit = new RoomTemplate(RoomType.Exit, 1, 1, 1, 1); //corridor.ExitPlacement = ExitPlacement.Opposite; var corridor2 = new RoomTemplate(RoomType.Circulation, 1, 1, 1, 8); //corridor2.ExitPlacement = ExitPlacement.Opposite_Side; // Create map: var generator = new DungeonArtitect(mapX, mapY); generator.Snapshots = _SnapShots; generator.Templates.Add(stdRoom); generator.Templates.Add(largeRoom); generator.Templates.Add(corridor); generator.Templates.Add(corridor2); generator.Templates.Add(exit); generator.Generate(10, 14, stdRoom, CompassDirection.East); _Timer = new DispatcherTimer(); _Timer.Interval = new TimeSpan(0, 0, 0, 0, 20); _Timer.Tick += _Timer_Tick; _Timer.Start(); Blueprint = _SnapShots[0]; }
private void _Timer_Tick(object sender, EventArgs e) { _Frame++; if (_Frame >= _SnapShots.Count) { _Frame = 0; } Blueprint = _SnapShots[_Frame]; }
/// <summary> /// Creates a new dungeon artitect to work within the specified bounds /// </summary> /// <param name="iSize"></param> /// <param name="jSize"></param> public DungeonArtitect(int iSize, int jSize) { _Blueprint = new SquareCellMap <BlueprintCell>(iSize, jSize); for (int i = 0; i < iSize; i++) { for (int j = 0; j < jSize; j++) { _Blueprint[i, j] = new BlueprintCell(); } } }
/// <summary> /// Take a snapshot of the current state of the blueprint and add it to the snapshots collection /// </summary> public void TakeSnapshot() { if (Snapshots != null) { var snap = new SquareCellMap <CellGenerationType>(_Blueprint.SizeX, _Blueprint.SizeY); for (int i = 0; i < Blueprint.CellCount; i++) { snap[i] = Blueprint[i].GenerationType; } Snapshots.Add(snap); } }
public override void RefreshUI() { object value = Binding.GetBoundValue(); if (value is ICellMap <int> ) { ICellMap <int> map = (ICellMap <int>)value; if (_NewValue != null) { _OldValue = _NewValue; } _NewValue = (SquareCellMap <int>)map; _Tween = 0; } }
public override void Update() { base.Update(); //Animate: if (_NewValue != null) { _Tween += Time.deltaTime * TweenFactor; if (_Tween > 1) { _Tween = 1; } GetComponent <MeshFilter>().mesh.SetVertexColoursFromVisionMap(_NewValue, _OldValue, _Tween, Nucleus.Maths.Interpolation.Sin, 4); if (_Tween >= 1) { _OldValue = _NewValue; } } }
public override GameState StartingState() { // Initialise state, map and stage: int mapX = 24; int mapY = 18; var state = new RLState(); var stage = new MapStage(); var map = new SquareCellMap <MapCell>(mapX, mapY); stage.Map = map; stage.Map.InitialiseCells(); state.Stage = stage; // Items library: var items = new ItemsLibrary(); // Room templates: var stdRoom = new RoomTemplate(); var largeRoom = new RoomTemplate(RoomType.Room, 3, 6, 4, 6); var corridor = new RoomTemplate(RoomType.Circulation, 1, 1, 4, 8); var exit = new RoomTemplate(RoomType.Exit, 1, 1, 1, 1); // Create map: var generator = new DungeonArtitect(mapX, mapY); generator.Templates.Add(stdRoom); generator.Templates.Add(largeRoom); generator.Templates.Add(corridor); generator.Templates.Add(exit); generator.Generate(10, 14, stdRoom, CompassDirection.South); var blueprint = generator.Blueprint; var playerFaction = new Faction("Player"); var enemyFaction = new Faction("Enemy"); // Build dungeon from blueprint: Random rng = new Random(); for (int i = 0; i < mapX; i++) { for (int j = 0; j < mapY; j++) { CellGenerationType cGT = blueprint[i, j].GenerationType; if (cGT.IsWall() || cGT == CellGenerationType.Untouched) { var wall = new GameElement("Wall"); wall.SetData(new ASCIIStyle("█"), new PrefabStyle("Wall"), new MapCellCollider(), new VisionBlocker(), new Memorable(), new Inertia(true)); map[i, j].PlaceInCell(wall); state.Elements.Add(wall); } else if (cGT == CellGenerationType.Door && rng.NextDouble() > 0.5) { // Create door /*var door = new PointElement("Door"); * door.SetData(new ASCIIStyle("+"), new VisionBlocker(), new Memorable(), new Inertia(true)); * map[i, j].PlaceInCell(door); * state.Elements.Add(door);*/ } else if (cGT == CellGenerationType.Void) { if (rng.NextDouble() < 0.1) { var eSword = items.Sword(); // Create enemy var enemy2 = new GameElement("Enemy"); enemy2.SetData(enemyFaction, new ASCIIStyle("e"), new PrefabStyle("Meeple"), new MapCellCollider(), new MapAwareness(10), new Memorable(), new HitPoints(3), new AvailableActions(), new TurnCounter(), new WaitAbility(), new MoveCellAbility(), new BumpAttackAbility(), new Equipped( new EquipmentSlot("1", InputFunction.Ability_1, eSword), new EquipmentSlot("2", InputFunction.Ability_2), new EquipmentSlot("3", InputFunction.Ability_3), new EquipmentSlot("4", InputFunction.Ability_4), new EquipmentSlot("5", InputFunction.Ability_5), new EquipmentSlot("6", InputFunction.Ability_6)), new UseItemAbility()); map[i, j].PlaceInCell(enemy2); state.Elements.Add(enemy2); } } } } /*for (int i = 0; i < mapX; i++) * { * for (int j = 0; j < mapY; j++) * { * if (!(i > 1 && i < 8 && j > 1 && j < 6) && * !(i == 4 && j > 5 && j < 12) && * !(i > 4 && i < 14 && j == 11) && * !(i > 11 && i < 17 && j > 7 && j < 15)) * { * var wall = new PointElement("Wall"); * wall.SetData(new ASCIIStyle("█"), new MapCellCollider(), * new VisionBlocker(), new Memorable()); * map[i, j].PlaceInCell(wall); * } * } * } * * for (int i = 12; i < 17; i++) * { * for (int j = 8; j < 11; j++) * { * var water = new PointElement("Water"); * water.SetData(new ASCIIStyle("~")); * map[i, j].PlaceInCell(water); * } * }*/ // Create stairs var stairs = new GameElement("Stairs"); stairs.SetData(new ASCIIStyle("<"), new Memorable(), new Inertia(true));//, new MapCellCollider()); map[10, 13].PlaceInCell(stairs); //state.Elements.Add(stairs); var sword = items.Sword(); //map[10, 12].PlaceInCell(sword); //state.Elements.Add(sword); var spear = items.Spear(); map[10, 12].PlaceInCell(spear); state.Elements.Add(spear); // Create player character var hero = new GameElement("Hero"); hero.SetData(playerFaction, new ASCIIStyle("@"), new PrefabStyle("Meeple2"), new MapCellCollider(), new MapAwareness(10), new Memorable(), new HitPoints(9), new Equipped( new EquipmentSlot("1", InputFunction.Ability_1, sword), new EquipmentSlot("2", InputFunction.Ability_2), new EquipmentSlot("3", InputFunction.Ability_3), new EquipmentSlot("4", InputFunction.Ability_4), new EquipmentSlot("5", InputFunction.Ability_5), new EquipmentSlot("6", InputFunction.Ability_6)), new AvailableActions(), new TurnCounter(), new WaitAbility(), new MoveCellAbility(), new BumpAttackAbility(), new UseItemAbility(), new PickUpAbility()); map[10, 13].PlaceInCell(hero); state.Elements.Add(hero); state.Controlled = hero; // Create test enemy var enemy = new GameElement("Enemy"); enemy.SetData(enemyFaction, new ASCIIStyle("M"), new VisionBlocker());//, new MapCellCollider()); //map[4, 3].PlaceInCell(enemy); return(state); }