Exemplo n.º 1
0
        void checkIfIAmShot()
        {
            Rectangle r    = shooter.getBoundingBoxAA();
            int       temp = targets.collisionWithRect(r);

            if (temp == -1)
            {
                return;
            }
            Sprite3 s = targets.getSprite(temp);

            makeExplosion(shooter.getPos());
            makeExplosion(s.getPos());
            adjustScore(scoreIfPlayerHit, s.getPosX(), s.getPosY());
            s.active  = false;
            s.visible = false;
            //shooter.visible = false;
            lives   = lives - 1;
            mgState = 2;
            timeIn2 = 0;
            if (lives <= 0)
            {
                mgState = 4;
            }
        }
Exemplo n.º 2
0
        public override void LoadContent()
        {
            // Load Textures
            continueTex  = Content.Load <Texture2D>("Textures/Menu/Continue");
            optionsTex   = Content.Load <Texture2D>("Textures/Menu/Options");
            howToPlayTex = Content.Load <Texture2D>("Textures/Menu/HowToPlay");
            exitTex      = Content.Load <Texture2D>("Textures/Menu/Exit");
            titleTex     = Content.Load <Texture2D>("Textures/Menu/Title");
            triangleTex  = Content.Load <Texture2D>("Textures/Menu/TriangleMan");
            newgameTex   = Content.Load <Texture2D>("Textures/Menu/NewGame");
            hexagonTex   = Content.Load <Texture2D>("Textures/Menu/HexagonGuy");

            // Create sprites for title and display characters
            sTitle    = new Sprite3(true, titleTex, 0, 0);
            sTriangle = new Sprite3(true, triangleTex, 0, 0);

            // Set sprite offsets
            sTitle.setHSoffset(new Vector2(titleTex.Width / 2, titleTex.Height / 2));
            sTriangle.setHSoffset(new Vector2(triangleTex.Width / 2, triangleTex.Height / 2));

            // Set Position of Sprites
            sTitle.setPos(new Vector2(xAligned, 0 + sTitle.getHeight()));
            sTriangle.setPos(675, 275);

            buttonNewGame   = new Button(newgameTex, new Vector2(xAligned, (95 + sTitle.getPosY()) + (newgameTex.Height)), Resources.ColorHighLight, Button.ButtonType.ResetGame, 0);
            buttonContinue  = new Button(continueTex, new Vector2(xAligned, buttonNewGame.getPosY() + (minorOffset + continueTex.Height)), Resources.ColorHighLight, Button.ButtonType.ChangeLevelSet, Resources.currPlayLevel);
            buttonOptions   = new Button(optionsTex, new Vector2(xAligned, buttonContinue.getPosY() + (minorOffset + optionsTex.Height)), Resources.ColorHighLight, Button.ButtonType.ChangeLevelSet, 5);
            buttonHowToPlay = new Button(howToPlayTex, new Vector2(xAligned, buttonOptions.getPosY() + (minorOffset + howToPlayTex.Height)), Resources.ColorHighLight, Button.ButtonType.ChangeLevelPush, 8);
            buttonExit      = new Button(exitTex, new Vector2(xAligned, buttonHowToPlay.getPosY() + (minorOffset + exitTex.Height)), Resources.ColorHighLight, Button.ButtonType.Exit, 0);
            buttonHighScore = new Button(hexagonTex, new Vector2(135, 339), Resources.ColorLose, Button.ButtonType.ChangeLevelSet, 13);
        }
 public void Update(GameTime _gameTime)
 {
     if (parent == null)
     {
         rectGoalZone = new Rectangle((int)position.X, (int)position.Y, (int)zoneWidth, (int)zoneHeight);
     }
     else
     {
         rectGoalZone = new Rectangle((int)parent.getPosX(), (int)parent.getPosY() - 70, (int)parent.getWidth(), 70);
     }
 }
Exemplo n.º 4
0
        public void Follow(Sprite3 target)
        {
            var position = Matrix.CreateTranslation(
                -target.getPosX() - (target.getWidth() / 2),
                -target.getPosY() - (target.getHeight() / 2),
                0);

            var offset = Matrix.CreateTranslation(
                Game1.screenWidth / 2,
                Game1.screenHeight / 2,
                0);

            Transform = position * offset;
        }
Exemplo n.º 5
0
        void fire()
        {
            if (mgState != 1 && mgState != 3)
            {
                return;
            }

            for (int i = 0; i < shotsMax; i++)
            {
                if (bullets[i].X == 0)
                {
                    bullets[i].X = shooter.getPosX() + shooterShellOffset.X;
                    bullets[i].Y = shooter.getPosY() + shooterShellOffset.Y + 1 - shotLength;
                    break;
                }
            }
        }
