Ejemplo n.º 1
0
        /// <summary>
        /// Clone another Bullet object.
        /// </summary>
        /// <returns>A cloned bullet.</returns>
        public Bullet clone()
        {
            Bullet b = new Bullet();

            b.damage = damage;
            b.timeToLive = timeToLive;
            b.mass = mass;
            b.size = size;
            b.lastPosition = lastPosition.Clone();

            b.rateL = rateL;
            b.rateR = rateR;
            b.dragL = dragL;
            b.dragR = dragR;
            foreach (FBXModel model in models)
            {
                b.models.Add(model.clone());
            }

            b.onDeathSound = onDeathSound;

            if (explosion != null)
            {
                b.explosion = explosion.clone();
            }

            return b;
        }
Ejemplo n.º 2
0
 // Behaviors
 public Weapon()
 {
     fireFrom = new Coords();
     bullet = new Bullet();
     bullet.damage = 10;
     bullet.timeToLive = 5;
     bullet.mass = 5;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Explode an explosion.
        /// </summary>
        /// <param name="spot">The starting point for the explosion.</param>
        /// <param name="vel">The starting velocity for the explosion.</param>
        public void explode(Coords spot, Coords vel)
        {
            Coords velocity = new Coords(vel.pos());
            Coords position = new Coords(spot.pos());
            Bullet bullet;
            FBXModel model;

            if (bullets.Count < 1)
            {
                Console.WriteLine("Loading Explosion Bullets.");
                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 35 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.2f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = bullet.clone();
                bullet.damage = 100 * power;
                bullet.rateL = 35 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.2f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 150 * power;
                bullet.rateL = 20 * size;
                bullet.dragL = 0.5f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 2.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 80 * power;
                bullet.rateL = 30 * size;
                bullet.dragL = 0.5f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 45 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 0.6f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 45 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 0.6f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);
            }

            for (int i = 0; i < particles; i++)
            {
                Console.WriteLine("Explosion Bullet");
                int m = rand.Next(bullets.Count);
                bullet = bullets[m].clone();
                bullet.scaleModels(size);

                bullet.lastPosition = position.Clone();
                bullet.velocity = velocity.Clone();

                bullet.position.T = position.T;
                bullet.position.R = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)(MathHelper.TwoPi * rand.NextDouble())) *
                    Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)(MathHelper.TwoPi * rand.NextDouble())) *
                    Quaternion.CreateFromAxisAngle(Vector3.Right, (float)(MathHelper.TwoPi * rand.NextDouble()));

                bullet.throttle(1f);

                Engine.GetInstance().gameScene.track(bullet, GO_TYPE.BULLET);
            }
        }
Ejemplo n.º 4
0
        private void collideBullet(Bullet bullet, GameObject o2)
        {
            Vector3 originalPosition = bullet.lastPosition.pos();
            Vector3 newPosition = bullet.position.pos();
            Vector3 forwardVector = bullet.position.pos() - bullet.lastPosition.pos();
            forwardVector.Normalize();
            Ray forwardRay = new Ray(bullet.lastPosition.pos(), forwardVector);
            BoundingSphere sphere = new BoundingSphere(o2.position.pos(), o2.size);
            float? intersectDistance = sphere.Intersects(forwardRay);

            if (intersectDistance != null)
            {
                if ((float)intersectDistance < forwardVector.Length())
                {
                    gameScene.ignore(bullet, GO_TYPE.BULLET);
                    o2.takeDamage(bullet.damage);
                    bullet.OnDeath();
                }
            }
        }