Ejemplo n.º 1
0
        /***
         ***
         *** Stores all the important components of the current
         *** computer game, such as the load content, timer and
         *** draw methods, for each level in the current computer
         *** game.
         ***
         ***
         ***/

        public void UpdateSS0(GameTime gameTime)
        {
            // reset back to the original coordinates
            kittyCatVec.X = 275;
            kittyCatVec.Y = 50;

            titleVec.X    = 100;
            sloganVec.X   = 290;
            instructVec.X = 315;
            kittyCat.setPos(kittyCatVec.X, kittyCatVec.Y);
        }
Ejemplo n.º 2
0
        public override void LoadContent()
        {
            minusTex    = Content.Load <Texture2D>("Textures/Options/Minus");
            plusTex     = Content.Load <Texture2D>("Textures/Options/Plus");
            medTex      = Content.Load <Texture2D>("Textures/Options/Med");
            lowTex      = Content.Load <Texture2D>("Textures/Options/Low");
            mediumTex   = Content.Load <Texture2D>("Textures/Options/Medium");
            highTex     = Content.Load <Texture2D>("Textures/Options/High");
            triangleTex = Content.Load <Texture2D>("Textures/Menu/TriangleMan");

            buttonMinus = new Button(minusTex, new Vector2(-35 + minusTex.Width, 215 + minusTex.Height), Resources.ColorHighLight, Button.ButtonType.VolumeControl, 0);
            buttonPlus  = new Button(plusTex, new Vector2(xOffset + buttonMinus.getPosX() + minusTex.Width, buttonMinus.getPosY()), Resources.ColorHighLight, Button.ButtonType.VolumeControl, 1);
            buttonMed   = new Button(medTex, new Vector2(xOffset + buttonPlus.getPosX() + minusTex.Width, buttonMinus.getPosY()), Resources.ColorHighLight, Button.ButtonType.VolumeControl, 2);

            buttonLow    = new Button(lowTex, new Vector2(-35 + lowTex.Width, 375 + lowTex.Height), Resources.ColorHighLight, Button.ButtonType.GraphicsControl, 0);
            buttonMedium = new Button(mediumTex, new Vector2(xOffset + buttonLow.getPosX() + lowTex.Width, 375 + lowTex.Height), Resources.ColorHighLight, Button.ButtonType.GraphicsControl, 1);
            buttonHigh   = new Button(highTex, new Vector2(xOffset + buttonMedium.getPosX() + lowTex.Width, 375 + lowTex.Height), Resources.ColorHighLight, Button.ButtonType.GraphicsControl, 2);

            sTriangle = new Sprite3(true, triangleTex, 0, 0);
            sTriangle.setHSoffset(new Vector2(triangleTex.Width / 2, triangleTex.Height / 2));
            sTriangle.setPos(new Vector2(675, 305));

            title        = "Options:";
            subtitle     = "Adjust to Your Hearts Content";
            instructions = "Press Any Key to Return to Main Menu";
            displayGraphicsQuality();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public override void LoadContent()
 {
     transparency = new ColorField(new Color(Color.Black, 0.5f), new Rectangle(0, 0, (int)Game1.screenSize.X, (int)Game1.screenSize.Y));
     displayTex   = Content.Load <Texture2D>("Textures/Menu/HowToPlayScreen");
     display      = new Sprite3(true, displayTex, 0, 0);
     display.setHSoffset(new Vector2(displayTex.Width / 2, displayTex.Height / 2));
     display.setPos(Game1.screenSize / 2);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create a basic button
 /// </summary>
 /// <param name="tex">Button texture</param>
 /// <param name="pos">Position</param>
 /// <param name="highLight">Highlighted colour</param>
 /// <param name="buttonType">Button type</param>
 /// <param name="nextLevel">nextlevel/value if applicable</param>
 public Button(Texture2D tex, Vector2 pos, Color highLight, ButtonType buttonType, int nextLevel)
 {
     // Initialise our Button
     this.highLight = highLight;
     this.nextLevel = nextLevel;
     type           = buttonType;
     button         = new Sprite3(true, tex, 0, 0);
     button.setHSoffset(new Vector2(button.getWidth() / 2, button.getHeight() / 2));
     button.setPos(pos);
 }
Ejemplo n.º 6
0
        public void NewBall(float x, float y)
        {
            Sprite3 ball = new Sprite3(true, texBall, x, y);

            ball.setBBandHSFractionOfTexCentered(0.4f);

            ball.setPos(paddle.getPos() + ballOffset);
            ball.setDeltaSpeed(new Vector2(7, 0));

            ballList.addSpriteReuse(ball);
        }
Ejemplo 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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo 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>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            prevK = k;
            k     = Keyboard.GetState();

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

            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 (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));
                }

                if (ballbb.Intersects(paddle.getBoundingBoxAA()))
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }
            }



            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Ejemplo n.º 10
