void Dispose(bool disposing) { particleBoost.SetTotalTime(0); if (disposing && !isDisposed) { if (box != null) { box.Dispose(); box = null; } } }
ChaseCamera chaseCamera; // chase camera object /// <summary> /// Create a new player ship /// </summary> public PlayerShip( GameManager game, // game manager int player, // player id Model model, // model for player ship EntityList entities, // entity list for ship model float radius) // collision box radius { if (game == null) { throw new ArgumentNullException("game"); } if (entities == null) { throw new ArgumentNullException("entities"); } // save parameters gameManager = game; shipModel = model; shipEntities = entities; playerIndex = player; // create movement controller movement = new PlayerMovement(); movement.maxVelocity = GameOptions.MovementVelocity; // enable collision sound collisionSound = true; // create engine particle system with infinite life time particleBoost = gameManager.AddParticleSystem( ParticleSystemType.ShipTrail, transform); particleBoost.SetTotalTime(1e10f); boostTransform = shipEntities.GetTransform("engine"); // create the ship collision box box = new CollisionBox(-radius, radius); // random bobbing offset random = new Random(player); bobbingTime = (float)random.NextDouble(); // setup 3rd person camera parameters camera3rdPerson = false; chaseCamera = new ChaseCamera(); chaseCamera.DesiredPositionOffset = GameOptions.CameraOffset; chaseCamera.LookAtOffset = GameOptions.CameraTargetOffset; chaseCamera.Stiffness = GameOptions.CameraStiffness; chaseCamera.Damping = GameOptions.CameraDamping; chaseCamera.Mass = GameOptions.CameraMass; }
/// <summary> /// Update projectile /// </summary> public bool Update(float elapsedTime, GameManager game) { if (game == null) { throw new ArgumentNullException("game"); } // add elapsed time for this frame this.elapsedTime += elapsedTime; // normalize time float normalizedTime = Math.Min(1.0f, this.elapsedTime / totalTime); // compute current projectile position Vector3 position = Vector3.Lerp(sourcePosition, destinationPosition, normalizedTime); // set postion into projectile transform matrix transform.Translation = position; // if projectile includes a particle system update its position if (system != null) { system.SetTransform(systemTransform * transform); } // check if projectile hit any player int playerHit = game.GetPlayerAtPosition(position); // if a player is hit or reached destination explode projectile if ((playerHit != player && playerHit != -1) || normalizedTime == 1.0f) { // compute explosion position moving hit point into hit normal direction Vector3 explosionPosition = position + 0.5f * animatedSpriteSize * transform.Backward; // set transform to explosion position transform.Translation = explosionPosition; // if an animated sprite explosion is available, create it if (animatedSpriteSize > 0) { game.AddAnimSprite(animatedSprite, explosionPosition, animatedSpriteSize, 10.0f, animatedSpriteFrameRate, animatedSpriteDrawMode, -1); } // if splash damage is available, apply splash damage to nearby players if (explosionDamageRadius > 0) { game.AddDamageSplash(player, explosionDamage, explosionPosition, explosionDamageRadius); } // if exploded on a player add contact damage if (playerHit != -1 && game.GetPlayer(playerHit).IsAlive) { game.AddDamage(player, playerHit, contactDamage, Vector3.Normalize(destinationPosition - sourcePosition)); } // if explosion sound is available, play it if (explosionSound != null) { game.PlaySound3D(explosionSound, explosionPosition); } // add explosion particle system if (projectileType == ProjectileType.Missile) { game.AddParticleSystem( ParticleSystemType.MissileExplode, transform); } else if (projectileType == ProjectileType.Blaster) { game.AddParticleSystem( ParticleSystemType.BlasterExplode, transform); } // kill trail particle system if (system != null) { system.SetTotalTime(-1e10f); } // return false to kill the projectile return(false); } // return true to keep projectile alive return(true); }
// collision box radius /// <summary> /// Create a new player ship /// </summary> public PlayerShip( GameManager game, // game manager int player, // player id Model model, // model for player ship EntityList entities, // entity list for ship model float radius) { if (game == null) { throw new ArgumentNullException("game"); } if (entities == null) { throw new ArgumentNullException("entities"); } // save parameters gameManager = game; shipModel = model; shipEntities = entities; playerIndex = player; // create movement controller movement = new PlayerMovement(); movement.maxVelocity = GameOptions.MovementVelocity; // enable collision sound collisionSound = true; // create engine particle system with infinite life time particleBoost = gameManager.AddParticleSystem( ParticleSystemType.ShipTrail, transform); particleBoost.SetTotalTime(1e10f); boostTransform = shipEntities.GetTransform("engine"); // create the ship collision box box = new CollisionBox(-radius, radius); // random bobbing offset random = new Random(player); bobbingTime = (float)random.NextDouble(); // setup 3rd person camera parameters camera3rdPerson = false; chaseCamera = new ChaseCamera(); chaseCamera.DesiredPositionOffset = GameOptions.CameraOffset; chaseCamera.LookAtOffset = GameOptions.CameraTargetOffset; chaseCamera.Stiffness = GameOptions.CameraStiffness; chaseCamera.Damping = GameOptions.CameraDamping; chaseCamera.Mass = GameOptions.CameraMass; }