Exemple #1
0
 override public void Add(BioBotEntity e)
 {
     if (e.Get <MovementBehaviourComponent>() != null)
     {
         base.Add(e);
     }
 }
Exemple #2
0
 private void NaivelyMoveTowardsPlayer(BioBotEntity entity)
 {
     // Look at whether we should move on the X-axis, Y-axis, or both, and then move randomly from whichever ones we need to move.
     (var dx, var dy) = (areaMap.Player.X - entity.X, areaMap.Player.Y - entity.Y);
     if (dx == 0)
     {
         areaMap.TryToMove(entity, 0, Math.Sign(dy));
     }
     else if (dy == 0)
     {
         areaMap.TryToMove(entity, Math.Sign(dx), 0);
     }
     else
     {
         // Randomly move
         if (random.NextDouble() < 0.5)
         {
             areaMap.TryToMove(entity, Math.Sign(dx), 0);
         }
         else
         {
             areaMap.TryToMove(entity, 0, Math.Sign(dy));
         }
     }
 }
Exemple #3
0
        public void TryToMove(BioBotEntity entity, int deltaX, int deltaY)
        {
            var destinationX = entity.X + deltaX;
            var destinationY = entity.Y + deltaY;

            if (destinationX < 0 || destinationX >= this.width || destinationY < 0 || destinationY >= this.height ||
                !this.isWalkable[destinationX, destinationY])
            {
                return;
            }
            else if (this.Monsters.Any(m => m.X == destinationX && m.Y == destinationY))
            {
                // NB: monsters will fight each other to get to you :/
                var target = this.Monsters.Single(m => m.X == destinationX && m.Y == destinationY);
                target.Add(new DamageComponent(entity.Get <FightComponent>().Strength - target.Get <FightComponent>().Toughness));
            }
            else if (this.Player.X == destinationX && this.Player.Y == destinationY)
            {
                Player.Add(new DamageComponent(entity.Get <FightComponent>().Strength - Player.Get <FightComponent>().Toughness));
            }
            else
            {
                // Clear, so move.
                entity.X = destinationX;
                entity.Y = destinationY;
            }
        }
Exemple #4
0
        public AreaMap(IGenerator globalRandom)
        {
            this.globalRandom = globalRandom;
            this.width        = Constants.MAP_TILES_WIDE;
            this.height       = Constants.MAP_TILES_HIGH;
            this.isWalkable   = new ArrayMap <bool>(Constants.MAP_TILES_WIDE, Constants.MAP_TILES_HIGH);

            this.Player = new BioBotEntity("Player", 0, 0).Add(new HealthComponent(500)).Add(new FightComponent(50, 15));

            // Each method gets its own RNG, so hopefully things are more segregated (less cascading changes)
            this.GenerateMap(new StandardGenerator(globalRandom.Next()));
            // TODO: more sophisticated.
            Player.X = this.width / 4;
            Player.Y = this.height / 4;
            this.GenerateMonsters(new StandardGenerator(globalRandom.Next()));

            EventBus.LatestInstance.Subscribe(Signal.EntityDied, (obj) =>
            {
                var entity = (BioBotEntity)obj;
                if (Monsters.Contains(entity))
                {
                    this.Monsters.Remove(entity);
                }
            });
        }
Exemple #5
0
        private void RandomWalk(BioBotEntity entity)
        {
            // Actually random, doesn't matter if that tile is walkable or not. Meaning, sometimes do nothing. :shrug:
            var dx = random.NextDouble() < 0.5 ? -1 : 1;
            var dy = random.NextDouble() < 0.5 ? -1 : 1;

            if (random.NextDouble() < 0.5)
            {
                areaMap.TryToMove(entity, Math.Sign(dx), 0);
            }
            else
            {
                areaMap.TryToMove(entity, 0, Math.Sign(dy));
            }
        }
Exemple #6
0
        public void GenerateMonsters(IGenerator random)
        {
            // TODO: more sophisticated.
            var numMonsters = random.Next(6, 10);

            while (numMonsters-- > 0)
            {
                (var x, var y) = (random.Next(this.width), random.Next(this.height));

                while (!isWalkable[x, y] || Monsters.Any(m => m.X == x && m.Y == y) || (x == this.Player.X && y == this.Player.Y))
                {
                    (x, y) = (random.Next(this.width), random.Next(this.height));
                }

                var monster = new BioBotEntity("Slime", x, y)
                              .Add(new HealthComponent(100))
                              .Add(new FightComponent(25, 15))
                              .Add(new MovementBehaviourComponent(5, IdleBehaviour.NaiveStalk, SeenPlayerBehaviour.NaiveStalk));

                this.Monsters.Add(monster);
            }
        }
Exemple #7
0
 private void PathFindTowardsPlayer(BioBotEntity entity)
 {
     throw new NotImplementedException();
 }
Exemple #8
0
 public virtual void Add(BioBotEntity e)
 {
     this.entities.Add(e);
 }
Exemple #9
0
 public void Remove(BioBotEntity e)
 {
     this.entities.Remove(e);
 }