Ejemplo n.º 1
0
        /// <summary>
        /// Destroys enemies and cleans up references in other lists of said enemy
        /// </summary>
        static void DestroyEnemy(Enemy enemy, string TypeID, string EnemyID)
        {
            EnemyListener.RemoveEnemy(enemy);

            Enemies.Remove(enemy);

            int index2 = EnemyIDs.FindIndex(item => string.Compare(item, EnemyID, 0) == 0);

            if (index2 >= 0)
                EnemyIDs.RemoveAt(index2);
        }
Ejemplo n.º 2
0
        public static Vector2 Update(Enemy enemy)
        {
            enemy.shootTimer -= 1 / 60f;

            //Find closest tower
            Vector2 turretDirection = new Vector2();
            Tower targetTower = null;
            Tower tempTower = null;
            float dist = 175;
            foreach(Tower tower in TowerListener.TowersList)
            {
                tempTower = tower;
                if (dist > Vector2.Distance(tempTower.Position, enemy.ScreenPos))
                {
                    dist = Vector2.Distance(tempTower.Position, enemy.ScreenPos);

                    if(dist > 100)
                        targetTower = tower;

                    enemy.towerInRange = true;
                }
            }
            //Shoot
            if (targetTower != null)
            {
                // LERPING HERE
                turretDirection = new Vector2(targetTower.Position.X - enemy.ScreenPos.X, targetTower.Position.Y - enemy.ScreenPos.Y);
                //float nextRotation = turretDirection.ToAngle();
                //Rotation = Extensions.CurveAngle(Rotation, nextRotation, 0.3f);
                //turretDirection = Rotation.ToVector();
                // Shoot

                if (enemy.shootTimer <= 0)
                {
                    enemy.shootTimer = 1;
                    Shoot(targetTower, enemy, turretDirection);
                }
            }

            else enemy.towerInRange = false;

            for (int i = 0; i < EnemyProjectiles.Count(); i++)
                if (EnemyProjectiles[i].TimeSinceSpawn > EnemyProjectiles[i].Lifetime)
                    EnemyProjectiles.RemoveAt(i);

            turretDirection.Normalize();
            Rotation = turretDirection.ToAngle();
            return turretDirection;
        }
Ejemplo n.º 3
0
 public Projectile(Type type, Enemy enemy, Vector2 position, Vector2 direction, float lifetime, float damage, float speed = 10)
 {
     direction.Normalize();
     m_enemy = enemy;
     Lifetime = lifetime;
     m_position = Position = position;
     m_speed = speed;
     m_velocity = direction * m_speed;
     m_damage = damage;
     switch(type)
     {
         case Type.Gun:
             TypeofProj = type;
             m_sprite = Art.ProjectileGun;
             m_center = new Vector2(m_sprite.Width / 2, m_sprite.Height / 2);
             Radius = m_sprite.Width / 2;
             break;
         case Type.Rocket:
             TypeofProj = type;
             m_sprite = Art.ProjectileRocket;
             m_center = new Vector2(m_sprite.Width / 2, m_sprite.Height / 2);
             Radius = m_sprite.Width / 2;
             break;
         case Type.SAM:
             TypeofProj = type;
             m_sprite = Art.ProjectileSAM;
             m_center = new Vector2(m_sprite.Width / 2, m_sprite.Height / 2);
             Radius = m_sprite.Width / 2;
             break;
         case Type.Tesla:
             TypeofProj = type;
             m_sprite = Art.ProjectileTesla;
             m_center = new Vector2(m_sprite.Width / 2, m_sprite.Height / 2);
             Radius = m_sprite.Width / 2;
             break;
     }
 }
Ejemplo n.º 4
0
        public void Shoot(Enemy targetEnemy)
        {
            Quaternion aimQuat = Quaternion.CreateFromYawPitchRoll(0, 0, Rotation);
            Vector2 offset = Vector2.Transform(new Vector2(25, -16), aimQuat);

            if(TowerType != "Tesla")
                 Sound.GunShot.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, (float)GameManager.rnd.NextDouble(), 0f);
            
            if (GameManager.rnd.Next(1, 50) == 1) // misfire
            {
                if (TowerType != "Tesla")
                    Health -= 2;
                else Health -= 1;
                PopUpTextManager.Add(new PopUpText(PopUpTextManager.Misfire, Position, Color.Red));
            }

            else
            {
                switch (TypeofTower)
                {
                    case Type.Gun:
                        // Quaternion FTW. Used to Transform offset so bullets spawn correctly even as tower rotates.

                        // Aesthetically pleasing, but fuuuu...
                        if (Level == 1)
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        else if (Level == 2)
                        {
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 16), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else if (Level == 3)
                        {
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 16), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 0), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else
                        {
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 16), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        break;
                    case Type.Rocket:
                        if (Level == 1)
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        else if (Level == 2)
                        {
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 16), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else if (Level == 3)
                        {
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 16), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 0), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else
                        {
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 16), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        break;
                    case Type.SAM:
                        if (Level == 1)
                        {
                            offset = Vector2.Transform(new Vector2(25, -8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -4), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else if (Level == 2)
                        {
                            offset = Vector2.Transform(new Vector2(25, -8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -4), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 4), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else if (Level == 3)
                        {
                            offset = Vector2.Transform(new Vector2(25, -10), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -2), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 2), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 10), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        else
                        {
                            offset = Vector2.Transform(new Vector2(25, -10), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -6), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, -4), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 4), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 6), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 8), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                            offset = Vector2.Transform(new Vector2(25, 10), aimQuat);
                            TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage));
                        }
                        break;
                    case Type.Tesla:
                        TowerProjectiles.Add(new Projectile(Projectile.Type.Tesla, targetEnemy, Position, Rotation.ToVector(), 1f, Damage));
                        break;
                }
            }
        }
