private void updateStats(GameUpdateEventArgs e) { if (this.Player.Tile.Info.Lightness >= Settings.Game.Level.LightnessThreshold) { this.Statistics.TimeInLight += e.ElapsedTime; } else { this.Statistics.TimeInDarkness += e.ElapsedTime; } }
public void Update(GameUpdateEventArgs e) { var detachCount = randomCount(this.turnOverRate * e.ElapsedTimeF); for (int j = 0; j < detachCount; j++) { var i = GlobalRandom.Next(particles.Count); this.particles[i].DetachFromParent(); this.particles[i].FadeAway(GlobalRandom.NextFloat(0.2f, 1f)); this.particles[i] = this.makeParticle(); } }
public override void Update(GameUpdateEventArgs e) { var toParent = this.relativePosition ? -this.position : (this.parentPosition - this.position); var dSquared = toParent.LengthSquared; var distance = (float)Math.Sqrt(dSquared); var force = 10; this.velocity += toParent * (1 / distance * force * e.ElapsedTimeF); var tangent = Vector3.Cross(toParent, Vector3.UnitZ); var tangentForce = 0.3f * Math.Min(1, 1 / dSquared); if (Vector3.Dot(tangent, this.velocity) > 0) { tangentForce *= -1; } this.velocity += tangent.Normalized() * tangentForce * e.ElapsedTimeF; var speedSquared = this.velocity.LengthSquared; if (speedSquared > 10) { this.velocity *= (float)Math.Pow(0.5f, e.ElapsedTimeF); } this.position += this.velocity * e.ElapsedTimeF; if (this.fadeOutStart == 0 || this.fadeOutStart > this.game.Time) { this.alpha += (1 - this.alpha) * e.ElapsedTimeF; } else { this.alpha *= (1 - this.fadeOutFactor * e.ElapsedTimeF); if (this.alpha < 0.01f) { this.Delete(); } } }
public void Update(GameUpdateEventArgs e) { var focusGoal = new Vector3(this.focus.Position) + Settings.Game.Camera.FocusOffset; var positionGoal = new Vector3(this.focus.Position) + Settings.Game.Camera.PositionOffset * (this.Zoom ? Settings.Game.Camera.OverviewZoom : Settings.Game.Camera.DefaultZoom); var focusSpeed = Math.Min(1, Settings.Game.Camera.FocusForce * e.ElapsedTimeF); this.Focus += (focusGoal - this.Focus) * focusSpeed; var positionSpeed = Math.Min(1, Settings.Game.Camera.PositionForce * e.ElapsedTimeF); this.Position += (positionGoal - this.Position) * positionSpeed; }
private void updateOverlay(GameUpdateEventArgs e) { var fadeSpeed = (this.State == GameState.GameOverState.Undetermined ? 2 : 0.3f) * e.ElapsedTimeF; var bGoal = this.State == GameState.GameOverState.Won ? 1 : 0; GameState.overlayBrightness += (bGoal - GameState.overlayBrightness) * fadeSpeed; var pGoal = this.State == GameState.GameOverState.Undetermined ? 1 - this.Player.HealthPercentage : 1; pGoal *= pGoal; GameState.overlayPercentage += (pGoal - GameState.overlayPercentage) * fadeSpeed; }
public override void Update(GameUpdateEventArgs e) { var acceleration = this.game.State == GameState.GameOverState.Undetermined ? new Vector2( this.controls.Right.AnalogAmount - this.controls.Left.AnalogAmount, this.controls.Up.AnalogAmount - this.controls.Down.AnalogAmount ) : Vector2.Zero; var a = acceleration.Length; if (a > 0) { acceleration /= a; } this.velocity += acceleration * Settings.Game.Wisp.Acceleration * e.ElapsedTimeF; base.Update(e); this.particles.Update(e); if (this.game.State != GameState.GameOverState.Lost && this.healStartTime <= this.game.Time) { var healSpeed = this.Tile.Info.Lightness > Settings.Game.Level.LightnessThreshold ? Settings.Game.Wisp.LightHealSpeed : Settings.Game.Wisp.HealSpeed; this.health = Math.Min(Settings.Game.Wisp.MaxHealth, this.health + e.ElapsedTimeF * healSpeed); } if (this.game.State != GameState.GameOverState.Undetermined) { return; } if (this.health <= 0) { this.game.GameOver(false); } else if (this.Tile.Radius == this.game.Level.Tilemap.Radius) { this.game.GameOver(true); } }
public override void Update(GameUpdateEventArgs e) { // don't move stationary objects if (this.velocity == Vector2.Zero) { return; } var step = this.velocity * e.ElapsedTimeF; Vector2 lastStepDir = Vector2.Zero; // update position (tests collision recursively) for (int i = 0; i < 5; i++) { var rayResult = new RayHitResult(false, 1, this.position - this.tileCenter + step, Vector2.Zero); while (true) { var result = this.tile.Info.ShootRay(new Ray(this.position - this.tileCenter, step)); if (result.RayFactor < rayResult.RayFactor) { rayResult = result; } var point = rayResult.Point + this.tileCenter; var switchedTile = this.updateTile(rayResult.Point); if (!switchedTile) { break; } rayResult = rayResult.WithNewPoint(point - this.tileCenter); } lastStepDir = this.tileCenter + rayResult.Point - this.position; this.position = this.tileCenter + rayResult.Point; if (!rayResult.Hit) { break; } this.position += rayResult.Normal * 0.01f; var projected = rayResult.Normal * Vector2.Dot(rayResult.Normal, step); step -= projected; } this.velocity = lastStepDir.LengthSquared > 0 ? this.velocity.Length * lastStepDir.Normalized() : Vector2.Zero; float slowDownFactor = 1 - this.frictionCoefficient * e.ElapsedTimeF; this.velocity *= slowDownFactor < 0 ? 0 : slowDownFactor; }
public abstract void Update(GameUpdateEventArgs e);
public void Update(UpdateEventArgs args) { var newArgs = new GameUpdateEventArgs(args, 1f); // don't use 'args' after this point this.time += newArgs.ElapsedTime; this.timeF = (float)this.time; if (InputManager.IsKeyHit(Key.F3)) { this.DrawDebug = !this.DrawDebug; } if (InputManager.IsKeyHit(Key.F1)) { this.tutorialVisible = !tutorialVisible; } if (this.tutorialVisible) { this.tutorialAlpha = Math.Min(1, this.tutorialAlpha + newArgs.ElapsedTimeF * 2); if (InputManager.IsKeyHit(Key.F8)) { Process.Start("http://bit.ly/youarethelight"); } } else { this.tutorialAlpha = Math.Max(0, this.tutorialAlpha - newArgs.ElapsedTimeF * 2); } if (this.tutorialAlpha == 1) { this.hideTitle = true; } this.MonstersCloseToPlayer = 0; #region Update Game Objects bool deletedObjects = false; for (int i = 0; i < this.gameObjects.Count; i++) { var gameObject = this.gameObjects[i]; gameObject.Update(newArgs); if (gameObject.Deleted) { // dispose gameObject.Dispose(); this.gameObjects[i] = null; deletedObjects = true; } } if (deletedObjects) { this.gameObjects.RemoveAll(obj => obj == null); } #endregion if (InputManager.IsKeyHit(Key.F4)) { this.Camera.Zoom = !this.Camera.Zoom; } this.Camera.Update(newArgs); this.musicSettings.Update(newArgs); this.updateOverlay(newArgs); this.updateStats(newArgs); }
public override void Update(GameUpdateEventArgs e) { var toPlayer = this.game.Player.Position - this.position; var toPlayerDSquared = toPlayer.LengthSquared; #region check player visibility if (this.nextVisibleCheck == 0) { this.nextVisibleCheck = this.game.Time + GlobalRandom.NextFloat(Settings.Game.Enemy.MinScanInterval, Settings.Game.Enemy.MaxScanInterval); } if (this.nextVisibleCheck < this.game.Time) { this.nextVisibleCheck = 0; if (toPlayerDSquared < Settings.Game.Enemy.ViewDistanceSquared) { var result = this.game.Level.ShootRay(new Ray(this.position, toPlayer), this.Tile); this.seesPlayer = !result.Results.Hit; if (game.DrawDebug) { var lines = SpriteManager.Instance.Lines; lines.Color = result.Results.Hit ? Color.Red : Color.Green; lines.LineWidth = 0.2f; lines.DrawLine(this.position, result.GlobalPoint); } } else { this.seesPlayer = false; } } if (this.seesPlayer) { if (!this.chasing) { this.game.ChasingEnemies.Add(this); this.chasing = true; } this.lastKnownPlayerPosition = this.game.Player.Position; this.losePlayerTime = this.game.Time + 1; } if (this.chasing && this.losePlayerTime < this.game.Time) { this.game.ChasingEnemies.Remove(this); this.chasing = false; } #endregion #region chase if (this.chasing) { var toKnownPlayerPosition = this.lastKnownPlayerPosition - this.position; this.velocity += toKnownPlayerPosition.Normalized() * Settings.Game.Enemy.Acceleration * e.ElapsedTimeF; } #endregion #region monster-monster collision foreach (var monster in this.Tile.Info.Monsters) { if (monster == this) { continue; } var diff = monster.position - this.position; var dSquared = diff.LengthSquared; if (dSquared == 0) { continue; } const float radius = 1f; if (dSquared < radius * radius) { var d = (float)Math.Sqrt(dSquared); var normalDiff = diff / d; var f = radius - d; f *= f; this.velocity -= 100 * normalDiff * f * e.ElapsedTimeF; if (this.game.DrawDebug) { var lines = SpriteManager.Instance.Lines; lines.Color = Color.Red; lines.LineWidth = 0.1f; lines.DrawLine(this.position, this.position + diff / d); } } } #endregion #region fear of light foreach (var tile in this.Tile.Info.OpenSides.Enumerate() .Select(d => this.Tile.Neighbour(d)).Append(this.Tile)) { var info = tile.Info; if (info.Lightness > 0.2) { var tilePosition = this.game.Level.GetPosition(tile); var diff = tilePosition - this.position; var d = diff.Length; const float radius = Settings.Game.Level.HexagonSide * 1.1f; if (d < radius) { var normalDiff = diff / d; var f = radius - d; f *= f; this.velocity -= 100 * normalDiff * f * e.ElapsedTimeF; } } } #endregion #region bite if (this.waitingToBite) { if (this.biteNextFrame) { var toPlayerNormal = toPlayer.Normalized(); this.game.Player.Damage(Settings.Game.Enemy.HitDamage, toPlayerNormal); this.velocity *= 0.1f; this.velocity += toPlayerNormal * 5; this.particles.Explode(0.6f, toPlayerNormal.WithZ(0) * 10, 1); this.nextHitTime = this.game.Time + Settings.Game.Enemy.HitInterval; this.biteNextFrame = false; this.waitingToBite = false; } else { if (toPlayerDSquared > Settings.Game.Enemy.HitDistanceSquared) { this.waitingToBite = false; } } } if (!this.waitingToBite && this.nextHitTime <= this.game.Time && toPlayerDSquared < Settings.Game.Enemy.HitDistanceSquared) { //this.game.Player.Damage(Settings.Game.Enemy.HitDamage); //this.nextHitTime = this.game.Time + Settings.Game.Enemy.HitInterval; this.scheduleBite(); } #endregion #region blinking if (this.nextBlinkToggle < this.game.Time) { this.blinking = !this.blinking; if (this.blinking) { this.nextBlinkToggle = this.game.Time + (GlobalRandom.NextBool(0.1f) ? GlobalRandom.NextFloat(0.1f, 1f) : GlobalRandom.NextFloat(0.1f, 0.2f)); } else { this.nextBlinkToggle = this.game.Time + (GlobalRandom.NextBool(0.2f) ? GlobalRandom.NextFloat(0.2f, 0.4f) : GlobalRandom.NextFloat(1, 10)); } } #endregion if (toPlayerDSquared < Settings.Game.Enemy.ContributeToTensionDistanceSquared) { this.game.MonstersCloseToPlayer++; } base.Update(e); this.particles.Update(e); }