Esempio n. 1
0
        public void Update()
        {
            healthBar.Update(50);

            waveStats[0].StringText = "Wave: " + WaveManager.WaveNumber;
            waveStats[1].StringText = "Enemies: " + WaveManager.WaveEnemiesUsed + "/" + WaveManager.WaveEnemyAmount;

            currencyStats[0].StringText = "Manpower: " + GameManager.Manpower;
            currencyStats[1].StringText = "Resources: " + GameManager.Resources;

            timers[0].StringText = "Next Wave in: " + WaveManager.WaveStartTimer;
        }
Esempio n. 2
0
        public void Update()
        {
            if (IsActive)
            {
                shootTimer += 1 / 60f;
                // Find closest enemy, rotate and shoot.
                List <Enemy> enemyList   = EnemyListener.EnemyList;
                Enemy        targetEnemy = null;
                Enemy        tempEnemy   = null;
                float        dist        = Range;
                int          index       = 0;
                for (int i = 0; i < enemyList.Count; i++)
                {
                    if ((enemyList[i].EnemyType != "Helicopter" && TypeofTower != Type.SAM) || (TypeofTower == Type.SAM && enemyList[i].EnemyType == "Helicopter"))
                    {
                        tempEnemy = enemyList[i];
                        if (dist > Vector2.Distance(tempEnemy.ScreenPos, this.Position))
                        {
                            dist = Vector2.Distance(tempEnemy.ScreenPos, this.Position);

                            if (TypeofTower == Type.Gun)
                            {
                                if (targetEnemy == null || i < index || targetEnemy.EnemyType != "Soldier")
                                {
                                    index       = i;
                                    targetEnemy = enemyList[i];
                                }
                            }

                            if (TypeofTower == Type.Rocket)
                            {
                                if (targetEnemy == null || i < index || (targetEnemy.EnemyType != "Tank" && targetEnemy.EnemyType != "Transport" && targetEnemy.EnemyType != "Helicopter"))
                                {
                                    index       = i;
                                    targetEnemy = enemyList[i];
                                }
                            }


                            if (TypeofTower == Type.SAM || TypeofTower == Type.Tesla)
                            {
                                if (targetEnemy == null || i < index)
                                {
                                    index       = i;
                                    targetEnemy = enemyList[i];
                                }
                            }
                        }
                    }
                }
                if (targetEnemy != null)
                {
                    // LERPING HERE
                    float nextRotation = Extensions.ToAngle(targetEnemy.ScreenPos - Position);
                    Rotation = Extensions.CurveAngle(Rotation, nextRotation, 0.6f);
                    // Shoot
                    if (shootTimer >= (1f / FireRate))
                    {
                        shootTimer = 0;
                        Shoot(targetEnemy);
                    }
                }
                // If no enemy, rotate back and forth.
                if (Rotation < 0)
                {
                    rotClock = true;
                }
                if (Rotation > 6.2f)
                {
                    rotClock = false;
                }

                if (rotClock)
                {
                    Rotation += 0.02f;
                }
                else
                {
                    Rotation -= 0.02f;
                }
            }
            // Update Projectiles before deleting any.
            foreach (Projectile proj in TowerProjectiles)
            {
                proj.Update();
            }
            // Remove Projectiles after lifetime.
            for (int i = 0; i < TowerProjectiles.Count(); i++)
            {
                if (TowerProjectiles[i].TimeSinceSpawn > TowerProjectiles[i].Lifetime)
                {
                    TowerProjectiles.RemoveAt(i);
                }
            }

            healthBar.Update(Health);
        }