#region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; #endregion // Local using statements using XNAEngine; using CollisionDetection; using LinearAlgebra; //using Physics; // Test Gun Class by Dr. Roger Webster and Dr. Gary Zoppetti namespace XNACollisionDetection { public class PrawnNade : CollidableModel { ParticleSystem explosionParticles; ParticleSystem explosionSmokeParticles; ParticleEmitter trailEmitter; const float trailParticlesPerSecond = 200; const int numExplosionParticles = 30; const int numExplosionSmokeParticles = 50; const float gravity = 15; #region Variables float life_span = 4; float age = 0; Vector3 explosion_velocity; private bool m_isVisible; bool m_alive; string homedir = System.IO.Directory.GetCurrentDirectory() + "/sounds/"; Vector3 m_init_pos; Vector3 m_hide_pos; Vector3 m_pos; Direction m_direction; Quaternion m_rotation; Matrix4 world_transform; float m_gravity; float m_y_velocity; float m_fall_speed; float m_fwd_velocity; float m_angle_x; float m_angle_y; float m_angle_z; #endregion static Random random = new Random(); public PrawnNade(Model model, ParticleSystem trail, ParticleSystem explosionSmokeParticles, ParticleSystem explosionParticles, Matrix4 worldTrans) : base(model) { #region InitVars m_alive = false; m_init_pos = Vector3.Zero; m_gravity = -0.01f; m_fall_speed = -2.0f; m_y_velocity = 0.0f; m_fwd_velocity = 0.0f; m_direction = Direction.Forward; m_angle_x = 1.0f; m_angle_y = 0.0f; m_angle_z = 0.0f; m_hide_pos.X = 0.0f; m_hide_pos.Y = -1000.0f; m_hide_pos.Z = 0.0f; world_transform = worldTrans; #endregion explosion_velocity.X = (float)(random.NextDouble() - 0.5); explosion_velocity.Y = (float)(random.NextDouble() + 0.5); explosion_velocity.Z = (float)(random.NextDouble() - 0.5); this.explosionParticles = explosionParticles; this.explosionSmokeParticles = explosionSmokeParticles; trailEmitter = new ParticleEmitter(trail, trailParticlesPerSecond, this.Position); } public void setVisible(bool visible) { m_isVisible = visible; } public Vector3 getPos() { Vector3 pos; pos.X = (float)m_pos.X; pos.Y = (float)m_pos.Y; pos.Z = (float)m_pos.Z; return (pos); } public void setPos(Vector3 pos) { m_pos.X = pos.X; m_pos.Y = pos.Y; m_pos.Z = pos.Z; this.Position = m_pos; } public new void Draw(Camera camera) { if (m_isVisible) { base.Draw(camera); } } public void Fire(Vector3 pos, Quaternion rot) { setVisible(true); m_alive = true; m_init_pos = pos; m_pos = pos; m_rotation = rot; m_fwd_velocity = 1.0f; m_y_velocity = 0.1f; this.Position = m_pos; this.Rotation = m_rotation; age = 0; } public void Update(GameTime gameTime) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; age += elapsedTime; Vector3 prev_pos = this.Position; if(m_y_velocity > m_fall_speed) m_y_velocity += m_gravity; this.move(m_direction, m_fwd_velocity); this.moveWorld(world_transform.Up, m_y_velocity); if (m_alive) trailEmitter.Update(gameTime, this.Position); if (age > life_span) { this.Reset(); } } public void Reset() { if (m_alive) { Sound explode_snd = new Sound(homedir + "weapons/rocket hit.wav", false); explode_snd.play(); for (int i = 0; i < numExplosionParticles; i++) explosionParticles.AddParticle(this.Position, explosion_velocity); for (int i = 0; i < numExplosionSmokeParticles; i++) explosionSmokeParticles.AddParticle(this.Position, explosion_velocity); m_alive = false; } setVisible(false); m_fwd_velocity = 0.0f; this.Position = m_hide_pos; } } }