Exemple #1
0
        public void GenerateMapGeneratesBacktrackingGravityWavesOneFloorAboveGravityCannonWithPairedPowerUps()
        {
            RestrictRuntime(() => {
                const int GravityCannonFloor = 6; // B6
                var random     = new StandardGenerator(356);
                var noPowerUps = new List <PowerUp>();

                var floor = new Floor(30, 30, GravityCannonFloor - 2, random);
                Assert.That(floor.GravityWaves.Any());
                Assert.That(floor.GravityWaves.All(g => g.IsBacktrackingWave));

                // Make sure the power-ups are backtracking and paired
                var powerUps = floor.PowerUps.Where(p => p.IsBacktrackingPowerUp).ToArray();
                Assert.That(powerUps.Count(), Is.EqualTo(2));

                var p1 = powerUps[0];
                var p2 = powerUps[1];

                Assert.That(p1.PairedTo, Is.EqualTo(p2));
                Assert.That(p2.PairedTo, Is.EqualTo(p1));

                // Generated in a new room, make sure it's accessible
                var firstGravity            = floor.GravityWaves.First();
                var firstGravityCoordinates = new GoRogue.Coord(firstGravity.X, firstGravity.Y);
                var pathFinder = new AStar(floor.Map, GoRogue.Distance.EUCLIDEAN);
                var path       = pathFinder.ShortestPath(floor.StairsUpLocation, firstGravityCoordinates, true);
            });
        }
Exemple #2
0
 public TeleporterShot(int x, int y, Direction direction, Func <int, int, bool, bool> isMovable, GoRogue.Coord stairsDownLocation)
     : base(x, y, '?', Palette.Cyan, direction, AlwaysMovable)
 {
     this.TeleportTo         = new GoRogue.Coord(x, y);
     this.realIsMovable      = isMovable;
     this.stairsDownLocation = stairsDownLocation;
 }
Exemple #3
0
        public void GenerateMapGeneratesBacktrackingLockedDoorsOnZapperFloorMinusOneWithPairedPowerUps()
        {
            RestrictRuntime(() => {
                const int ZapperFloor = 4; // B4
                var random            = new StandardGenerator(355);
                var noPowerUps        = new List <PowerUp>();

                var floor = new Floor(30, 30, ZapperFloor - 2, random);
                Assert.That(floor.Doors.Any(d => d.IsLocked && d.IsBacktrackingDoor));
                Assert.That(floor.Doors.Count(d => d.IsLocked && !d.IsBacktrackingDoor), Is.EqualTo(0));

                // Make sure the power-ups are backtracking and paired
                var powerUps = floor.PowerUps.Where(p => p.IsBacktrackingPowerUp).ToArray();
                Assert.That(powerUps.Count(), Is.EqualTo(2));

                var p1 = powerUps[0];
                var p2 = powerUps[1];

                Assert.That(p1.PairedTo, Is.EqualTo(p2));
                Assert.That(p2.PairedTo, Is.EqualTo(p1));

                // Generated in a new room, make sure it's accessible
                var firstLock            = floor.Doors.First(d => d.IsLocked && d.IsBacktrackingDoor);
                var firstLockCoordinates = new GoRogue.Coord(firstLock.X, firstLock.Y);
                var pathFinder           = new AStar(floor.Map, GoRogue.Distance.EUCLIDEAN);
                var path = pathFinder.ShortestPath(floor.StairsUpLocation, firstLockCoordinates, true);
            });
        }