Exemplo n.º 6
0
 void moveBullets()
 {
     for (int i = 0; i < shotsMax; i++)
     {
         if (bullets[i].X != 0)
         {
             //bullets[i].X = shooter.getPosX() + shooterShellOffset.X;
             bullets[i].Y = bullets[i].Y - bulletSpeed;
             if (bullets[i].Y < innerRectangle.Y - shotLength)
             {
                 bullets[i].X = 0;
             }
         }
         if (bullets[i].X != 0)
         {
             // check for collision
             int tt = targets.pointInList(bullets[i]);
             if (tt == -1)
             {
                 tt = targets.pointInList(bullets[i] + new Vector2(0, shotLength));
             }
             if (tt != -1)
             {
                 Sprite3 s = targets.getSprite(tt);
                 makeExplosion(s.getPos());
                 s.visible = false;
                 s.active  = false;
                 adjustScore(scoreIfTargetHit, s.getPosX(), s.getPosY());
                 if (!shootThrough)
                 {
                     bullets[i].X = 0;              // remove bullet
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
        public override void Update(GameTime gameTime)
        {
            ticks++;

            //load animation
            //anmiation1.animationTick();
            dragonList.animationTick();
            if (scrolling1.rectangle.X + scrolling1.texture.Width <= 0)
            {
                scrolling1.rectangle.X = scrolling2.rectangle.X + scrolling2.texture.Width;
            }
            if (scrolling2.rectangle.X + scrolling2.texture.Width <= 0)
            {
                scrolling2.rectangle.X = scrolling1.rectangle.X + scrolling1.texture.Width;
            }

            scrolling1.Update();
            scrolling2.Update();

            for (int i = 0; i < dragonList.count(); i++)
            {
                Sprite3 s = dragonList.getSprite(i);
                if (s == null)
                {
                    continue;
                }
                if (!s.active)
                {
                    continue;
                }
                if (!s.visible)
                {
                    continue;
                }
                if (ball.getBoundingBoxAA().Intersects(s.getBoundingBoxAA()))
                {
                    baz.Play();
                    s.setActive(false);
                    scoure++;
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                    setSys5();
                    p.Update(gameTime);
                }
            }

            if (k.IsKeyDown(Keys.B) && prevK.IsKeyUp(Keys.B)) // ***
            {
                showbb = !showbb;
            }
            k = Keyboard.GetState();

            if (k.IsKeyDown(Keys.Right))
            {
                if (paddle.getPosX() < rhs - texpaddle.Width)
                {
                    paddle.setPosX(paddle.getPosX() + paddleSpeed);
                }
            }

            if (k.IsKeyDown(Keys.Left))
            {
                if (paddle.getPosX() > lhs)
                {
                    paddle.setPosX(paddle.getPosX() - paddleSpeed);
                }
            }

            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
            }

            //if (ballStuck)
            //{
            //    ball.setPos(paddle.getPos() + ballOffset);
            //    if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
            //    {
            //        ballStuck = false;
            //        ball.setDeltaSpeed(new Vector2(1, -3));
            //    }
            //}
            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
            }

            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
                if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
                {
                    ballStuck = false;
                    ball.setDeltaSpeed(new Vector2(2, -3));
                }
            }
            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
                Rectangle ballbb = ball.getBoundingBoxAA();

                if (ballbb.X + ballbb.Width > rhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.X < lhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.Y < top)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }

                //pedal intersects

                if (ballbb.Intersects(paddle.getBoundingBoxAA()))

                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }
            }
            if (k.IsKeyDown(Keys.P))
            {
                gameStateManager.setLevel(0);
            }
            if (k.IsKeyDown(Keys.M))
            {
                gameStateManager.setLevel(0);
                ball.setPos(xx, yy);
                paddle.setPos(xx, bot - texpaddle.Height);
                scoure = 0;
                //ball.setDeltaSpeed(new Vector2(0,0));
                for (int i = 0; i < dragonList.count(); i++)
                {
                    Sprite3 s = dragonList.getSprite(i);
                    s.setActive(true);
                }
            }


            if (ball.getPosY() > bot)
            {
                gameStateManager.setLevel(5);
                ball.setPos(xx, yy);
                paddle.setPos(xx, bot - texpaddle.Height);
                scoure = 0;
                //ball.setDeltaSpeed(new Vector2(0,0));
                for (int i = 0; i < dragonList.count(); i++)
                {
                    Sprite3 s = dragonList.getSprite(i);
                    s.setActive(true);
                    // p.Update(gameTime);
                }
            }
            // next leve condition
            if (scoure >= 15)
            {
                gameStateManager.setLevel(0);
                limSound.playSound();
            }
            ballPos = new Vector2(ball.getPosX(), ball.getPosY());
            if (p != null)
            {
                p.Update(gameTime);
            }
            base.Update(gameTime);
        }
Exemplo n.º 8
0
 public float getPosY()
 {
     return(button.getPosY());
 }
