Ejemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            LineBatch.init(GraphicsDevice);
            texBack   = Util.texFromFile(GraphicsDevice, dir + "back3.png");    //***
            texpaddle = Util.texFromFile(GraphicsDevice, dir + "red64x32.png"); //***
            texBall   = Util.texFromFile(GraphicsDevice, dir + "ball2.png");    //***
            texBlock1 = Util.texFromFile(GraphicsDevice, dir + "white64x32.png");
            paddle    = new Sprite3(true, texpaddle, xx, yy);
            paddle.setBBToTexture();
            ball = new Sprite3(true, texBall, xx, yy);
            ball.setBBandHSFractionOfTexCentered(0.7f);
            sl = new SpriteList();

            back1    = new ImageBackground(texBack, Color.White, GraphicsDevice);
            playArea = new Rectangle(lhs, top, rhs - lhs, bot - top); // width and height
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    Sprite3 s = new Sprite3(true, texBlock1, x * 68 + playArea.X + blocksOffsetX, y * 36 + playArea.Y + blocksOffsetY);
                    s.hitPoints = 1;
                    if (y == 0)
                    {
                        s.hitPoints = 2;
                        s.setColor(Color.LightBlue);
                    }

                    sl.addSpriteReuse(s);
                }
            }
            // TODO: use this.Content to load your game content here
        }
Ejemplo n.º 2
0
        public override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(graphicsDevice);

            // put a font to tell play to press space to start
            //Dir.texBackground = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Press_Space.png");

            float xLocation = Dir.rightBoundary / 2;

            texpressStart = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Press_Space.png");
            texStartSub   = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\navio-hi.png");
            titleFont     = Content.Load <SpriteFont>("display");
            texTitle      = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\title.png");
            introSound    = Content.Load <SoundEffect>("intro_theme");
            intro         = introSound.CreateInstance();

            pressStart = new Sprite3(true, texpressStart, xLocation - 302, Dir.topBoundary + 400);
            startSub   = new Sprite3(true, texStartSub, movingXLocation, Dir.bottomBoundary / 2);
            title      = new Sprite3(true, texTitle, xLocation - 300, 50);

            pressStart.setWidthHeight(pressStart.getWidth() * 2, pressStart.getHeight() * 2);
            title.setWidthHeight((title.getWidth() * 3) / 2, (title.getHeight() * 3) / 2);
            startSub.setWidthHeight(startSub.getWidth() / 2, startSub.getWidth() / 2);

            pressStart.setColor(Color.Aqua);
            startSub.setColor(Color.GreenYellow);
        }
