Exemple #1
0
 // If the min ammount of time since last shot has expired, allow player to fire a projectile
 private void SendShotRequest()
 {
     if (player.shotTimer >= player.minShotTimer)
     {
         playerShots.FireShot(
             player.Location + player.shotOffset,
             new Vector2(0, -1),
             true);
         player.shotTimer = 0.0f;
     }
 }
Exemple #2
0
        // Update method for enemy objects
        public void Update(GameTime gameTime)
        {
            EnemyShots.Update(gameTime);

            for (int x = Enemies.Count - 1; x >= 0; x--)
            {
                Enemies[x].Update(gameTime);

                // If enemy is no longer active remove from enemies list
                if (Enemies[x].IsActiveCheck() == false)
                {
                    Enemies.RemoveAt(x);
                }
                // Else, begin projectile firing protocol
                else
                {
                    // Randomized fire shot for enemies
                    if ((float)rand.Next(0, 1000) / 10 <= Enemies[x].enemyShotRate)
                    {
                        Vector2 fireLoc = Enemies[x].Location;
                        fireLoc += Enemies[x].shotOffset;
                        Vector2 shotDirection;
                        // Enemies will fire in the direction of the player
                        switch (Enemies[x].Type)
                        {
                        //type 0: grunt 1
                        //type 1: grunt 2
                        //type 2: midboss
                        case 0:
                            shotDirection = playerFactory.player.Center - fireLoc;
                            shotDirection.Normalize();
                            EnemyShots.FireShot(fireLoc, shotDirection, false);
                            break;

                        case 1:
                            shotDirection = new Vector2(0, 1);
                            shotDirection.Normalize();
                            EnemyShots.FireShot(fireLoc, shotDirection, false);
                            break;

                        case 2:
                            shotDirection = new Vector2(0, 1);
                            EnemyShots.FireTriangle(fireLoc);

                            //shotDirection = playerFactory.player.Center - fireLoc;
                            //shotDirection.Normalize();
                            //EnemyShots.FireShot(fireLoc, shotDirection, false);
                            break;
                        }

                        // Normalize vector for constant projectile speed in all directions


                        //Create new projectile and add to List
                    }
                }
            }
            // If level is still active, update.
            if (Active)
            {
                updateWaveSpawns(gameTime);
            }
        }