0
        public override void Draw(GameTime gameTime)
        {
            if (score >= 1000)
            {
                status = "THE END!";
            }
            else if (player.hitPoints == 0)
            {
                status = "YOU DEAD!";
            }
            else
            {
                status = "Missile Left: " + missileCount;
            }

            spriteBatch.Begin();

            backgroundLevel2.Draw(spriteBatch);
            spriteBatch.DrawString(scoreFont, "Score: " + score + "/1000", new Vector2(20, 20), Color.Black); // Draw Score on top left
            spriteBatch.DrawString(scoreFont, status, new Vector2(1100, 20), Color.Black);                    // Draw missile count
            spriteBatch.Draw(texMouse, new Rectangle((int)mouse_x, (int)mouse_y, 16, 16), Color.White);       // draw the mouse here
            enemy1.Draw(spriteBatch);
            enemy2.Draw(spriteBatch);
            player.Draw(spriteBatch);
            missileSmoke.Draw(spriteBatch);

            if (timer > 300)
            {
                life.setActiveAndVisible(true);
                life.draw(spriteBatch);
            }

            // If certain conditions are met, then draw these weapons
            if (drawMissile == true && missileCount != 0)
            {
                missile.draw(spriteBatch);
                missile.setPosY(missile.getPosY() - 3);
                missileSmoke.sysPos = new Vector2(missile.getPosX() + missile.getWidth() / 2, missile.getPosY() + missile.getHeight());
            }

            if (anchorDraw == true)
            {
                anchor.setActiveAndVisible(true);
                anchor.draw(spriteBatch);
                anchor.setPosY(anchor.getPosY() + 4);
            }

            if (drawMines && mineCount == 1)
            {
                mine.setPos(minePos.X, minePos.Y);
                mine.draw(spriteBatch);
            }

            // If there is a collision, draw explosion animation
            if (collision1 == true)
            {
                drawMissile = false;
                drawExplosion(currXMissile, currYMissile);
                enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                if (explostionTimer == 100)
                {
                    collision1      = false;
                    score          += 50;
                    explostionTimer = 0;
                }
            }
            if (collision2 == true)
            {
                drawMissile = false;
                drawExplosion(currXMissile, currYMissile);
                enemy2.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                if (explostionTimer == 80)
                {
                    score          += 100;
                    collision2      = false;
                    explostionTimer = 0;
                    missileSmoke.deActivate();
                }
            }

            if (mineCollisionToggle == true)
            {
                mineCollission = false;
                mineExplostionAnimation.setPos(mineCurrPos.X - mine.getWidth() / 2, mineCurrPos.Y - mine.getHeight() / 2);
                mineExplostionAnimation.draw(spriteBatch);
                if (explostionTimer == 100)
                {
                    mineExplostionAnimation.makeInactive = true;
                    enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                    mineCollisionToggle = false;
                    explostionTimer     = 0;
                }
            }
            if (mineCollisionToggle2 == true)
            {
                mineCollission2 = false;
                mineExplostionAnimation.setPos(mineCurrPos.X - mine.getWidth() / 2, mineCurrPos.Y - mine.getHeight() / 2);
                mineExplostionAnimation.draw(spriteBatch);
                if (explostionTimer == 100)
                {
                    mineExplostionAnimation.makeInactive = true;
                    enemy2.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                    mineCollisionToggle2 = false;
                    explostionTimer      = 0;
                }
            }
            // Draw BB
            if (showBB)
            {
                player.drawInfo(spriteBatch, Color.White, Color.Yellow);
                enemy1.drawInfo(spriteBatch, Color.White, Color.Yellow);
                enemy2.drawInfo(spriteBatch, Color.White, Color.Yellow);;
                missile.drawInfo(spriteBatch, Color.White, Color.Yellow);
                life.drawInfo(spriteBatch, Color.White, Color.Yellow);
                mine.drawInfo(spriteBatch, Color.White, Color.Yellow);
                anchor.drawInfo(spriteBatch, Color.White, Color.Yellow);
                //weaponList.drawInfo(spriteBatch, Color.White, Color.Yellow);
            }
            spriteBatch.End();
        }
Ejemplo n.º 11
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);
                }
            }
        }
Ejemplo n.º 12
0
 public void drawExplosion(float currXMissile, float currYMissile)
 {
     explosionAnimation.setPos(currXMissile, currYMissile);
     explosionAnimation.draw(spriteBatch);
 }
Ejemplo n.º 13
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);
        }