Пример #1
0
        /// <summary>
        /// Shoot
        /// </summary>
        public void Shoot()
        {
            PhysicsObject nearestEnemy = ((JTD)JTD.Instance).FindEnemy(this);  // TODO: nearest enemy is searched twice

            if (nearestEnemy != null)
            {
                Ammo ammo = new Ammo(Damage, AmmoColor);
                ammo.Position = Position;
                GameManager.Add(ammo);

                // Minor fix for ammo direction, needs more tweaking.
                Vector enemySpeed = nearestEnemy.Velocity;
                Vector enemyDist  = nearestEnemy.Position - Position;
                Vector dirFix     = enemyDist * 0.2 + enemySpeed * RandomGen.NextDouble(0.05, 2);

                double power     = 500;
                Vector direction = (nearestEnemy.Position - Position).Normalize();
                ammo.Hit(ammo.Mass * (direction * power + dirFix));
            }
        }
Пример #2
0
 private void AmmoHit(Ammo ammo)
 {
     ammo.Destroy();
     Health.Value -= ammo.Damage;
 }