public override void Update(TimeSpan t) { this.totalInvestment = this.ecoStats.Values.Sum(stat => stat.Investment); var credits = this.Income * t.NumericValue; this.invest(credits); }
public ServerContinuousSynchronizer(GameState game, NetServer server, PlayerConnectionLookup connections) : base(game) { this.server = server; this.connections = connections; this.timeToNextObjectUpdate = TimeSpan.One; this.timeToNextEcoUpdate = TimeSpan.One; }
public void Update(TimeSpan elapsedS) { _gameState.Update(elapsedS); // Explosions foreach (var gameObject in _gameState.DeadGameObjects) { ExplosionManager.Explode(gameObject); } }
public void Update(TimeSpan elapsedTimeInS) { for (int i = Particles.Count - 1; i >= 0; i--) { var particle = Particles[i]; particle.Update(elapsedTimeInS); if (!particle.IsAlive) { Particles.RemoveAt(i); } } }
public override void Update(TimeSpan t) { this.timeToNextObjectUpdate -= t; this.timeToNextEcoUpdate -= t; if (this.timeToNextEcoUpdate < TimeSpan.Zero) { this.sendEcoUpdate(); this.timeToNextEcoUpdate = TimeSpan.One; } if (this.timeToNextObjectUpdate < TimeSpan.Zero) { this.sendObjectUpdate(); // TODO: check math (intent: sends packages more often when there are more objects, to keep update frequency of single objects stable) this.timeToNextObjectUpdate = TimeSpan.One * (0.5f / (this.objects.Count + 2)); } }
public void DistributeResources(TimeSpan elapsedTime) { currentResources += elapsedTime.NumericValue * totalResourcesProvided; var resourceOut = elapsedTime.NumericValue * totalResourcesRequested; if (resourceOut <= currentResources) { foreach (var consumer in resourceConsumers) { var consumerGrantedResources = elapsedTime.NumericValue * consumer.RatePerS; var grant = new ResourceGrant( Math.Min(consumer.Maximum, consumerGrantedResources), consumerGrantedResources >= consumer.Maximum); currentResources -= grant.Amount; consumer.ConsumeResources(grant); } resetForFrame(); return; } var sortedConsumers = resourceConsumers.OrderBy((consumer) => (consumer.Maximum / consumer.RatePerS)); var resourceRatio = currentResources / resourceOut; foreach (var consumer in sortedConsumers) { var consumerGrantedResources = resourceRatio * elapsedTime.NumericValue * consumer.RatePerS; if (consumer.Maximum <= consumerGrantedResources) { consumer.ConsumeResources(new ResourceGrant(consumer.Maximum, true)); resourceOut -= consumer.Maximum; currentResources -= consumer.Maximum; resourceRatio = currentResources / resourceOut; } else { consumer.ConsumeResources(new ResourceGrant(consumerGrantedResources, false)); currentResources -= consumerGrantedResources; } } resetForFrame(); }
public abstract void Update(TimeSpan elapsedTime);
public override void Update(TimeSpan elapsedTime) { }