public void Update() { foreach (var e in _entities) { var sensorComponents = e.GetComponents <SensorComponent>(); foreach (var s in sensorComponents) { // todo - collisioncomponent.getcollider? var hitbox = new BoundingCircle { Radius = s.Radius, Location = e.Location() }; var collisions = _collisionHandler.GetCollisions(hitbox) .Where(x => x.entity.Id != e.Id) .Select(x => x.entity); s.Detections = collisions.ToList(); } } }
public void Update() { foreach (var e in _entities) { var weaponComponent = e.GetComponent <WeaponComponent>(); var now = DateTime.Now;// todo: weaponComponent.GetElapsedTime() var elapsed = (now - weaponComponent.LastFiredTime).TotalMilliseconds; if (elapsed < weaponComponent.ReloadTime) { continue; } var location = e.GetComponent <LocationComponent>(); // todo: replace these with entity extension methods? var collider = new BoundingCircle { Radius = weaponComponent.Range, Location = location.Location }; var collisions = _collisionHandler.GetCollisions(collider).Where(x => x.entity.Id != e.Id); if (!collisions.Any()) { continue; } // get closest target in range -- in future we could have an AI component with target priorities here var target = collisions.First().entity; if (!TryGetAim(e, target, out var aimPoint)) { continue; } var projectile = CreateProjectile(location, aimPoint, weaponComponent); _messageHub.Post(new CreateEntityCommand { Entity = projectile }); weaponComponent.LastFiredTime = now; } }