override public void Add(BioBotEntity e) { if (e.Get <MovementBehaviourComponent>() != null) { base.Add(e); } }
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)); } } }
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; } }
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); } }); }
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)); } }
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); } }
private void PathFindTowardsPlayer(BioBotEntity entity) { throw new NotImplementedException(); }
public virtual void Add(BioBotEntity e) { this.entities.Add(e); }
public void Remove(BioBotEntity e) { this.entities.Remove(e); }