Esempio n. 1
0
        public void Collided(Collision collision, World world, Particles particles)
        {
            var go = collision.GameObject;

            if (go is Rocket || go is PlasmaBullet)
            {
                for (int h = 0; h < 100; h++)
                    particles.Emit(ParticleManager.Explosion, (go.Position + Position) / 2f, Chaos.GetVector2InCircle(3f));
                if (go is Rocket)
                    HP -= 7;
                else
                    HP -= 3;
                if (HP <= 0)
                    IsDestroyed = true;
            }

            if (go is Asteroid)
            {
                if (collision.Time > 0)
                    Response.Apply(this, collision);
                for (int i = 0; i < collision.GameObject.Collisions.Count; i++)
                    if (collision.GameObject.Collisions[i].GameObject == this)
                    {
                        CollisionPool.Instance.PutObject(collision.GameObject.Collisions[i]);
                        collision.GameObject.Collisions[i] = null;
                    }
                collision.GameObject.Collisions.RemoveAll(c => c == null);
            }
        }
Esempio n. 2
0
 public virtual void Update(World world, Particles particles)
 {
     Position += Speed;
     Position = new Vector2(
         (Position.X + Game.WorldWidth) % Game.WorldWidth,
         (Position.Y + Game.WorldHeight) % Game.WorldHeight);
     Rotation += RotationSpeed;
 }
Esempio n. 3
0
 public override void Update(World world, Particles particles)
 {
     base.Update(world, particles);
     if (_state >= 1f) { IsDestroyed = true; return; }
     Size = Lerp.OfFloat(_particleParameters.Sizes, _state * (_particleParameters.Sizes.Length - 1));
     Color = Lerp.OfColor(_particleParameters.Colors, _state * (_particleParameters.Colors.Length - 1));
     Alpha = Lerp.OfFloat(_particleParameters.Alphas, _state * (_particleParameters.Alphas.Length - 1));
     _state += _step;
 }
Esempio n. 4
0
 public override void Update(World world, Particles particles)
 {
     foreach (var col in Collisions)
         Collided(col.GameObject, world, particles);
     base.Update(world, particles);
     State -= .01f;
     if (State < 0f)
         IsDestroyed = true;
     particles.Emit(ParticleManager.PlasmaTrail, Position, Vector2.Zero);
 }
Esempio n. 5
0
 public override void Update(World world, Particles particles)
 {
     Speed += _acceleration;
     particles.Emit(ParticleManager.RocketFire, Position - new Vector2(10f * Maf.Sin(Rotation), -10f * Maf.Cos(Rotation)), Chaos.GetVector2InCircle() + Speed);
     foreach (var col in Collisions)
         Collided(col.GameObject, world, particles);
     base.Update(world, particles);
     State -= .01f;
     if (State < 0f)
         IsDestroyed = true;
 }
Esempio n. 6
0
 public void Update(World world, Particles particles)
 {
     for (int i = 0; i < _particles.Count; i++)
     {
         _particles[i].Update(world, particles);
         if ((_particles[i]).IsDestroyed)
         {
             _particlePool.PutParticle((Particle)_particles[i]);
             _particles[i] = null;
         }
     }
     _particles.RemoveAll(p => p == null);
 }
Esempio n. 7
0
 public void Update(World world, Particles particles)
 {
     for (int i = 0; i < _gameObjects.Count; i++)
     {
         var obj = _gameObjects[i];
         obj.Update(world, particles);
         if (obj.IsDestroyed)
         {
             obj.ResetGameObject();
             Game.Objects.ReleaseObject(obj);
             _gameObjects[i] = null;
         }
     }
     _gameObjects.RemoveAll(o => o == null);
 }
Esempio n. 8
0
 public void Collided(GameObject go, World world, Particles particles)
 {
     IsDestroyed = true;
 }
Esempio n. 9
0
        public override void Update(World world, Particles particles)
        {
            _weapon.Update(_world);
            _weaponAlt.Update(_world);
            foreach (var col in Collisions)
                Collided(col, world, particles);
            if (_speedBonusTime > 0)
            {
                _boost = 2.0f;
                _speedBonusTime--;
                if (_acceleration > 0)
                    particles.Emit(ParticleManager.EngineNitro, Position - new Vector2(10f * Maf.Sin(Rotation), -10f * Maf.Cos(Rotation)), Speed - _acceleration * new Vector2(8f * Maf.Sin(Rotation), -8f * Maf.Cos(Rotation)) + Chaos.GetVector2InCircle());
            }
            else
            {
                _boost = 1.0f;
                if (_acceleration > 0)
                    particles.Emit(ParticleManager.EngineFire, Position - new Vector2(10f * Maf.Sin(Rotation), -10f * Maf.Cos(Rotation)), Speed - _acceleration * new Vector2(8f * Maf.Sin(Rotation), -8f * Maf.Cos(Rotation)) + Chaos.GetVector2InCircle());
            }

            base.Update(world, particles);
            Speed *= .99f;
        }
