public void Update(GameTime gameTime) { //To satisfy the condition, that you have to loose after some time mOuterRange += 0.001f * gameTime.ElapsedGameTime.Milliseconds / 16.0f; mInnerRange += 0.001f * gameTime.ElapsedGameTime.Milliseconds / 16.0f; var inRange = mScene.mQuadTree.QueryRectangle(Actor.mBoundingRectangle.GetAxisAlignedRectangle((int)Math.Floor(mOuterRange))); mDistanceSilverbackHut = Vector3.Distance(mSilverback.Actor.ModelMatrix.Translation, Actor.ModelMatrix.Translation); if (!mSpawned && mDistanceSilverbackHut <= mOuterRange) { if (!mTechDemo) { mNumLumberjacks = LumberChoice.NumLumberjacks(HP); // Spawning is not enough, we should give them a target // Also I suggest that we use something like an inner and an outer range. // If the distance to the siverback is less than the outer range, we spawn the lumberjacks // If the distance to the silverback is less than the inner range, we set the targets of the lumberjacks for (var i = 0; i < mNumLumberjacks; i++) { var lumberjack = new Lumberjack.Lumberjack(mLumberjackMesh, mScene.mTerrain, mScene.mQuadTree, Actor.ModelMatrix.Translation, 4.0f, mInnerRange, mScene, mSilverback, false); lumberjack.Hut = this; var axe = new Actor(mAxeMesh); lumberjack.Actor.mAnimator.AttachActor("Bone.016", axe); mLumberjacks.Add(lumberjack); lumberjack.StayInRange(); mScene.Add(lumberjack); mScene.Add(axe); } for (var i = 0; i < (HP - mNumLumberjacks); i++) { var killer = new DoubleAxeKiller(mDoubleAxeKillerMesh, mScene.mTerrain, mScene.mQuadTree, Actor.ModelMatrix.Translation, 4.0f, mInnerRange, mScene, mSilverback); killer.Hut = this; var leftAxe = new Actor(mAxeMesh); var rightAxe = new Actor(mAxeMesh); mDoubleAxeKillers.Add(killer); killer.Actor.mAnimator.AttachActor("Bone.017", leftAxe); killer.Actor.mAnimator.AttachActor("Bone.016", rightAxe); killer.StayInRange(); mScene.Add(killer); mScene.Add(leftAxe); mScene.Add(rightAxe); } } else { for (var i = 0; i < HP; i++) { var lumberjack = new Lumberjack.Lumberjack(mLumberjackMesh, mScene.mTerrain, mScene.mQuadTree, Actor.ModelMatrix.Translation, 4.0f, mInnerRange, mScene, mSilverback, true); lumberjack.Hut = this; mLumberjacks.Add(lumberjack); lumberjack.StayInRange(); mScene.Add(lumberjack); } } mSpawned = true; } else { // Instead of calculating the range to the silverback, we should do a query on the quad tree // to determine if there are any apes in the range. We should also do this for spawning. mDistanceSilverbackHut = Vector3.Distance(mSilverback.Actor.ModelMatrix.Translation, Actor.ModelMatrix.Translation); // Set the target to one of the lumberjacks and let them return of the lumberjack is out of range if (mDistanceSilverbackHut <= mInnerRange) { foreach (var lumberjack in mLumberjacks) { if (lumberjack.IsMoving) { lumberjack.SetTarget(mSilverback.Actor.ModelMatrix.Translation); } } foreach (var doubleAxeKiller in mDoubleAxeKillers) { if (doubleAxeKiller.IsMoving) { doubleAxeKiller.SetTarget(mSilverback.Actor.ModelMatrix.Translation); } } mWasInInnerRange = true; } else { // We just want to tell them once to stay in range if (mWasInInnerRange) { foreach (var lumberjack in mLumberjacks) { lumberjack.StayInRange(); } foreach (var killer in mDoubleAxeKillers) { killer.StayInRange(); } mWasInInnerRange = false; } } } }