Exemple #4
0
        public void GenreateMapGeneratesBacktrackingChasmsOneFloorBeforeTeleporterWithPairedPowerUps()
        {
            RestrictRuntime(() => {
                const int InstaTeleporterFloor = 8; // B8
                var random     = new StandardGenerator(357);
                var noPowerUps = new List <PowerUp>();

                var floor = new Floor(30, 30, InstaTeleporterFloor - 2, random);
                Assert.That(floor.Chasms.Any());

                // Chasms don't have a "backtracking" property. Instead, Check that all the chasms are in one room.
                // Well, we can't check that either; so check that they're all adjacent to two other chasms. /shrug
                foreach (var chasm in floor.Chasms)
                {
                    var adjacencies = floor.Chasms.Where(c => c != chasm && Math.Sqrt(Math.Pow(c.X - chasm.X, 2) + Math.Pow(c.Y - chasm.Y, 2)) == 1);
                    Assert.That(adjacencies.Count(), Is.EqualTo(2));
                }

                // Make sure the power-ups are backtracking and paired
                var powerUps = floor.PowerUps.Where(p => p.IsBacktrackingPowerUp).ToArray();
                Assert.That(powerUps.Count(), Is.EqualTo(2));

                var p1 = powerUps[0];
                var p2 = powerUps[1];

                Assert.That(p1.PairedTo, Is.EqualTo(p2));
                Assert.That(p2.PairedTo, Is.EqualTo(p1));

                // Generated in a new room, make sure it's accessible
                var firstChasm            = floor.Chasms.First();
                var firstChasmCoordinates = new GoRogue.Coord(firstChasm.X, firstChasm.Y);
                var pathFinder            = new AStar(floor.Map, GoRogue.Distance.EUCLIDEAN);
                var path = pathFinder.ShortestPath(floor.StairsUpLocation, firstChasmCoordinates, true);
            });
        }
Exemple #5
0
        private float CalculateFitness(List <DungeonOp> solution)
        {
            // Reset RNG so we are deterministic
            var map = new GridMap(new Random(GLOBAL_RANDOM_SEED));

            foreach (DungeonOp op in solution)
            {
                op.Execute(map);
            }

            // Calculate the walking distance from every point to the center. Manhatten distance (no sqrt).
            // More distance is better, obviously, because we're more maze-like.
            var center = new GoRogue.Coord(GridMap.TILES_WIDE / 2, GridMap.TILES_HIGH / 2);

            map.Set(center.X, center.Y, true);

            var totalCalculated = 0f;

            var aStar = new AStar(map.Data, GoRogue.Distance.MANHATTAN);

            for (var y = 0; y < GridMap.TILES_HIGH; y++)
            {
                for (var x = 0; x < GridMap.TILES_WIDE; x++)
                {
                    var path = aStar.ShortestPath(new GoRogue.Coord(x, y), center);
                    totalCalculated += path != null ? path.Length : 0;  // 0 if no path found
                }
            }

            return(totalCalculated);
        }
Exemple #6
0
        public void CreateExplosionCreatesTilesAroundAndIncludingMissileEpicenter()
        {
            var generator = new StandardGenerator(313821775);

            var floor     = new Floor(80, 28, 0, generator);
            var epicenter = new GoRogue.Coord(5, 5);
            var radius    = Floor.ExplosionRadius;

            floor.CreateExplosion(epicenter.X, epicenter.Y);

            // Just for clarity, yes it's redundant
            Assert.That(floor.EffectEntities.Any(e => e.X == epicenter.X && e.Y == epicenter.Y && e is Explosion), $"Didn't find explosion at epicenter!");

            for (var y = epicenter.Y - radius; y <= epicenter.Y + radius; y++)
            {
                for (var x = epicenter.X - radius; x <= epicenter.X + radius; x++)
                {
                    var distance = Math.Sqrt(Math.Pow(x - epicenter.X, 2) + Math.Pow(y - epicenter.Y, 2));
                    if (distance <= radius)
                    {
                        Assert.That(floor.EffectEntities.Any(e => e.X == x && e.Y == y && e is Explosion), $"Didn't find explosion at {x}, {y}");
                    }
                }
            }
        }
Exemple #7
0
 public Shot(int x, int y, char character, Color color, Direction direction, Func <int, int, bool, bool> isMovable) : base(x, y, character, Palette.Red, ShotUpdateTimeMs)
 {
     this.Direction      = direction;
     this.isMovableCheck = isMovable;
     this.createdOnTile  = new GoRogue.Coord(x, y);
     // Shots don't get delayed by setting effects to 2x slowness or whatever
     this.tickEveryMilliseconds = (int)(this.tickEveryMilliseconds / Options.EffectsDelayMultiplier);
 }
 public bool CanActorSeeTarget(IBeing being, Coord target)
 {
     //FINISH: one FOV and one Pathfinder per map
     //FieldOfView fov = new FieldOfView(Map);
     //fov.ComputeFov(actor.Point, actor.Awareness, true);
     //return fov.IsInFov(target);
     return(false);
 }