Ejemplo n.º 3
0
        public override void LoadContent()
        {
            pauseHelpText  = Content.Load <SpriteFont>("helpText");
            texPauseScreen = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Pause.jpg");  //
            texBack        = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Pause.jpg");  //
            texPause       = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Pause2.jpg"); //

            pauseBackground = new ImageBackground(texBack, Color.White, graphicsDevice);
            pause           = new Sprite3(true, texPause, 444, 30);

            pause.setWidthHeight(pause.getWidth() / 2, pause.getHeight() / 2);
            pause.setColor(Color.Aquamarine);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Act when our button is entered
        /// </summary>
        public void buttonEntered()
        {
            button.setColor(highLight);
            button.scale = highLightScale;
            if (!playedSound)
            {
                SoundManager.getMenuSelect().Play(0.2f * Resources.volume, HelperUtils.RandFloat(rand, -0.2f, 0.2f), 0);
                playedSound = true;
            }

            switch (type)
            {
            case ButtonType.ChangeLevelSet:
                if (PlayerInput.m1OldPressed())
                {
                    SoundManager.getMenuSelect().Play(0.2f * Resources.volume, HelperUtils.RandFloat(rand, -0.2f, 0.2f), 0);
                    Game1.levelManager.setLevel(nextLevel);
                }
                break;

            case ButtonType.ChangeLevelPush:
                if (PlayerInput.m1OldPressed())
                {
                    SoundManager.getMenuSelect().Play(0.2f * Resources.volume, HelperUtils.RandFloat(rand, -0.2f, 0.2f), 0);
                    Game1.levelManager.pushLevel(nextLevel);
                }
                break;

            case ButtonType.ChangeLevelPop:
                if (PlayerInput.m1OldPressed())
                {
                    Game1.levelManager.popLevel();
                }
                break;

            case ButtonType.ResetGame:
                if (PlayerInput.m1OldPressed())
                {
                    SoundManager.getMenuSelect().Play(0.2f * Resources.volume, HelperUtils.RandFloat(rand, -0.2f, 0.2f), 0);
                    Resources.score         = 0;
                    Resources.currPlayLevel = 0;
                    Game1.spriteManager.clearScene(true);
                    Game1.particleManager.ClearScene();
                    if (Game1.spriteManager.player != null)
                    {
                        Game1.spriteManager.player.resetPlayer();
                    }
                    Game1.levelManager.setLevel(0);
                    //Game1.ResetLevel
                }
                break;

            case ButtonType.Exit:
                if (PlayerInput.m1OldPressed())
                {
                    Game1.exitGame = true;
                }
                break;

            case ButtonType.VolumeControl:
                if (PlayerInput.m1Pressed())
                {
                    if (nextLevel == 0)
                    {
                        Resources.volume -= 0.01f;
                    }
                    else if (nextLevel == 1)
                    {
                        Resources.volume += 0.01f;
                    }
                    else if (nextLevel == 2)
                    {
                        Resources.volume = 0.5f;
                    }
                    Resources.volume   = HelperUtils.Clamp(Resources.volume, 0f, 1f);
                    MediaPlayer.Volume = Resources.volume;
                }
                break;

            case ButtonType.GraphicsControl:
                if (PlayerInput.m1Pressed())
                {
                    if (nextLevel == 0)
                    {
                        Resources.graphicsQuality = 0;
                    }
                    else if (nextLevel == 1)
                    {
                        Resources.graphicsQuality = 1;
                    }
                    else if (nextLevel == 2)
                    {
                        Resources.graphicsQuality = 2;
                    }

                    Game1.particleManager.setMaxParticleAmount(1500);
                }
                break;
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(graphicsDevice);
            weaponList  = new SpriteList(20);

            playerXLocation = Dir.rnd.Next(0, 1000);
            playerYLocation = 880;
            enemyXLocation  = -20;
            enemyYLocation  = Dir.rnd.Next(213, 600);
            enemy2XLocation = Dir.rnd.Next(Dir.rightBoundary - 300, Dir.rightBoundary);
            anchorXLocation = Dir.rnd.Next(Dir.leftBoundary + 100, Dir.rightBoundary - 100);
            anchorYLocation = 175;

            texBackgroundLevel2    = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Sea04.png");
            texPlayer              = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\ship-md.png");
            texEnemy1              = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Merchant1.png");
            texEnemy2              = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Merchant2.png");
            texMissile             = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Torpedo5up.png");
            texMissileSmoke        = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Particle1.png");
            texExplostionAnimation = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\explodeWater1024x64.png");
            texMineExplostion      = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\explode1.png");
            texMouse        = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Mouse.png");
            texAnchor       = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\anchor-th.png");
            texLife         = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\life-preserver-th.png");
            texMine         = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\water_mine.png");
            scoreFont       = Content.Load <SpriteFont>("display");
            helpFont        = Content.Load <SpriteFont>("helpText");
            explostionSound = Content.Load <SoundEffect>("bazooka_fire");
            exLimSound      = new LimitSound(explostionSound, 3);

            backgroundLevel2        = new ImageBackground(texBackgroundLevel2, Color.White, graphicsDevice);
            player                  = new Sprite3(true, texPlayer, playerXLocation, playerYLocation);
            enemy1                  = new Sprite3(true, texEnemy1, enemyXLocation, enemyYLocation);
            enemy2                  = new Sprite3(true, texEnemy2, enemy2XLocation, enemyYLocation);
            explosionAnimation      = new Sprite3(true, texExplostionAnimation, 0, playerYLocation);
            mineExplostionAnimation = new Sprite3(true, texMineExplostion, 0, playerYLocation);
            mine = new Sprite3(true, texMine, 0, 0);
            mine.setHSoffset(new Vector2(296, 313));
            weaponList.addSpriteReuse(mine);
            life = new Sprite3(true, texLife, Dir.rnd.Next(Dir.leftBoundary + 200, Dir.rightBoundary - 200), Dir.rnd.Next(300, 600));
            life.setActiveAndVisible(false);

            for (int i = 1; i < 3; i++)
            {
                anchor = new Sprite3(true, texAnchor, anchorXLocation, anchorYLocation);
                anchor.setWidthHeight(50, 50);
                weaponList.addSpriteReuse(anchor);
            }
            for (int m = 1; m < 6; m++)
            {
                missile = new Sprite3(true, texMissile, playerXLocation, playerYLocation);
                missile.setWidthHeight(missile.getWidth() / 2, missile.getHeight() / 2);
                weaponList.addSpriteReuse(missile);
            }

            player.setColor(Color.Red);

            // Adjusting sprite image sizes to suit my taste
            player.setWidthHeight(210, 64);
            enemy1.setWidthHeight(256, 64);
            enemy2.setWidthHeight(enemy1.getWidth() / 2, 64);
            life.setWidthHeight(48, 48);
            mine.setWidthHeight(40, 45);

            // animation for torpedo explosion
            explosionAnimation.setWidthHeightOfTex(1024, 64);
            explosionAnimation.setXframes(16);
            explosionAnimation.setYframes(1);
            explosionAnimation.setWidthHeight(80, 80);
            for (int moveX = 0; moveX <= 15; moveX++)
            {
                anim[moveX].X = moveX; anim[moveX].Y = 0;
            }
            explosionAnimation.setAnimationSequence(anim, 0, 15, 3);
            explosionAnimation.setAnimFinished(0);
            explosionAnimation.animationStart();

            // animation for mine explostion
            mineExplostionAnimation.setWidthHeightOfTex(1024, 64);
            mineExplostionAnimation.setXframes(16);
            mineExplostionAnimation.setYframes(1);
            mineExplostionAnimation.setWidthHeight(80, 80);
            for (int moveX = 0; moveX <= 15; moveX++)
            {
                mineAnim[moveX].X = moveX; mineAnim[moveX].Y = 0;
            }
            mineExplostionAnimation.setAnimationSequence(mineAnim, 0, 15, 4);
            mineExplostionAnimation.setAnimFinished(0);
            mineExplostionAnimation.animationStart();

            HealthBarAttached h1 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true);

            h1.offset                 = new Vector2(0, -1); // one pixel above the bounding box
            h1.gapOfbar               = 2;
            enemy1.hitPoints          = 10;
            enemy1.maxHitPoints       = 10;
            enemy1.attachedRenderable = h1;

            HealthBarAttached h2 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true);

            h2.offset                 = new Vector2(0, -1); // one pixel above the bounding box
            h2.gapOfbar               = 2;
            enemy2.hitPoints          = 20;
            enemy2.maxHitPoints       = 20;
            enemy2.attachedRenderable = h2;

            HealthBarAttached playerHP = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true);

            playerHP.offset           = new Vector2(0, -1); // one pixel above the bounding box
            playerHP.gapOfbar         = 2;
            player.hitPoints          = 50;
            player.maxHitPoints       = 50;
            player.attachedRenderable = playerHP;

            drawSmoke();
        }