public void Update()
        {
            if (enemy.IsSpawned)
            {
                // Move only if the enemy is spawned and chase phase active
                if (chaseDirection != Vector2.Zero)
                {
                    // Move the shizzle
                    GameObject.Transform.Translate(chaseDirection * speed * Time.DeltaTime, Space.World);
                    GameObject.Transform.LookAtDirection(chaseDirection);

                    // Reset the chase direction after the period
                    phaseTimer.DoEvery(chaseDuration, () => chaseDirection = Vector2.Zero, MyTimer.When.End);
                    return;
                }

                // Set the chase direction after the period
                Action chaseStartAction = () => {
                    isFirstChase = false;

                    // This is executed later, so we need to get the data again
                    var playerNow = PlayerHelper.GetNearestPlayer(GameObject.Transform.WorldPosition);
                    if (playerNow == null)
                    {
                        return;
                    }
                    chaseDirection = playerNow.Transform.WorldPosition - GameObject.Transform.WorldPosition;
                    chaseDirection.Normalize();
                };
                if (isFirstChase)
                {
                    chaseStartAction.Invoke();
                }
                else
                {
                    phaseTimer.DoEvery(restDuration, chaseStartAction, MyTimer.When.End);
                }
            }

            // Look to the player if spawning or resting
            var player = PlayerHelper.GetNearestPlayer(GameObject.Transform.WorldPosition);

            if (player != null)
            {
                GameObject.Transform.LookAt(player.Transform.WorldPosition);
            }
        }
        public override void Update()
        {
            if (AllSpawnersFinishedWave())
            {
                // Show the overlay to the user once
                waveStartTimerOverlay.DoEvery(WAVE_PAUSE_DELAY,
                                              () => Scene.Current.Spawn(new NewWaveOverlay()), MyTimer.When.Start);

                // Trigger the wave start delayed
                waveStartTimer.DoEvery(WAVE_PAUSE_DELAY, StartNewWave, MyTimer.When.End);
            }

            // We want to run the waves after starting a new one
            base.Update();
        }
Exemple #3
0
 public void Update()
 {
     spawnTimer.DoEvery(SpawnInterval, MaySpawnEnemy, MyTimer.When.End, true);
 }
 void MaySpawnShot(Vector2 axis)
 {
     shotTimer.DoEvery(ShotRate, () => SpawnShot(axis), MyTimer.When.Start);
 }