예제 #1
0
        /// <summary>
        /// Enables self-updating of the building
        /// </summary>
        /// <param name="gameTime">Snapshot of time.</param>
        public override void Update(GameTime gameTime)
        {
            if (scene.Fighters.Count <= scene.MaxNumberOfFighters)
            {
                HealthPoints += 0.01f;

                if (HealthPoints >= 1)
                {
                    Fighter f = null;
                    do
                    {
                        if (f != null)
                        {
                            f.Destroy();
                        }
                        Vector3 randomPosition  = new Vector3(Position.X + (float)WarGame.RandomGenerator.NextDouble() * 40.0f - 20.0f,
                                                              scene.GroundYAxisPosition + 1.0f,
                                                              Position.Z + (float)WarGame.RandomGenerator.NextDouble() * 40.0f - 20.0f);

                        f = new Fighter((WarGame)base.Game, randomPosition, scene);

                    } while (f.CheckForCollisions() != null);

                    HealthPoints = 0.0f;
                    ((WarGame)base.Game).Sound.BoooiiinnngSoundInstance.Play();
                    scene.SceneComponents.Add(f);
                    scene.SceneObjects.Add(f);
                    scene.Fighters.Add(f);
                }
            }
            base.Update(gameTime);
        }
예제 #2
0
파일: Bullet.cs 프로젝트: propheel/Projects
 /// <summary>
 /// Constructor of the bullet
 /// </summary>
 /// <param name="_owner">Fighter which shoots the bullet</param>
 /// <param name="_game">Game in which the bullet exists</param>
 public Bullet(Fighter _owner, Game _game, MainScene _scene)
     : base(_game)
 {
     scene = _scene;
     owner = _owner;
     position = _owner.Position;
     headVector = Vector3.Normalize(_owner.TargetToAttack.Position - position);
     velocity = headVector * owner.MaxSpeed * 2;
     secondPoint = position + headVector * length;
     color = new Color(new Vector3((float)WarGame.RandomGenerator.NextDouble(),
                                   (float)WarGame.RandomGenerator.NextDouble(),
                                   (float)WarGame.RandomGenerator.NextDouble()));
     DrawOrder = (int)WarGame.DrawingOrder.GameObject;
     scene.SceneComponents.Add(this);
     lifeTime = new TimeSpan();
 }
예제 #3
0
        /// <summary>
        /// Atack steering behavior
        /// </summary>
        /// <param name="caller">Game object which calles atack SB</param>
        /// <param name="target">Target of the attack</param>
        /// <returns>Force acting on caller</returns>
        public static Vector3 Attack(Fighter caller, AlienCraft target, List<Fighter> friends)
        {
            float minimalDistanceToTargetSquared = 5.0f * 5.0f;
            float shootingDistanceSquared = 15.0f * 15.0f;
            float maximalDistaneToTargetSquared = 30.0f * 30.0f;

            // if you're not escaping
            if (!caller.IsEscaping)
            {
                Vector3 seekingForce = SeekWithSeparation(caller, target.Position, friends);
                Vector3 separationForce = Vector3.Zero;

                // if you're to close start escaping
                if (Vector3.DistanceSquared(caller.Position, target.Position) < minimalDistanceToTargetSquared)
                {
                    caller.IsEscaping = true;
                }

                // if you're in the shooting range slow down to minimum
                if (Vector3.DistanceSquared(caller.Position, target.Position) < shootingDistanceSquared)
                {
                    caller.Velocity = Vector3.Zero;
                }

                return seekingForce + separationForce;
            }

            // if you're escaping
            else
            {
                // if you're far enough start shooting once again
                if (Vector3.DistanceSquared(caller.Position, target.Position) > maximalDistaneToTargetSquared)
                {
                    caller.IsEscaping = false;
                }

                return Flee(caller, target.Position);
            }
        }
예제 #4
0
 /// <summary>
 /// Seek steering behavior combined with the separation
 /// </summary>
 /// <param name="caller">Game object which calls this SB</param>
 /// <param name="target">Target seeked by the caller</param>
 /// <param name="objects">List of fighters to separate from</param>
 /// <returns>Force acting at the caller</returns>
 public static Vector3 SeekWithSeparation(Fighter caller, Vector3 target, List<Fighter> objects)
 {
     if ((caller.Position - target).Length() > 5)
         return Seek(caller, target) + 2 * Separation(caller, objects);
     else if (Separation(caller, objects).Length() < 0.1f)
         return Vector3.Zero;
     else
         return Seek(caller, target) + 6 * Separation(caller, objects);
 }