Esempio n. 10
0
 private void Collided(Collision col, World world, Particles particles)
 {
     if (col.GameObject is SpeedBonus)
     {
         _speedBonusTime = 1000;
     }
     if (col.GameObject is Medkit)
         HP = MaxHP;
     if (col.GameObject is PlasmaBullet)
         HP -= 3;
     if (col.GameObject is Rocket)
         HP -= 7;
     if (HP <= 0)
     {
         var t = this.GetType();
         Game.WinShip(t);
         for (int i = 0; i < _world.Count; i++)
         {
             var ship = _world[i] as Ship;
             if (ship != null && ship.HP < 0)
             {
                 ship.HP = ship.MaxHP;
                 ship.Position = Chaos.GetVector2InRectangle(Game.WorldWidth, Game.WorldHeight);
             }
         }
     }
 }
Esempio n. 11
0
 private void Collided(Collision col, World world, Particles particles)
 {
     if (col.GameObject is Ship)
         IsDestroyed = true;
 }
Esempio n. 12
0
 public override void Update(World world, Particles particles)
 {
     foreach (var col in Collisions)
         Collided(col, world, particles);
     base.Update(world, particles);
 }
Esempio n. 13
0
        public override void Update(World world, Particles particles)
        {
            var d_pos = _target.Position - Position;
            float dx = ((d_pos.X + Game.WorldWidth / 2) % Game.WorldWidth) - Game.WorldWidth / 2;
            float dy = ((d_pos.Y + Game.WorldHeight / 2) % Game.WorldHeight) - Game.WorldHeight / 2;

            var directionTargetBegin = new Vector2(dx, dy);
            var nrm_directionTargetBegin = directionTargetBegin;
            nrm_directionTargetBegin.Normalize();

            //var time_Speed = directionTarget.Length()
            //    / (
            //        Vector2.Dot(_target.Speed, new Vector2(-nrm_directionTarget.X, -nrm_directionTarget.Y))
            //        + Vector2.Dot(Speed, nrm_directionTarget)
            //    );

            //var directionTargetEnd = directionTargetBegin * Speed / (Speed - _target.Speed);
            //var nrm_directionTargetEnd = directionTargetEnd;
            //nrm_directionTargetEnd.Normalize();

            var time_weapon = directionTargetBegin.Length() / (_weapon.Speed + Vector2.Dot(Speed, nrm_directionTargetBegin));

            TargetPos = _target.Position + time_weapon * (_target.Speed - Speed);

            var t = directionTargetBegin - time_weapon * (Speed - _target.Speed);
            float ang = Maf.Atan2(t.Y, t.X);

            Rotation = ang + MathHelper.PiOver2;

            var dir = new Vector2(Maf.Cos(ang), Maf.Sin(ang));
            var nrm = new Vector2(dir.Y, -dir.X);
            var accel = Vector2.Dot(nrm_directionTargetBegin, dir);
            var strafe = Vector2.Dot(nrm_directionTargetBegin, nrm);

            //var distanceVector = new Vector2(directionTarget.X - time_Speed * (Speed.X - _target.Speed.X), directionTarget.Y - time_Speed * (Speed.Y - _target.Speed.Y));

            float distance_length = (directionTargetBegin).Length();
            //if (HP < (MaxHP / 2))
            //{
            //    ;
            //}
            //else
            if (distance_length > 600.0f)
            {
                SpeedUp(accel);
                Strafe(strafe);
                //ShootAlt(Input.InputDigitalState.Released);
            }
            else if (distance_length > 400.0f)
            {
                _strafe = Chaos.GetFloat(-.2f, .2f);
                _accel = Chaos.GetFloat(-.05f, .05f);
                SpeedUp(0.4f * accel);
                Strafe(0.4f * strafe);
                //Shoot(Input.InputDigitalState.Released);
            }
            else if (distance_length < 200.0f)
            {
                _strafe = Chaos.GetFloat(-.2f, .2f);
                _accel = Chaos.GetFloat(-.05f, .05f);
                SpeedUp(-0.2f * accel);
                Strafe(-0.2f * strafe);
                //Shoot(Input.InputDigitalState.Pressed);
            }
            else if (distance_length < 100.0f)
            {
                SpeedUp(-accel);
                Strafe(-strafe);
                //Shoot(Input.InputDigitalState.Pressed);
            }
            else
            {
                SpeedUp(_accel);
                Strafe(_strafe);
                //ShootAlt(Input.InputDigitalState.Pressed);
            }

            Shoot(Input.InputDigitalState.Pressed);

            base.Update(world, particles);
        }
Esempio n. 14
0
 public void Collided(GameObject go, World world, Particles particles)
 {
     if (!(go is PlasmaBullet))
         IsDestroyed = true;
 }