Exemple #9
0
        private ChargeStation GenerateChargeStation()
        {
            GoRogue.Coord chargePos = map.RandomPosition((coord, value) =>
                                                         value &&
                                                         coord != GoRogue.Coord.Get(Player.X, Player.Y) &&
                                                         !ChargeStations.Any(station =>
                                                                             coord == GoRogue.Coord.Get(station.X, station.Y)));

            return(new ChargeStation(chargePos.X, chargePos.Y, '&'));
        }
Exemple #10
0
        private Enemy GenerateEnemy()
        {
            GoRogue.Coord chargePos = map.RandomPosition((coord, value) =>
                                                         value &&
                                                         coord != GoRogue.Coord.Get(Player.X, Player.Y) &&
                                                         !ChargeStations.Any(station =>
                                                                             coord == GoRogue.Coord.Get(station.X, station.Y)));

            return(new Enemy(chargePos.X, chargePos.Y, 'D', new Energy(0, 5))); // TODO: Define enemy fuel levels better
        }
Exemple #11
0
 public void GenerateDoesntGenerateDataCubeOnStairs()
 {
     RestrictRuntime(() => {
         var seed             = 1470491287;
         var dungeon          = new Dungeon(80, 28, seed);
         var b9               = dungeon.Floors[8];
         var dataCubePosition = new GoRogue.Coord(b9.DataCube.X, b9.DataCube.Y);
         Assert.That(b9.StairsDownLocation, Is.Not.EqualTo(dataCubePosition));
         Assert.That(b9.StairsUpLocation, Is.Not.EqualTo(dataCubePosition));
     });
 }
Exemple #12
0
        // floor number is 2 for B2
        public static DataCube GetCube(int floorNumber, GoRogue.Coord coordinates)
        {
            if (floorNumber < FirstDataCubeFloor || floorNumber > FirstDataCubeFloor + cubeTexts.Count - 1)
            {
                throw new InvalidOperationException($"There is no data cube for B{floorNumber}");
            }

            var index = floorNumber - DataCube.FirstDataCubeFloor;
            var data  = cubeTexts[index];

            return(new DataCube(coordinates.X, coordinates.Y, floorNumber, data.Item1, data.Item2));
        }
Exemple #13
0
 public override void PerformAction()
 {
     if (Parent.Position != Goal)
     {
         Map.GameMap map = (Map.GameMap)Parent.CurrentMap;
         GoRogue.Pathing.FastAStar pathing = new GoRogue.Pathing.FastAStar(map.GetWalkabilityMap(), GoRogue.Distance.EUCLIDEAN);
         GoRogue.Pathing.Path      path    = pathing.ShortestPath(Parent.Position, Goal);
         if (path != null)
         {
             GoRogue.Coord next   = path.GetStepWithStart(1);
             GoRogue.Coord toMove = next - Parent.Position;
             Parent.Position += toMove;
         }
     }
 }
Exemple #14
0
 internal void Step()
 {
     // Enemies that are adjacent to the player attempt to attack
     // Otherwise they try to move towards the player
     foreach (Enemy enemy in Enemies)
     {
         Path path = aStar.ShortestPath(enemy.X, enemy.Y, Player.X, Player.Y);
         if (path.Length > 1)
         {
             GoRogue.Coord nextPoint = path.GetStep(0);
             enemy.X = nextPoint.X;
             enemy.Y = nextPoint.Y;
             enemy.RenderEntity.Position = new Microsoft.Xna.Framework.Point(nextPoint.X, nextPoint.Y);
         }
     }
 }