Exemplo n.º 9
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// This is a mess, please forgive me
        protected override void Update(GameTime gameTime)
        {
            //Console.WriteLine(enemies.count());
            curPos = horse.getPos();
            bool keyDown = false;

            switch (level)
            {
            case 1:
                horse.setWidthHeight(1568 / 8 * 0.3f, texHorseRun.Height * 0.3f);
                k = Keyboard.GetState();
                if (!started)
                {
                    started = true;
                    StartMovement(8);
                }

                if (k.IsKeyDown(Keys.Down))
                {
                    keyDown = true;
                    horse.setPosY(horse.getPosY() + movementSpeed - 2);
                }

                if (k.IsKeyDown(Keys.Up))
                {
                    keyDown = true;
                    horse.setPosY(horse.getPosY() - movementSpeed + 2);
                }

                if (k.IsKeyDown(Keys.Left))
                {
                    keyDown = true;
                    horse.setFlip(SpriteEffects.FlipHorizontally);
                    horse.setPosX(horse.getPosX() - movementSpeed + 2);
                }

                if (k.IsKeyDown(Keys.Right))
                {
                    keyDown = true;
                    horse.setFlip(SpriteEffects.None);
                    horse.setPosX(horse.getPosX() + movementSpeed - 2);
                }
                if (!keyDown)
                {
                    horse.setAnimationSequence(anim, 0, 7, 0);
                }
                else
                {
                    horse.setAnimationSequence(anim, 0, 7, 8);
                }
                //387 330
                if (curPos.X >= -155 && curPos.X <= -75 && curPos.Y >= 330 && curPos.Y <= 387)
                {
                    horse.setPos(xx, yy);
                    started = false;
                    horse.setFlip(SpriteEffects.None);
                    level = 0;
                }

                horseRun.animationTick(gameTime);
                mainCamera.Follow(horse);

                break;

            default:
                if (!started)
                {
                    if (k.IsKeyDown(Keys.D1) || k.IsKeyDown(Keys.NumPad1))
                    {
                        difficulty = 1;
                    }
                    else if (k.IsKeyDown(Keys.D2) || k.IsKeyDown(Keys.NumPad2))
                    {
                        difficulty = 2;
                    }
                    else if (k.IsKeyDown(Keys.D3) || k.IsKeyDown(Keys.NumPad3))
                    {
                        difficulty = 3;
                    }
                }
                switch (difficulty)
                {
                case 1:
                    difficultyOffset = 1;
                    break;

                case 2:
                    difficultyOffset = 0.5f;
                    break;

                case 3:
                    difficultyOffset = 0.1f;
                    break;

                default:
                    break;
                }
                horse.setWidthHeight(1568 / 8 * 0.5f, texHorseRun.Height * 0.5f);
                //This timer makes basic instructions disappear after 3 seconds
                if (textFadeTimer < 3 && started)
                {
                    textFadeTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                if (started)
                {
                    enemySpawnTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (enemySpawnTimer > difficultyOffset)
                {
                    enemySpawnTimer = 0;
                    LoadEnemies();
                }

                //Escape key exits game
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    Exit();
                }

                //Keyboard current and previous state
                prevK = k;
                k     = Keyboard.GetState();

                //Begin all game functionality essentially
                if (k.IsKeyDown(Keys.Enter) && !started)
                {
                    started = true;
                    StartMovement(8);
                }

                if (started)
                {
                    //Bounding box activation key
                    if (k.IsKeyDown(Keys.B) && prevK.IsKeyUp(Keys.B))
                    {
                        showbb = !showbb;
                    }

                    //Game over is a bool that is used to ensure the player can't move horse after it is dead, causes errors otherwise
                    if (!gameOver)
                    {
                        //Player movement down
                        if (k.IsKeyDown(Keys.Down))
                        {
                            if (horseRun.getSprite(0).getPosY() < bot - horse.getHeight())
                            {
                                horseRun.getSprite(0).setPosY(horseRun.getSprite(0).getPosY() + movementSpeed);
                            }
                        }
                        //Player movement up
                        if (k.IsKeyDown(Keys.Up))
                        {
                            if (horseRun.getSprite(0).getPosY() > top)
                            {
                                horseRun.getSprite(0).setPosY(horseRun.getSprite(0).getPosY() - movementSpeed);
                            }
                        }
                    }

                    for (int e = 0; e < enemies.count(); e++)
                    {
                        if (enemies[e].getVisible())
                        {
                            enemies[e].setPosX(enemies[e].getPosX() - enemyMovementSpeed);
                        }
                        if (enemies[e].getPosX() < 0 - texEnemy.Width)
                        {
                            enemies[e].setVisible(false);
                        }
                    }

                    //Collision detection, arrow to enemy
                    for (int ea = 0; ea < quiver.count(); ea++)
                    {
                        int ac = enemies.collisionWithRect(quiver[ea].getBoundingBoxAA());
                        if (ac != -1)
                        {
                            score++;
                            Blood(enemies.getSprite(ac).getPosX(), enemies.getSprite(ac).getPosY(), false);
                            enemies.getSprite(ac).setVisible(false);
                            quiver[ea].setVisible(false);
                            quiver[ea].setPos(new Vector2(0, 0));
                            //LoadEnemies();
                        }
                    }


                    //Allow player to increase or decrease speed
                    if (Keyboard.GetState().IsKeyDown(Keys.Right))
                    {
                        enemyMovementSpeed = fastEnemy;
                        horse.setAnimationSequence(anim, 0, 7, fastPlayer);
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Left))
                    {
                        enemyMovementSpeed = slowEnemy;
                        horse.setAnimationSequence(anim, 0, 7, slowPlayer);
                    }
                    else if (started)
                    {
                        enemyMovementSpeed = normalEnemy;
                        horse.setAnimationSequence(anim, 0, 7, normalPlayer);
                    }

                    //Scrolling background functionality
                    if (scrolling1.rectangle.X + scrolling1.texture.Width <= 0)
                    {
                        scrolling1.rectangle.X = scrolling2.rectangle.X + scrolling2.texture.Width;
                    }
                    if (scrolling2.rectangle.X + scrolling2.texture.Width <= 0)
                    {
                        scrolling2.rectangle.X = scrolling1.rectangle.X + scrolling1.texture.Width;
                    }
                    scrolling1.Update();
                    scrolling2.Update();

                    //Game over is a bool that is used to ensure the player can't move horse after it is dead, causes errors otherwise
                    if (!gameOver)
                    {
                        //Collision detection, enemy to player
                        int rc = enemies.collisionWithRect(horse.getBoundingBoxAA());
                        if (rc != -1)
                        {
                            Blood(horse.getPosX(), horse.getPosY(), true);
                            movementSpeed      = 0;
                            enemyMovementSpeed = 0;
                            scrolling1.speed   = 0;
                            scrolling2.speed   = 0;
                            for (int i = 0; i < horseRun.count(); i++)
                            {
                                horseRun.deleteSprite(i);
                            }
                            gameOver = true;
                        }
                    }

                    //Shooting arrow functionality
                    if (Keyboard.GetState().IsKeyDown(Keys.Space) && !arrowShot)
                    {
                        Arrow();
                        arrowShot = true;
                    }
                    for (int a = 0; a < quiver.count(); a++)
                    {
                        if (quiver[a].getVisible())
                        {
                            quiver[a].savePosition();
                            quiver[a].moveByDeltaXY();
                        }
                        if (quiver[a].getPosX() > 800)
                        {
                            quiver[a].setVisible(false);
                        }
                    }
                    if (arrowShot)
                    {
                        arrowTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    if (arrowTimer > 0.5f)
                    {
                        arrowTimer = 0;
                        arrowShot  = false;
                    }
                }

                //Animation ticks for anything that is being animated
                horseRun.animationTick(gameTime);
                enemies.animationTick(gameTime);
                bloodSplat.animationTick(gameTime);

                if (gameOver)
                {
                    deathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                break;
            }
            base.Update(gameTime);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here
            InputManager.Instance.Update();



            //deltaTime is in seconds, so calculations = pixels per second.
            deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Press enter to start game/level
            if (!startGame)
            {
                if (InputManager.Instance.KeyPressed(Keys.Enter))
                {
                    startGame = true;
                }


                return;
            }

            timer += deltaTime;

            //update player
            spritePlayer.Update(gameTime);

            //update backgrounds
            scrollBack.Update(gameTime);
            scrollFore.Update(gameTime);
            scrollBack.setScrollSpeed(playerSpeeeeeed - 2);
            scrollFore.setScrollSpeed(playerSpeeeeeed);

            //limit scroll speed
            if (playerSpeeeeeed > -1)
            {
                playerSpeeeeeed = -1;
            }
            else if (playerSpeeeeeed < -10)
            {
                playerSpeeeeeed = -10;
            }

            //Every 2 seconds, spawn an enemy randomly.
            if (timer > spawnInterval)
            {
                AddEnemy(enemyList);
                timer = 0;
            }

            //inputs
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (InputManager.Instance.KeyPressed(Keys.B))
            {
                showbb = !showbb;
            }

            //PLAYER MOVEMENT
            if (InputManager.Instance.KeyDown(Keys.Left))
            {
                if (spritePlayer.getPosX() > playArea.Left)
                {
                    spritePlayer.setPosX(spritePlayer.getPosX() - playerSpeed);
                }
                playerSpeeeeeed += 0.1f;
            }
            if (InputManager.Instance.KeyDown(Keys.Right))
            {
                if (spritePlayer.getPosX() < playArea.Right - spritePlayer.getWidth())
                {
                    spritePlayer.setPosX(spritePlayer.getPosX() + playerSpeed);
                }
                playerSpeeeeeed += -0.1f;
            }
            if (InputManager.Instance.KeyDown(Keys.Up))
            {
                if (spritePlayer.getPosY() > playArea.Bottom)
                {
                    spritePlayer.setPosY(spritePlayer.getPosY() - playerSpeed);
                }
            }
            if (InputManager.Instance.KeyDown(Keys.Down))
            {
                if (spritePlayer.getPosY() < playArea.Top - spritePlayer.getHeight())
                {
                    spritePlayer.setPosY(spritePlayer.getPosY() + playerSpeed);
                }
            }
            //PLAYER SHOOT
            if (InputManager.Instance.KeyPressed(Keys.Space))
            {
                AddBullet((int)spritePlayer.getPosX(), (int)spritePlayer.getPosY());
            }

            //Update all enemies and bullets to move. also inactive if outofbounds
            //In the past I called this instead of having an extended class with custom update
            // enemyList.moveDeltaX(-3);


            //Update/remove enemies
            enemyList.Update(gameTime);
            enemyList.removeIfOutside(new Rectangle(-100, -100, SCREEN_WIDTH + 200, SCREEN_HEIGHT + 200));

            //update/remove bullets
            playerBulletList.moveDeltaX(5);
            playerBulletList.removeIfOutside(new Rectangle(-100, -100, SCREEN_WIDTH + 200, SCREEN_HEIGHT + 200));



            //If player collides with enemy
            int collisionIndex = enemyList.collisionAA(spritePlayer);

            if (collisionIndex != -1)
            {
                Sprite3 temp = enemyList.getSprite(collisionIndex);
                //player collides with boss
                if (temp.getName() == "boss")
                {
                }
                else
                {
                    //enemy dies?
                    temp.active  = false;
                    temp.visible = false;
                    AddExplosion((int)temp.getPosX(), (int)temp.getPosY());
                    score         -= 5;
                    textScore.text = "Score : " + score.ToString();
                }
            }

            //if a bullet collides with enemy
            for (int i = 0; i < playerBulletList.count(); i++)
            {
                Sprite3 currentBullet = playerBulletList.getSprite(i);
                if (currentBullet == null)
                {
                    continue;
                }
                if (currentBullet.active != true)
                {
                    continue;
                }
                if (currentBullet.visible != true)
                {
                    continue;
                }

                //if collision success
                int collision = enemyList.collisionAA(currentBullet);
                if (collision != -1)
                {
                    Sprite3 currentEnemy = enemyList.getSprite(collision);

                    //kill both enemy and bullet
                    currentEnemy.active   = false;
                    currentEnemy.visible  = false;
                    currentBullet.active  = false;
                    currentBullet.visible = false;

                    //add particle
                    AddExplosion((int)currentEnemy.getPosX(), (int)currentEnemy.getPosY());

                    //add score
                    score         += 10;
                    textScore.text = "Score : " + score.ToString();
                }
            }

            //update particles
            particleList.animationTick(gameTime);



            base.Update(gameTime);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            prevK = k;
            k     = Keyboard.GetState();

            delTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            redTimer += delTime;

            timer += delTime;



            if ((timer > (float)spawnTimer))
            {
                NewEnemy(enemyXX, bot - texEnemy.Height);
                timer = 0;
            }



            back1.Update(gameTime);
            grass1.Update(gameTime);



            //player collision
            int plCol = enemyList.collisionAA(paddle);



            if (plCol != -1)
            {
                Sprite3 temp = enemyList.getSprite(plCol);
                createExplosion((int)temp.getPosX(), (int)temp.getPosY());
                temp.active  = false;
                temp.visible = false;
                score       += 1;

                if (spawnTimer > 1)
                {
                    spawnTimer -= 1;
                }

                else
                {
                    spawnTimer = 1;
                }
            }

            for (int j = 0; j < enemyList.count(); j++)
            {
                Sprite3 currentEnemy = enemyList.getSprite(j);

                currentEnemy.varInt0 += delTime;
                float prevPosX = currentEnemy.getPosX();
                if (currentEnemy.varInt0 > 0.2f)
                {
                    currentEnemy.setColor(Color.White);
                    //redTimer = 0;
                    currentEnemy.setPosX(prevPosX);
                    currentEnemy.varInt0 = 0;
                }
            }


            for (int i = 0; i < ballList.count(); i++)
            {
                Sprite3 tempBullet    = ballList.getSprite(i);
                int     enemyCollided = enemyList.collisionAA(tempBullet);



                if (enemyCollided != -1)
                {
                    Sprite3 tempEnemy = enemyList.getSprite(enemyCollided);

                    tempBullet.active  = false;
                    tempBullet.visible = false;


                    tempEnemy.setColor(Color.Red);
                    tempEnemy.setPosX(tempEnemy.getPosX() + 10);



                    tempEnemy.hitPoints -= 1;



                    if (tempEnemy.hitPoints < 1)
                    {
                        createExplosion((int)tempBullet.getPosX(), (int)tempBullet.getPosY());
                        tempEnemy.active  = false;
                        tempEnemy.visible = false;
                        score            += 1;

                        if (spawnTimer > 1)
                        {
                            spawnTimer -= 1;
                        }

                        else
                        {
                            spawnTimer = 1;
                        }
                    }
                }
            }



            enemyList.moveDeltaXY();
            enemyList.removeIfOutside(playArea);
            ballList.moveDeltaXY();
            ballList.removeIfOutside(playArea);



            if (k.IsKeyDown(Keys.Left))
            {
                scrollSpeed = 0.5f;
                back1.setScrollSpeed(scrollSpeed);
                grass1.setScrollSpeed(1);
            }


            if (k.IsKeyDown(Keys.Up))
            {
                if (paddle.getPosY() > top + 1)
                {
                    paddle.setPosY(paddle.getPosY() - paddleSpeed);
                }
            }

            else if (k.IsKeyDown(Keys.Down))
            {
                //if (paddle.getPosY() < ((bot- top) - (texpaddle.Height + 2))) paddle.setPosY(paddle.getPosY() + paddleSpeed);
                if (paddle.getPosY() <= playArea.Height - texpaddle.Height + 7)
                {
                    paddle.setPosY(paddle.getPosY() + paddleSpeed);
                }
            }

            else if (k.IsKeyDown(Keys.Right))
            {
                scrollSpeed = -1;
                back1.setScrollSpeed(scrollSpeed);
                grass1.setScrollSpeed(-30);
            }
            else if (k.IsKeyDown(Keys.Left))
            {
                scrollSpeed = 0.5f;
                back1.setScrollSpeed(scrollSpeed);
                grass1.setScrollSpeed(1);
            }



            if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
            {
                NewBall(xx, yy);
            }
            if (k.IsKeyDown(Keys.B) && prevK.IsKeyUp(Keys.B)) // ***
            {
                showbb = !showbb;
            }



            booms.animationTick(gameTime);
            base.Update(gameTime);
        }
Exemplo n.º 12
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //MOVEMENT
            //ALL CHECKS AND CHANGES BEFORE THE POSITION SET.

            //PLAYER SLICE COOLDOWN
            if (canSlice == false)
            {
                sliceTimer += deltaTime;
            }

            if (sliceTimer > sliceCooldown)
            {
                sliceTimer        = 0;
                canSlice          = true;
                iconSlice.isReady = true;
            }



            //DASH MECHANIC...no gravity for a duration
            //if (justDashed)
            //{
            //    acceleration.Y = 0;
            //    noGravityTimer += deltaTime;
            //    if(noGravityTimer > noGravityLimit)
            //    {
            //        noGravityTimer = 0;
            //        justDashed = false;
            //    }
            //}

            velocity += acceleration * deltaTime;

            if (velocity.X > velocityHorizontalMovespeedCap)
            {
                velocity.X -= accelerationDecay.X * deltaTime;
                if (velocity.X < velocityHorizontalMovespeedCap)
                {
                    velocity.X = velocityHorizontalMovespeedCap;
                }
                acceleration.X = 0;
            }
            else if (velocity.X < -velocityHorizontalMovespeedCap)
            {
                velocity.X += accelerationDecay.X * deltaTime;
                if (velocity.X > -velocityHorizontalMovespeedCap)
                {
                    velocity.X = -velocityHorizontalMovespeedCap;
                }
                acceleration.X = 0;
            }



            //FINALLY SET POSITION

            //set x pos.
            setPosX(getPosX() + velocity.X * deltaTime);



            //check horizontal collisions
            //COLLISION TEST WITH PLATFORMS
            for (int i = 0; i < platformList.count(); i++)
            {
                Sprite3 currentPlatform = platformList.getSprite(i);
                if (this.collision(currentPlatform))
                {
                    if (velocity.X > 0)
                    {
                        velocity.X = 0;
                        this.setPosX(currentPlatform.getPosX() - this.getWidth());
                    }
                    else if (velocity.X < 0)
                    {
                        velocity.X = 0;
                        this.setPosX(currentPlatform.getPosX() + currentPlatform.getWidth());
                    }
                }
            }



            setPosY(getPosY() + velocity.Y * deltaTime);



            //COLLISION TEST WITH PLATFORMS
            for (int i = 0; i < platformList.count(); i++)
            {
                Sprite3 currentPlatform = platformList.getSprite(i);
                if (this.collision(currentPlatform))
                {
                    if (velocity.Y >= 0 && this.getPosY() <= currentPlatform.getPosY())
                    {
                        this.setPos(getPosX(), currentPlatform.getPosY() - this.getHeight());
                        velocity.Y = 0;
                        IsOnGround = true;
                    }
                    else if (velocity.Y < 0 && this.getPosY() >= currentPlatform.getPosY())
                    {
                        this.setPos(getPosX(), currentPlatform.getPosY() + currentPlatform.getHeight());
                        velocity.Y = 0;
                    }
                }
            }


            //If no input movement, slow down player
            if (canPlayerMove)
            {
                if (InputManager.Instance.KeyUp(Keys.Left) && InputManager.Instance.KeyUp(Keys.Right) && GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X == 0)
                {
                    acceleration.X = 0;

                    if (velocity.X != 0)
                    {
                        if (velocity.X > 0)
                        {
                            velocity.X -= deltaTime * velocityDecay.X;
                            if (velocity.X < 0)
                            {
                                velocity.X = 0;
                            }
                        }
                        else if (velocity.X < 0)
                        {
                            velocity.X += deltaTime * velocityDecay.X;
                            if (velocity.X > 0)
                            {
                                velocity.X = 0;
                            }
                        }
                    }
                }
                else
                {
                    //If travelling right and player moves left, increase the acceleration to opposite
                    if (InputManager.Instance.KeyDown(Keys.Left))
                    {
                        if (acceleration.X > -HorizontalMoveSpeed)
                        {
                            acceleration.X = -HorizontalMoveSpeed;
                        }

                        //If player velocity is more than the cap, slowly decay to the cap.
                        if (velocity.X > 0)
                        {
                            velocity.X -= deltaTime * velocityDecay.X;
                            if (velocity.X < 0)
                            {
                                velocity.X = 0;
                            }
                        }
                    }
                    if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X != 0)
                    {
                        acceleration.X = HorizontalMoveSpeed * GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X;

                        if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0)
                        {
                            if (velocity.X < 0)
                            {
                                velocity.X += deltaTime * velocityDecay.X;
                                if (velocity.X > 0)
                                {
                                    velocity.X = 0;
                                }
                            }
                        }
                        else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0)
                        {
                            if (velocity.X > 0)
                            {
                                velocity.X -= deltaTime * velocityDecay.X;
                                if (velocity.X < 0)
                                {
                                    velocity.X = 0;
                                }
                            }
                        }
                    }

                    if (InputManager.Instance.KeyDown(Keys.Right))
                    {
                        if (acceleration.X < HorizontalMoveSpeed)
                        {
                            acceleration.X = HorizontalMoveSpeed;
                        }
                        if (velocity.X < 0)
                        {
                            velocity.X += deltaTime * velocityDecay.X;
                            if (velocity.X > 0)
                            {
                                velocity.X = 0;
                            }
                        }
                    }
                    //If both left and right pressed down, 0 acceleration
                    if (InputManager.Instance.KeyDown(Keys.Right) && InputManager.Instance.KeyDown(Keys.Left))
                    {
                        acceleration.X = 0;
                    }
                }
            }



            //Is the player currently on a platform?
            bool isOnPlatform = false;

            for (int i = 0; i < platformList.count(); i++)
            {
                Sprite3 currentPlatform = platformList.getSprite(i);
                if (currentPlatform.getActive())
                {
                    if (currentPlatform.getBoundingBoxAA().Intersects(rectPlatformCheck))
                    {
                        isOnPlatform = true;
                    }
                }
            }
            if (isOnPlatform == false)
            {
                IsOnGround = false;
            }


            //PLAYER JUMP.
            if (canPlayerMove)
            {
                if (InputManager.Instance.KeyPressed(Keys.Z) || InputManager.Instance.ButtonPressed(Buttons.A))
                {
                    if (IsOnGround)
                    {
                        velocity.Y = -jumpVelocity;
                        IsOnGround = false;
                        soundJump.Play();
                    }
                    else
                    {
                        if (canDoubleJump == true)
                        {
                            velocity.Y             = -doubleJumpVelocity;
                            canDoubleJump          = false;
                            iconDoubleJump.isReady = false;
                            soundDoubleJump.Play();
                        }
                    }
                }
            }

            //If player holds the jump button, gets maximum jump, otherwise fall faster.
            if (canPlayerMove)
            {
                if (InputManager.Instance.KeyDown(Keys.Z) || InputManager.Instance.ButtonDown(Buttons.A) && IsOnGround == false)
                {
                    acceleration.Y = accelerationPlayerFall.Y;
                }
                else
                {
                    acceleration.Y = accelerationDefault.Y;
                }
            }


            //PLAYER DASH
            if (canPlayerMove)
            {
                if (InputManager.Instance.KeyPressed(Keys.C) || InputManager.Instance.ButtonPressed(Buttons.B))
                {
                    if (canDash)
                    {
                        if (InputManager.Instance.KeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0)
                        {
                            velocity.X       = horizontalDashVelocity;
                            velocity.Y       = -20;
                            canDash          = false;
                            iconDash.isReady = false;
                            noGravityTimer   = 0;
                            justDashed       = true;
                            soundDash.Play();
                        }
                        else if (InputManager.Instance.KeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0)
                        {
                            velocity.X       = -horizontalDashVelocity;
                            velocity.Y       = -20;
                            canDash          = false;
                            iconDash.isReady = false;
                            noGravityTimer   = 0;
                            justDashed       = true;
                            soundDash.Play();
                        }
                    }
                }
            }

            if (IsOnGround == false)
            {
                if (velocity.Y > 0)
                {
                    //check for platforms
                    isCheckGroundPlatforms = true;
                }
            }
            else
            {
                isCheckGroundPlatforms = false;
            }

            rectPlatformCheck = new Rectangle((int)this.getPosX(), (int)this.getPosY() + (int)this.getHeight(), (int)this.getWidth(), 5);
        }
