Beispiel #1
0
        // If player is not dead, update
        public void Update(GameTime gameTime)
        {
            playerShots.Update(gameTime);

            if (player.dead == false)
            {
                player.Velocity = Vector2.Zero;

                player.shotTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                HandleKeyboardInput(Keyboard.GetState());

                // Normalize is used to ensure a vector length of 1 in all conditions
                // If not normalized, when the player has both up/down and left/right
                // A vector length of 1.4 would result...moving faster diagonally (unwanted behaviour)
                // Normalize = vector/vector.length = length of one
                // Physics and shit
                player.Velocity.Normalize();

                switch (velocitySelection)
                {
                case VelocitySelection.Slow:
                    player.Velocity *= player.moveSpeed / 2;
                    break;

                case VelocitySelection.Fast:
                    player.Velocity *= player.moveSpeed;
                    break;
                }

                player.Update(gameTime);
                enforceBounds();
            }
        }
Beispiel #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);
            }
        }