Exemple #15
0
        private List <GoRogue.Coord> getSurroundingTiles(GoRogue.Coord location)
        {
            var x = location.X;
            var y = location.Y;

            return(new List <GoRogue.Coord>()
            {
                new GoRogue.Coord(x - 1, y - 1),
                new GoRogue.Coord(x - 1, y),
                new GoRogue.Coord(x - 1, y + 1),
                new GoRogue.Coord(x, y - 1),
                new GoRogue.Coord(x, y + 1),
                new GoRogue.Coord(x + 1, y - 1),
                new GoRogue.Coord(x + 1, y),
                new GoRogue.Coord(x + 1, y + 1),
            });
        }
        public List <Coord> GetPathTo(Coord start, Coord target)
        {
            //Map.SetWalkable(start, true);
            //Map.SetWalkable(target, true);

            ////IMapView<bool> view = Map.sd

            ////PathFinder pathFinder = new PathFinder(Map, 1.0, Math.Sqrt(2));
            ////GoRogue.Pathing.AStar finder = new AStar(IMapView<bool> null, Distance.EUCLIDEAN);
            //var pathList = pathFinder.ShortestPathList(start, target);

            //Map.SetWalkable(start, false);
            //Map.SetWalkable(target, false);

            //return pathList;
            throw new NotImplementedException();
        }
Exemple #17
0
        override internal void OnAction()
        {
            base.OnAction();

            // We only want to track the previous spot if it was walkable. This way, we teleport to the last walkable spot we saw.
            if (this.realIsMovable(this.X, this.Y, false))
            {
                this.TeleportTo = new GoRogue.Coord(this.X, this.Y);
                if (this.TeleportTo == this.stairsDownLocation)
                {
                    // teleport immediately to avoid getting stuck on floors where the stairs are surrounded
                    // by a chasm, and teleporting takes you over the chasm, not down into the middle (stairs).
                    // https://twitter.com/nightblade99/status/1185686524802879488
                    this.IsAlive = false;
                }
            }

            this.Life -= 1;
            if (this.Life == 0)
            {
                this.IsAlive = false;
            }
        }
Exemple #18
0
        public override void PerformAction()
        {
            if (Goal == Parent.Position || Goal.X == -1)
            {
                GoRogue.Coord zero = new GoRogue.Coord(0, 0);
                int           x;
                int           y;
                do
                {
                    x    = rand.Next(0, Parent.CurrentMap.Width);
                    y    = rand.Next(0, Parent.CurrentMap.Height);
                    Goal = new GoRogue.Coord(x, y);
                } while ((Goal - Parent.Position) == zero || !Parent.CurrentMap.GetWalkabilityMap()[x, y]);
            }

            Map.GameMap map = (Map.GameMap)Parent.CurrentMap;
            GoRogue.Pathing.FastAStar pathing = new GoRogue.Pathing.FastAStar(map.GetWalkabilityMap(), GoRogue.Distance.EUCLIDEAN);
            GoRogue.Pathing.Path      path    = pathing.ShortestPath(Parent.Position, Goal);
            if (path != null)
            {
                GoRogue.Coord next   = path.GetStepWithStart(1);
                GoRogue.Coord toMove = next - Parent.Position;
                Parent.Position += toMove;
            }
            else
            {
                if (WaitTime > 10)
                {
                    Goal     = new GoRogue.Coord(-1, -1);
                    WaitTime = 0;
                }
                else
                {
                    WaitTime++;
                }
            }
        }
        public Coord CoordInDirection(Coord start, CmdDirection direction)
        {
            int newX = start.X;
            int newY = start.Y;

            if (direction.HasFlag(CmdDirection.North))
            {
                newY--;
            }
            if (direction.HasFlag(CmdDirection.South))
            {
                newY++;
            }
            if (direction.HasFlag(CmdDirection.West))
            {
                newX--;
            }
            if (direction.HasFlag(CmdDirection.East))
            {
                newX++;
            }

            return(newX, newY);
        }
        public void CheckActorAtCoordEvent(IBeing being, Coord position)
        {
            ////0.1.MAP  fix load of map-based events

            //if (Map.LocationMessages.ContainsKey(tile.Point))
            //{
            //    var message = Map.LocationMessages[tile.Point];
            //    foreach (var line in message)
            //        Output.WriteLine(line);

            //    Map.LocationMessages.Remove(tile.Point);
            //}

            //if (Map.LocationEventEntries.ContainsKey(tile.Point))
            //{
            //    var entries = Map.LocationEventEntries[tile.Point];
            //    foreach (var entry in entries)
            //    {
            //        //CommandQueue.Enqueue(entry.Command);
            //    }
            //}

            //0.3 may unify those collections and loops, may restructure flow
        }