Exemplo n.º 13
0
        public override void Update(GameTime gameTime)
        {
            //deltaTime is in seconds, so calculations = pixels per second.
            deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Press enter to start game/level
            switch (levelState)
            {
            case LEVELSTATE.LEVELSTART:


                if (InputManager.Instance.KeyPressed(Keys.Enter))
                {
                    levelState = LEVELSTATE.LEVELPLAY;
                }
                return;

            case LEVELSTATE.LEVELPLAY:
                timer += deltaTime;



                //update player
                player.Update(gameTime);


                //PAUSE
                if (InputManager.Instance.KeyPressed(Keys.P))
                {
                    gameStateManager.pushLevel(3);
                }


                //PLAYER SHOOT
                if (InputManager.Instance.KeyPressed(Keys.Space))
                {
                    AddBullet((int)player.getPosX(), (int)player.getPosY());
                    soundBulletLimit.playSoundIfOk();
                }


                break;

            case LEVELSTATE.LEVELFINISH:
                player.Update(gameTime);
                if (InputManager.Instance.KeyPressed(Keys.Enter))
                {
                    gameStateManager.pushLevel(1);
                }
                break;

            case LEVELSTATE.LEVELGAMEOVER:
                timer += deltaTime;

                if (InputManager.Instance.KeyPressed(Keys.Q))
                {
                    gameStateManager.setLevel(4);
                }
                break;

            default:
                throw new Exception("hahaha");
            }

            //Every 2 seconds, spawn an enemy randomly.
            if (timer > spawnInterval && enemyCounter < enemyToSpawn)
            {
                AddEnemy(enemyList);
                timer = 0;
                enemyCounter++;
            }

            //update backgrounds
            scrollBack.Update(gameTime);
            scrollFore.Update(gameTime);
            scrollBack.setScrollSpeed(player.playerBackgroundSpeed - 2);
            scrollFore.setScrollSpeed(player.playerBackgroundSpeed);


            //Update/remove enemies
            enemyList.Update(gameTime);
            enemyList.removeIfOutside(new Rectangle(-100, -100, Game1.SCREEN_WIDTH + 200, Game1.SCREEN_HEIGHT + 200));
            if (enemyList.countActive() == 0 && enemyCounter >= enemyToSpawn)
            {
                levelState = LEVELSTATE.LEVELFINISH;
            }

            //update/remove bullets
            playerBulletList.moveDeltaX(5);
            playerBulletList.removeIfOutside(new Rectangle(-100, -100, Game1.SCREEN_WIDTH + 200, Game1.SCREEN_HEIGHT + 200));

            //If player collides with enemy
            int collisionIndex = enemyList.collisionAA(player);

            if (collisionIndex != -1)
            {
                Sprite3 temp = enemyList.getSprite(collisionIndex);
                //player collides with boss
                if (temp.getName() == "boss")
                {
                }
                else
                {
                    //enemy dies?
                    temp.active  = false;
                    temp.visible = false;
                    AddExplosion((int)temp.getPosX(), (int)temp.getPosY());
                    score         -= 5;
                    textScore.text = "Score : " + score.ToString();
                    player.TakeDamage();

                    if (player.hitPoints <= 0)
                    {
                        levelState = LEVELSTATE.LEVELGAMEOVER;
                        AddExplosion((int)player.getPosX(), (int)player.getPosY());
                        player.setPos(0, -300); // offscreen
                        player.setActive(false);
                    }

                    //TODO: GET HITSOUND
                    soundEnemyHitLimit.playSoundIfOk();
                }
            }

            //if a bullet collides with enemy
            for (int i = 0; i < playerBulletList.count(); i++)
            {
                Sprite3 currentBullet = playerBulletList.getSprite(i);
                if (currentBullet == null)
                {
                    continue;
                }
                if (currentBullet.active != true)
                {
                    continue;
                }
                if (currentBullet.visible != true)
                {
                    continue;
                }

                //if collision success
                int collision = enemyList.collisionAA(currentBullet);
                if (collision != -1)
                {
                    Sprite3 currentEnemy = enemyList.getSprite(collision);

                    currentEnemy.hitPoints -= 1;
                    //DEAD ENEMY
                    if (currentEnemy.hitPoints <= 0)
                    {
                        currentEnemy.active  = false;
                        currentEnemy.visible = false;


                        //add particle
                        AddExplosion((int)currentEnemy.getPosX(), (int)currentEnemy.getPosY());

                        //add score
                        score         += 10;
                        textScore.text = "Score : " + score.ToString();
                    }
                    //DAMAGED ENEMY
                    else
                    {
                        currentEnemy.varInt0 = 100;
                        soundEnemyHitLimit.playSoundIfOk();
                    }

                    //REMOVE BULLET
                    currentBullet.active  = false;
                    currentBullet.visible = false;
                }
            }

            //update particles
            particleList.animationTick(gameTime);

            base.Update(gameTime);
        }