Ejemplo n.º 5
0
        static float Resist(Enemy enemy)
        {
            float ResistValue = rnd.Next(1, (int)enemy.resistance);

            return ResistValue / 10;
        
        }
Ejemplo n.º 6
0
        static float Critical(Enemy enemy)
        {
            int CriticalValue = rnd.Next(1, 101);

            if (CriticalValue < enemy.criticalResist)
                return 0;

            else return 2;

        }
Ejemplo n.º 7
0
        static float TotalDamageCrunch(float baseDam, float resistedDam, Enemy enemy, ref string text, ref Color textColour)
        {
            float totalDamage;
            float critical;

            totalDamage = baseDam - resistedDam;

            critical = Critical(enemy);

            totalDamage += totalDamage * critical;

            if (critical != 0)
            {
                text += " " + PopUpTextManager.Critical;
            }

            if (totalDamage == 0)
            {
                text += " " + PopUpTextManager.NoEffect;
                textColour = Color.Red;

            }

            return totalDamage;
        }
Ejemplo n.º 8
0
        //damage stuffs
        public static float DamageCalculator(float Damage, Enemy enemy, Projectile.Type projectile)
        {
            float totalDamage = 0f;
            float resistedDamage;
            float baseDmg = Damage;
            Projectile.Type proj = projectile;
            string enemyType = enemy.EnemyType;

            Color textColour = Color.Black;
            string popUpText = "";

            resistedDamage = Resist(enemy );

 
                if (enemyType == "Soldier")
                {
                    if (projectile == Projectile.Type.Gun)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 2;
                        popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString();
                    }

                    else if (projectile == Projectile.Type.Tesla)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour);
                        popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString();
                    }

                    else
                    {
                        textColour = Color.Yellow;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 2;
                        popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString();
                    }
                }

                else if (enemyType == "Tank")
                {
                    if (projectile == Projectile.Type.Rocket)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 2;
                        popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString();
                    }

                    else if (projectile == Projectile.Type.Tesla)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour);
                        popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString();
                    }

                    else
                    {
                        textColour = Color.Yellow;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 4;
                        popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString();
                    }
                }

                else if (enemyType == "Helicopter")
                {
                    if (projectile == Projectile.Type.SAM)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 2;
                        popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString();
                    }

                    else if (projectile == Projectile.Type.Tesla)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour);
                        popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString();
                    }

                    else
                    { 
                        textColour = Color.Yellow;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 2;
                        popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString();
                    }

                }

                else if (enemyType == "Jeep")
                {
                    if (projectile == Projectile.Type.Rocket)
                    { 
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 4;
                        popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString();
                    }

                    else if (projectile == Projectile.Type.Tesla)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour);
                        popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString();
                    }

                    else
                    {
                        textColour = Color.Yellow;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 2;
                        popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString();
                    }
                }

                else if (enemyType == "Transport")
                {
                    if (projectile == Projectile.Type.Rocket)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 3;
                        popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString();
                    }

                    else if (projectile == Projectile.Type.Tesla)
                    {
                        textColour = Color.DarkKhaki;
                        totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour);
                        popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString();
                    }

                    else
                    {
                        
                        textColour = Color.Yellow;
                        totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 3;
                        popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString();
                    }

                }
            


            PopUpTextManager.Add(new PopUpText(popUpText, enemy.ScreenPos, textColour));

            return totalDamage;
        }
Ejemplo n.º 9
0
 public static void EnemyDamaged(float Damage, Enemy enemy, Projectile.Type projectile)
 {
     enemy.hitPoints -= GameManager.DamageCalculator(Damage, enemy, projectile);
 }
Ejemplo n.º 10
0
 static void Shoot(Tower TargetTower, Enemy enemy, Vector2 Direction)
 {
     Quaternion aimQuat = Quaternion.CreateFromYawPitchRoll(0, 0, Rotation);
     Vector2 offset = Vector2.Transform(new Vector2(35, 0), aimQuat);
     EnemyProjectiles.Add(new Projectile(Projectile.Type.Gun, TargetTower, enemy.ScreenPos, Direction, 1f, 2));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Removes enemy from listener. Shouldnt have to be called manually,  should be automted.
 /// </summary>
 /// <param name="EnemyID"></param>
 static public void RemoveEnemy(Enemy EnemyID)
 {
     EnemyList.Remove(EnemyID);
        
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Add enemies to listener, for towers to interact with them
 /// </summary>
 /// <param name="Enemy"></param>
  public static void AddEnemy(Enemy Enemy) 
  {
      EnemyList.Add(Enemy);
  }