Beispiel #1
0
        /// <summary>
        /// Checks if target is out of range, handles reload timer, rotates tower towards target and calls Fire function
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="level"></param>
        public virtual void Update(GameTime gameTime, Level level)
        {
            if (target != null)
            {
                if (Vector2.Distance(position, target.projTargetPosition) > range)
                {
                    target = null;
                }
            }

            if (!readyToFire)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (timer >= reloadTime)
                {
                    readyToFire = true;
                }
            }

            if (target != null)
            {
                direction = target.projTargetPosition - position;
                direction.Normalize();
                rotationAngle = (float)Math.Atan2(direction.Y, direction.X);
                if (readyToFire && target.CurrentHealth > 0)
                {
                    Fire(level);
                }

                if (target.CurrentHealth <= 0)
                {
                    target = null;
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Projectile is created after a Tower shot
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="explosionTexture"></param>
 /// <param name="speed"></param>
 /// <param name="damage"></param>
 /// <param name="hasSplash"></param>
 /// <param name="position"></param>
 /// <param name="target"></param>
 /// <param name="canSlow"></param>
 /// <param name="level"></param>
 public Projectile(Texture2D texture, Texture2D explosionTexture, float speed, float damage, bool hasSplash, Vector2 position, Enemys target, bool canSlow, Level level)
 {
     this.texture          = texture;
     this.explosionTexture = explosionTexture;
     this.speed            = speed;
     this.damage           = damage;
     this.hasSplash        = hasSplash;
     this.position         = position;
     this.target           = target;
     this.canSlow          = canSlow;
     this.level            = level;
     hit                   = false;
     speedModifier         = 0.5f;
     speedModifierDuration = 1.9f;
     rotationCenter        = new Vector2(texture.Width / 2, texture.Height / 2);
 }
Beispiel #3
0
        /// <summary>
        /// Spawns enemys until the desired number of enemys is spawned
        /// </summary>
        /// <param name="texture"></param>
        private void SpawnEnemy(Texture2D texture)
        {
            Enemys enemy = new Enemys(player, texture, spawnPosition, enemyLife, enemyBounty, enemySpeed, graphicsDevice);

            enemy.SetWaypoints(level.Waypoints);
            level.AddEnemy(enemy);
            countEnemys++;
            timerEnemys = 0;
            if (countEnemys >= nrToSpawn)
            {
                countEnemys    = 0;
                spawnNewEnemys = false;
                timerWaves     = 0;
                stopTimer      = false;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Checks if an Enemy is insider an Explosion
        /// </summary>
        /// <param name="enemy"></param>
        public void CheckIfInsideExplosion(Enemys enemy)
        {
            if (hasSplash)
            {
                if (enemy.Position.X < pos.X + texture.Width &&
                    enemy.Position.X > pos.X - texture.Height &&
                    enemy.Position.Y < pos.Y + texture.Height &&
                    enemy.Position.Y > pos.Y - texture.Height)
                {
                    enemy.CurrentHealth -= damage;

                    if (canSlow)
                    {
                        enemy.SpeedModifier    = speedModifier;
                        enemy.ModifierDuration = speedModifierDuration;
                    }
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Add enemy to the list enemyList.
 /// </summary>
 /// <param name="enemys"></param>
 public void AddEnemy(Enemys enemys)
 {
     enemyList.Add(enemys);
 }