Exemplo n.º 14
0
        public override void Update(GameTime gameTime)
        {
            prevKeyState     = keyState;
            keyState         = Keyboard.GetState();
            timer           += 1;
            explostionTimer += 1;
            explosionAnimation.animationTick(gameTime);
            mineExplostionAnimation.animationTick(gameTime);
            missileSmoke.Update(gameTime);
            exLimSound.Update(gameTime);

            previousMouseState = currentMouseState;
            currentMouseState  = Mouse.GetState();

            mouse_x = currentMouseState.X;
            mouse_y = currentMouseState.Y;

            // Sets up mine
            if (currentMouseState.LeftButton == ButtonState.Pressed)
            {
                minePos.X   = mouse_x;
                minePos.Y   = mouse_y;
                drawMines   = true;
                mine.active = true;
                mineCount   = 1;
            }

            // Controls player movements
            if (keyState.IsKeyDown(Keys.Left))
            {
                if (player.getPosX() > Dir.leftBoundary)
                {
                    player.setPosX(player.getPosX() - 4);                   // Moves player 3 units left
                    player.setFlip(SpriteEffects.FlipHorizontally);
                }
            }
            if (keyState.IsKeyDown(Keys.Right))
            {
                if (player.getPosX() < (Dir.rightBoundary - (player.getWidth() - 5)))
                {
                    player.setPosX(player.getPosX() + 4);                   // Moves player 3 units right
                    player.setFlip(SpriteEffects.None);
                }
            }

            // Moves enemy sprite
            enemy1.setPosX(enemy1.getPosX() + Dir.rnd.Next(1, 3));
            enemy2.setPosX(enemy2.getPosX() - Dir.rnd.Next(1, 3));

            // If enemy runs off screen, reset position to random x postion
            if (enemy1.getPosX() > Dir.rightBoundary + 60)
            {
                enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
            }
            if (enemy2.getPosX() < Dir.leftBoundary - (enemy2.getWidth() + 50))
            {
                enemy2.setPos(Dir.rnd.Next(Dir.rightBoundary, Dir.rightBoundary + 200), Dir.rnd.Next(200, 700));
            }

            // Shoot missile
            if (keyState.IsKeyDown(Keys.Space) && prevKeyState.IsKeyUp(Keys.Space))
            {
                missile.setPos(player.getPosX() + player.getWidth() / 2, player.getPosY() - missile.getHeight());
                missile.active = true;
                drawSmoke();
                drawMissile = true;
                if (missileCount > 0)
                {
                    missileCount--;
                }
            }

            if (missileCount == 0)
            {
                missileCount = 5;
            }

            if (missile.getPosY() < 185 + missile.getHeight())
            {
                missile.setPos(player.getPos());
                drawMissile = false;
                missileSmoke.deActivate();
            }

            if (timer % 361 == 360)
            {
                anchor.setPos(enemy1.getPosX() + enemy1.getWidth() / 2, enemy1.getPosY() + enemy1.getHeight() / 2);
                anchorDraw = true;
            }

            if (anchor.getPosY() > Dir.bottomBoundary + anchor.getHeight())
            {
                anchor.active = false;
                anchorDraw    = false;
            }
            // Collision Control
            enemy1Collision = missile.collision(enemy1);
            enemy2Collision = missile.collision(enemy2);

            if (enemy1Collision)
            {
                enemy1.hitPoints = enemy1.hitPoints - 10;
                currXMissile     = enemy1.getPosX() + enemy1.getWidth() / 2;
                currYMissile     = enemy1.getPosY() - enemy1.getHeight() / 2;
                if (enemy1.hitPoints <= 0)
                {
                    collision1       = true;
                    enemy1.hitPoints = 10;
                    Dir.enemy1Count++;
                    missileSmoke.deActivate();
                }
                getSetMissile();
            }
            if (enemy2Collision)
            {
                missileSmoke.deActivate();
                enemy2.hitPoints = enemy2.hitPoints - 10;
                drawMissile      = false;
                if (enemy2.hitPoints <= 0)
                {
                    currXMissile = enemy2.getPosX() + enemy2.getWidth() / 2;
                    currYMissile = enemy2.getPosY() - enemy2.getHeight() / 2;
                    collision2   = true;
                    Dir.enemy2Count++;
                    enemy2.hitPoints = 20;
                }
                getSetMissile();
            }

            // Gain 10 hp if missile hits the anchor preserve
            bool lifeGain = missile.collision(life);

            if (lifeGain == true)
            {
                if (player.hitPoints < 50)
                {
                    player.hitPoints = player.hitPoints + 10;
                }
                lifeGain    = false;
                drawMissile = false;
                life.active = false;
                life.setPos(new Vector2(Dir.rnd.Next(250, 800), Dir.rnd.Next(400, 600)));
                missile.active = false;
                missile.setPos(player.getPosX(), player.getPosY());
                missileSmoke.deActivate();
            }

            bool anchorCollision = anchor.collision(player);

            if (anchorCollision)
            {
                anchorDraw = false;
                anchor.setActiveAndVisible(false);
                anchor.setPos(new Vector2(-100, -100));
                player.hitPoints = player.hitPoints - 20;
            }

            mineCollission = mine.collision(enemy1);
            if (mineCollission)
            {
                mine.active = false;
                drawMines   = false;
                mineCurrPos = mine.getPos();
                mine.setPos(new Vector2(-100, 0));
                enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                mineCollisionToggle = true;
                score           += 150;
                mineCount        = 0;
                Dir.enemy1Count += 1;
                exLimSound.playSoundIfOk();
            }

            mineCollission2 = mine.collision(enemy2);
            if (mineCollission2)
            {
                mine.active = false;
                drawMines   = false;
                mineCurrPos = mine.getPos();
                mine.setPos(new Vector2(-100, 0));
                enemy2.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                mineCollisionToggle2 = true;
                score           += 200;
                mineCount        = 0;
                Dir.enemy2Count += 1;
                exLimSound.playSoundIfOk();
            }
            // Toggle BB
            if (keyState.IsKeyDown(Keys.B) && prevKeyState.IsKeyUp(Keys.B))
            {
                showBB = !showBB;
            }

            // Pause
            if (keyState.IsKeyDown(Keys.P) && !prevKeyState.IsKeyDown(Keys.P))
            {
                gameStateManager.pushLevel(3);
            }

            // Help State
            if (keyState.IsKeyDown(Keys.F1) && !prevKeyState.IsKeyDown(Keys.F1))
            {
                gameStateManager.pushLevel(5);
            }

            if (player.hitPoints < 0)
            {
                player.hitPoints = 0;
            }

            // End State
            if (score >= 1000 || player.hitPoints <= 0)
            {
                if (timer % 181 == 180)
                {
                    gameStateManager.setLevel(4);
                }
            }
        }