Exemple #21
0
 protected override Terrain TranslateSet(GoRogue.Coord pos, bool value)
 {
     return(value ? Terrain.Floor(pos, FloorColor) : Terrain.Wall(pos, WallColor));
 }
 public void RemovePlantAt(Coord position)
 {
     //Map.GetTileAt(point).RemovePlant();
 }
 public void PutItemOnMap(IItem item, Coord coord)
 {
     ItemMap.Add(item, coord);
 }
Exemple #24
0
 public MoveTo(GameEntity parent, GoRogue.Coord goal) : base(parent)
 {
     Goal = goal;
 }
Exemple #25
0
 public PlayerBlueprint(string name, GoRogue.Coord pos) : base("player")
 {
     _name = name;
     _pos  = pos;
 }
Exemple #26
0
 private Player GeneratePlayer()
 {
     GoRogue.Coord playerPos = map.RandomPosition(true);
     return(new Player(playerPos.X, playerPos.Y, '@', new Energy(100, 20)));
 }
Exemple #27
0
 public RandomMove(GameEntity parent) : base(parent)
 {
     Goal     = new GoRogue.Coord(-1, -1);
     WaitTime = 0;
 }
Exemple #28
0
        private void ProcessPlayerInput(object data)
        {
            if (data is PuffinAction)
            {
                var action = (PuffinAction)data;

                if (action == PuffinAction.Up)
                {
                    areaMap.OnPlayerIntendToMove(0, -1);
                    this.rangeAttackTiles.Clear();
                }
                else if (action == PuffinAction.Down)
                {
                    areaMap.OnPlayerIntendToMove(0, 1);
                    this.rangeAttackTiles.Clear();
                }
                else if (action == PuffinAction.Left)
                {
                    areaMap.OnPlayerIntendToMove(-1, 0);
                    this.rangeAttackTiles.Clear();
                }
                else if (action == PuffinAction.Right)
                {
                    areaMap.OnPlayerIntendToMove(1, 0);
                    this.rangeAttackTiles.Clear();
                }

                this.RedrawEverything();
            }
            else if (data is SpaceMarineEvent)
            {
                var marineEvent = (SpaceMarineEvent)data;
                if (marineEvent == SpaceMarineEvent.AimOrFire)
                {
                    if (!rangeAttackTiles.Any())
                    {
                        this.effectsTileMap.Clear();
                        var target = this.areaMap.Aliens.OrderBy(
                            a => GoRogue.Distance.EUCLIDEAN.Calculate(a.TileX, a.TileY, this.areaMap.Player.TileX, this.areaMap.Player.TileY))
                                     .FirstOrDefault();

                        if (target != null)
                        {
                            var stop  = new GoRogue.Coord(target.TileX, target.TileY);
                            var start = new GoRogue.Coord(this.areaMap.Player.TileX, this.areaMap.Player.TileY);
                            // Calculate line, stop at the first solid tile; order from player => target
                            var line = GoRogue.Lines.Get(start, stop)
                                       .Where(s => s != start)
                                       .OrderBy(s => GoRogue.Distance.EUCLIDEAN.Calculate(s.X, s.Y, this.areaMap.Player.TileX, this.areaMap.Player.TileY))
                                       .ToList();

                            var stopAt = line.FirstOrDefault(s => this.areaMap[s.X, s.Y] == false);
                            if (stopAt.X != 0 && stopAt.Y != 0) // not nullable, we get zero if not found
                            {
                                var stopIndex = line.IndexOf(stopAt);
                                line = line.GetRange(0, stopIndex);
                            }

                            this.rangeAttackTiles = line;

                            // Draw
                            this.RedrawEverything();
                        }
                    }
                    else
                    {
                        var lastTile = this.rangeAttackTiles.Last();
                        var target   = this.areaMap.Aliens.SingleOrDefault(a => a.TileX == lastTile.X && a.TileY == lastTile.Y);
                        if (target != null)
                        {
                            // pew pew
                            this.areaMap.PlayerShoots(target);
                        }
                        this.rangeAttackTiles.Clear();
                        this.RedrawEverything();
                    }
                }
            }
        }