/// <summary> Update </summary> public override void Update() { HandleInput(); // Sync AI, Use display units //base.Update(); // no need, just update Position and Rotation Position = ConvertUnits.ToDisplayUnits(_vehicleBody.Position); Rotation = Body.Rotation; if (_vehicleBody.UserData.ToString() == "getroffen") { HealthBar.SetDamage(GameSettings.TowerDamage); _vehicleBody.UserData = "player"; } cannon.Update(); } // Update()
} // CreateBodyByList(list) #endregion #region Update /// <summary> /// Updates the PhysicBreakable /// </summary> /// <param name="gameTime"></param> /// <returns></returns> public void Update(GameTime gameTime) { // used in BreakableTrigger if (Animate) { // Bounce control constants float bounce; const float BounceHeight = 0.18f;//0.18f; const float BounceRate = 3.0f; //const float BounceSync = -0.75f; // Bounce along a sine curve over time. // Include the X coordinate so that neighboring gems bounce in a nice wave pattern ? double t = gameTime.TotalGameTime.TotalSeconds * BounceRate; //+ body.Position.X * BounceSync; bounce = (float)Math.Sin(t) * BounceHeight; // *ConvertUnits.ToSimUnits(_textureBodyXna.Height);// *32; //texture.Height; Vector2 position = body.Position; position.Y -= bounce; body.Position = position; } if (body.UserData.ToString() == "damage") { hitpoints -= GameSettings.PlayerDamage; body.UserData = "enemyTower"; } // Is Shooting for the Tower allowed? for (int t = 0; t < GameDemo1.physicBreakables.Count; t++) { if (Vector2.Distance(GameDemo1.vehicle.Position, ConvertUnits.ToDisplayUnits(GameDemo1.physicBreakables[t].body.Position)) < GameDemo1.vehicle.Radius + GameDemo1.physicBreakables[t].AggroRange) { GameDemo1.physicBreakables[t].MayFire = true; } else { GameDemo1.physicBreakables[t].MayFire = false; } } // Break the Body if we have no more hitpoints and Start the Timer if (hitpoints <= 0 && _breakableBody != null) { _breakableBody.Break(); disableLevelCollision = true; TimeBroken += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (TimeBroken >= DeleteAfter) { Delete(); if (WithCannon == true) { cannon.Body.Dispose(); if (enemyShot != null) { enemyShot.shotBody.Dispose(); } } TimeBroken -= DeleteAfter; } if (_breakableBody != null && _broken != _breakableBody.Broken) { _reselect = _broken = true; } if (_reselect || _parts.Length == 0) { _parts = PhysicsGameScreen.World.BodyList.Where( b => b.FixtureList.Any( f => f.UserData is Guid && _infos.ContainsKey((Guid)f.UserData)) ).ToArray(); // if we are broken, disable collision with level or car if (disableLevelCollision) { foreach (Body b in _parts) { b.IgnoreCollisionWith(GameDemo1.vehicle.Body); b.IgnoreCollisionWith(GameDemo1.vehicle.WheelBackBody); b.IgnoreCollisionWith(GameDemo1.vehicle.WheelFrontBody); b.IgnoreCollisionWith(GameDemo1.vehicle.cannon.Body); } } // case when we are Destroyed if (_reselect == true) { // Only explode if this are no background object. else vehicle gets raped too hard :( if (Explode) { Vector2 explosionDirection = GameDemo1.vehicle.cannon.Body.Position - _breakableBody.MainBody.Position; explosionDirection.Normalize(); new Explosion(_breakableBody.MainBody.Position + explosionDirection, 200); } // still play explosion sound, else it's too booring! Sound.Play(Sound.Sounds.Explosion); GameDemo1.particleManager.AddExplosion(body.Position); // receive Score GameSettings.HighScore += (uint)GameSettings.TowerScore; FadeUp.AddTextMessage("+ " + GameSettings.TowerScore, FadeUp.TextTypes.Score, body.Position); // Don't animate any more, causes errors! Animate = false; body.IgnoreGravity = false; // Gravity enabled = better performance + look&feel! if (WithCannon) // drop a Pickup if this breakable has a cannon { new PickUp("AI/health", body.Position, 2.0f); } } _reselect = false; } // Update cannon and shots if we are not broken if (!_broken && WithCannon == true) { if (enemyShot != null && enemyShot.shotBody.UserData.ToString() == "disable") { enemyShot.shotBody.Dispose(); enemyShot = null; } cannon.Update(); TimeSinceShot += (float)gameTime.ElapsedGameTime.TotalSeconds; //Zeit seit letztem Update dazuaddieren if (TimeSinceShot >= ShotTimer) //Wenn die vergangene Zeit größer ist als der Timer, do... { TimeSinceShot = 0; if (MayFire == true) { Sound.Play(Sound.Sounds.CannonShot); GameDemo1.particleManager.AddEnemyCannonParticles(cannon.Body); UpdateShot(); } } } } // Update(gameTime)