Exemplo n.º 15
0
        public override void Update(GameTime gameTime)
        {
            prevKeyState = keyState;
            keyState     = Keyboard.GetState();
            timer       += 1;
            explosionAnimation.animationTick(gameTime);
            missileSmoke.Update(gameTime);

            if (keyState.IsKeyDown(Keys.Left))
            {
                if (player.getPosX() > Dir.leftBoundary)
                {
                    player.setPosX(player.getPosX() - 4);                   // Moves player 4 units left
                    player.setFlip(SpriteEffects.FlipHorizontally);
                }
            }
            if (keyState.IsKeyDown(Keys.Right))
            {
                if (player.getPosX() < (Dir.rightBoundary - (player.getWidth() - 5)))
                {
                    player.setPosX(player.getPosX() + 4);                   // Moves player 4 units right
                    player.setFlip(SpriteEffects.None);
                }
            }
            enemy1.setPosX(enemy1.getPosX() + Dir.rnd.Next(1, 3));
            enemy2.setPosX(enemy2.getPosX() - Dir.rnd.Next(1, 3));
            enemy3.setPosX(enemy3.getPosX() + Dir.rnd.Next(2, 4));

            // If enemy runs off screen, reset position to random x postion
            if (enemy1.getPosX() > Dir.rightBoundary + 60)
            {
                enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
            }
            if (enemy2.getPosX() < Dir.leftBoundary - (enemy2.getWidth() + 50))
            {
                enemy2.setPos(Dir.rnd.Next(Dir.rightBoundary, Dir.rightBoundary + 200), Dir.rnd.Next(200, 700));
            }
            if (enemy3.getPosX() > Dir.rightBoundary + 60)
            {
                enemy3.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
            }

            if (keyState.IsKeyDown(Keys.Space) && prevKeyState.IsKeyUp(Keys.Space))
            {
                missile.setPos(player.getPosX() + player.getWidth() / 2, player.getPosY() - missile.getHeight());
                missile.active = true;
                drawMissile    = true;
                drawSmoke();
                if (missileCount > 0)
                {
                    missileCount--;
                }
            }

            if (missileCount == 0)
            {
                missileCount = 5;
            }

            if (missile.getPosY() < 185 + missile.getHeight())
            {
                missile.setPos(player.getPos());
                drawMissile = false;
                missileSmoke.deActivate();
            }

            enemy1Collision = missile.collision(enemy1);
            enemy2Collision = missile.collision(enemy2);
            enemy3Collision = missile.collision(enemy3);

            explostionTimer += 1;
            if (enemy1Collision)
            {
                enemy1.hitPoints = enemy1.hitPoints - 10;
                currXMissile     = enemy1.getPosX() + enemy1.getWidth() / 2;
                currYMissile     = enemy1.getPosY() - enemy1.getHeight() / 2;
                if (enemy1.hitPoints <= 0)
                {
                    collision1 = true;
                    Dir.enemy1Count++;
                    enemy1.hitPoints = 10;
                }
                getSetMissile();
            }
            if (enemy2Collision)
            {
                missileSmoke.deActivate();
                enemy2.hitPoints = enemy2.hitPoints - 10;
                drawMissile      = false;
                if (enemy2.hitPoints <= 0)
                {
                    currXMissile = enemy2.getPosX() + enemy2.getWidth() / 2;
                    currYMissile = enemy2.getPosY() - enemy2.getHeight() / 2;
                    collision2   = true;
                    Dir.enemy2Count++;
                    enemy2.hitPoints = 20;
                }
                getSetMissile();
            }
            if (enemy3Collision)
            {
                enemy3.hitPoints = enemy3.hitPoints - 10;
                currXMissile     = enemy3.getPosX() + enemy3.getWidth() / 2;
                currYMissile     = enemy3.getPosY() - enemy3.getHeight() / 2;
                if (enemy3.hitPoints <= 0)
                {
                    collision3 = true;
                    Dir.enemy3Count++;
                    enemy3.hitPoints = 10;
                }
                getSetMissile();
            }

            // Toggle showing Boundary Box
            if (keyState.IsKeyDown(Keys.B) && prevKeyState.IsKeyUp(Keys.B))
            {
                showBoundary = !showBoundary;
            }

            if (keyState.IsKeyDown(Keys.P) && !prevKeyState.IsKeyDown(Keys.P))
            {
                gameStateManager.pushLevel(3);
            }

            if (keyState.IsKeyDown(Keys.F1) && !prevKeyState.IsKeyDown(Keys.F1))
            {
                gameStateManager.pushLevel(5);
            }

            if (score >= 300)
            {
                if (timer % 181 == 180)
                {
                    gameStateManager.setLevel(2);
                }
            }
            exLimSound.Update(gameTime);
        }