Ejemplo n.º 1
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.º 2
0
 void automove() // auto playing fire(); AI_x
 {
     if (shooter.getPosX() + shooter.getWidth() / 2 > AI_x)
     {
         shooter.setPosX(shooter.getPosX() - shooterSpeed);
         if (shooter.getPosX() < innerRectangle.X)
         {
             shooter.setPosX(prevX);
         }
     }
     if (shooter.getPosX() + shooter.getWidth() / 2 < AI_x)
     {
         shooter.setPosX(shooter.getPosX() + shooterSpeed);
         if (shooter.getPosX() + actualShooterSize.X > innerRectangle.X + innerRectangle.Width)
         {
             shooter.setPosX(prevX);
         }
     }
     if (ticks % AIMoveLevel == 0)
     {
         AI_x = AI_xxx;
     }
     if (ticks % AIShootLevel == 0 && targets.countActive() > 0)
     {
         fire();
     }
 }
Ejemplo n.º 3
0
        void generateAliens()
        {
            if (numOfTargets >= numOfTargetsMax)
            {
                mgState = 3; return;
            }
            ;

            if (rnd.Next(0, 1000) < genAliensPercent * 10 && numOfTargets < numOfTargetsMax)
            {
                numOfTargets++;
                float   xx = rnd.Next(innerRectangle.X, (int)(innerRectangle.X + innerRectangle.Width - actualTargetSize.X));
                float   yy = innerRectangle.Y - actualTargetSize.Y / 2;
                Sprite3 s  = new Sprite3(true, targetTex, xx, yy);
                s.setWidthHeight(actualTargetSize.X, actualTargetSize.Y);
                s.setBBToTexture();

                //s.setWidthHeightOfTex(1536, 384);
                //s.setXframes(16);
                //s.setYframes(4);
                s.setDeltaSpeed(new Vector2(0, 1));
                //s.setBB(10, 10, 48 - 20, 48 - 20);

                //int frames = 12;
                //Vector2[] anim = new Vector2[frames];
                //for (int i = 0; i < frames; i++)
                //{
                //    anim[i].X = i; anim[i].Y = 0;
                //}
                //s.setAnimationSequence(anim, 0, frames - 1, 3);
                //s.animationStart();
                targets.addSpriteReuse(s);
                AI_xxx = s.getPosX() + s.getWidth() / 2;
            }
        }
Ejemplo n.º 4
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.º 5
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.º 6
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;
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Game1.TimeScore += deltaTime;

            cam.Pos = new Vector2(cam.Pos.X, Game1.SCREEN_HEIGHT / 2);

            if (InputManager.Instance.KeyDown(Keys.W))
            {
                cam.Pos = new Vector2(cam.Pos.X, cam.Pos.Y - 5);
            }
            if (InputManager.Instance.KeyDown(Keys.S))
            {
                cam.Pos = new Vector2(cam.Pos.X, cam.Pos.Y + 5);
            }
            if (InputManager.Instance.KeyDown(Keys.A))
            {
                cam.Pos = new Vector2(cam.Pos.X - 5, cam.Pos.Y);
            }
            if (InputManager.Instance.KeyDown(Keys.D))
            {
                cam.Pos = new Vector2(cam.Pos.X + 5, cam.Pos.Y);
            }


            if (InputManager.Instance.KeyPressed(Keys.Back))
            {
                gameStateManager.setLevel(gameStateManager.getCurrentLevelNum() - 1);
            }

            //CAMERA STICK ON PLAYER.
            if (cam.Pos.X < player.getPosX() - 100)
            {
                cam.Pos = new Vector2(player.getPosX() - 100, cam.Pos.Y);
            }
            else if (cam.Pos.X > player.getPosX() + player.getWidth() + 100)
            {
                cam.Pos = new Vector2(player.getPosX() + player.getWidth() + 100, cam.Pos.Y);
            }

            ////Move camera to infront of player.
            //if (player.velocity.X > 0)
            //{
            //    CamPlayerPositiveVelocity = true;
            //}
            //else if (player.velocity.X < 0)
            //{
            //    CamPlayerPositiveVelocity = false;
            //}

            //if (CamPlayerPositiveVelocity)
            //{
            //    cam.Pos = new Vector2(cam.Pos.X + 10, cam.Pos.Y);
            //}
            //else
            //{
            //    cam.Pos = new Vector2(cam.Pos.X - 10, cam.Pos.Y);
            //}



            if (cam.Pos.X < CamOriginalPosition.X)
            {
                cam.Pos = new Vector2(CamOriginalPosition.X, cam.Pos.Y);
            }
            else if (cam.Pos.X + Game1.SCREEN_WIDTH / 2 > OutOfBounds.X + OutOfBounds.Width)
            {
                cam.Pos = new Vector2(OutOfBounds.X + OutOfBounds.Width - CamOriginalPosition.X, cam.Pos.Y);
            }

            //cam.Pos = new Vector2(Game1.SCREEN_WIDTH/2, Game1.SCREEN_HEIGHT/2);
            if (InputManager.Instance.KeyPressed(Keys.B))
            {
                showbb = !showbb;
            }


            if (InputManager.Instance.MousePressed(MouseButton.Left))
            {
                Slice newSlice = new Slice((float)InputManager.Instance.GetMousePositionX() - Slice.sliceWidth / 2 + cam.Pos.X - Game1.SCREEN_WIDTH / 2, (float)InputManager.Instance.GetMousePositionY());
                sliceList.addSpriteReuse(newSlice);

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

            //PLAYER SLICE
            if (InputManager.Instance.KeyPressed(Keys.X) || InputManager.Instance.ButtonPressed(Buttons.RightShoulder))
            {
                if (player.canSlice == true)
                {
                    Slice newSlice = new Slice(player.getBoundingBoxMiddle().X - Slice.sliceWidth / 2, player.getBoundingBoxMiddle().Y);
                    sliceList.addSpriteReuse(newSlice);
                    player.Slice();
                    soundSlice.Play();
                }
            }

            if (InputManager.Instance.MousePressed(MouseButton.Right))
            {
                TestEnemy newEnemy = new TestEnemy(InputManager.Instance.GetMousePosition() + cam.Pos - new Vector2(Game1.SCREEN_WIDTH / 2 + 70 / 2, Game1.SCREEN_HEIGHT / 2 + 70 / 2));

                enemyList.addSpriteReuse(newEnemy);
                Console.WriteLine("targetSpawnPositions.Add(new Vector2(" + newEnemy.getPos().X + "," + newEnemy.getPos().Y + "));");
            }


            player.Update(gameTime);
            sliceList.Update(gameTime);
            particleList.Update(gameTime);
            enemyList.Update(gameTime);
            platformList.Update(gameTime);
            goal.Update(gameTime);

            //GOAL CONDITION
            if (player.getBoundingBoxAA().Intersects(goal.rectGoalZone))
            {
                if (player.IsOnGround)
                {
                    //WIN
                    player.SetCanPlayerMove(false);
                    player.velocity     = Vector2.Zero;
                    player.acceleration = new Vector2(0, 1000f);

                    NextLevel();
                }
            }



            //update abilities
            abilityIconDoubleJump.Update(gameTime);
            abilityIconDash.Update(gameTime);
            abilityIconSlice.Update(gameTime);


            //IF PLAYER IS OUT OF BOUNDS
            if (player.getPosX() < OutOfBounds.X || player.getPosX() > OutOfBounds.X + OutOfBounds.Width || player.getPosY() + player.getHeight() * 2 < OutOfBounds.Y || player.getPosY() > OutOfBounds.Y + OutOfBounds.Height)
            {
                soundDeath.Play();
                player.SetCanPlayerMove(false);
                player.AbilityReset();
                ResetPlayer();
            }



            //DETECT COLLISION BETWEEN SLICES AND TARGETS
            for (int i = 0; i < enemyList.count(); i++)
            {
                //Get current enemy to test.
                //If not active, skip.
                Sprite3 currentSprite = enemyList.getSprite(i);
                if (currentSprite == null)
                {
                    continue;
                }
                if (currentSprite.active != true)
                {
                    continue;
                }
                if (currentSprite.visible != true)
                {
                    continue;
                }
                if (currentSprite is Enemy == false)
                {
                    continue;
                }

                TestEnemy currentEnemy = currentSprite as TestEnemy;



                //Get current slice to test.
                //If not active, skip.
                for (int j = 0; j < sliceList.count(); j++)
                {
                    currentSprite = sliceList.getSprite(j);
                    if (currentSprite == null)
                    {
                        continue;
                    }
                    if (currentSprite.active != true)
                    {
                        continue;
                    }
                    if (currentSprite.visible != true)
                    {
                        continue;
                    }
                    if (currentSprite is Slice)
                    {
                        Slice currentSlice = currentSprite as Slice;
                        //loop thru all the current enemy's hitboxes until a slice collides with it.
                        for (int k = 0; k < currentEnemy.listHitbox.count(); k++)
                        {
                            Sprite3 currentHitBox = currentEnemy.listHitbox.getSprite(k);
                            if (currentHitBox == null)
                            {
                                continue;
                            }
                            if (currentHitBox.active != true)
                            {
                                continue;
                            }
                            if (currentEnemy.active == false)
                            {
                                continue;
                            }


                            //Check if the slice has hit anything else yet.
                            if (currentSlice.canHit == true)
                            {
                                //SLICE HIT THE ENEMYHITBOX.
                                if (currentSlice.collision(currentHitBox))
                                {
                                    float sliceWidth  = currentSlice.getBB().Width;
                                    float sliceLeft   = currentSlice.getBoundingBoxMiddle().X - sliceWidth / 2;
                                    float sliceRight  = currentSlice.getBoundingBoxMiddle().X + sliceWidth / 2;
                                    float hitboxWidth = currentHitBox.getBB().Width;
                                    float hitboxLeft  = currentHitBox.getBoundingBoxMiddle().X - hitboxWidth / 2;
                                    float hitboxRight = currentHitBox.getBoundingBoxMiddle().X + hitboxWidth / 2;

                                    if (sliceLeft <= hitboxLeft && sliceRight >= hitboxRight)
                                    {
                                        //Console.WriteLine("FULL CUT");
                                        soundSliceHit.Play();
                                        SliceParticle topSlice;
                                        float         scaleWidth  = currentHitBox.getWidth() / currentEnemy.getTextureBase().Width;
                                        float         scaleHeight = currentHitBox.getHeight() / currentEnemy.getTextureBase().Height;
                                        Vector2       ScaleVec    = new Vector2(scaleWidth, scaleHeight);


                                        Rectangle topDest = new Rectangle(currentHitBox.getBoundingBoxAA().X, currentHitBox.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, (int)currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y);
                                        float     topScaleX;
                                        float     topScaleY;
                                        Rectangle topSourceRect = new Rectangle(0, 0, (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight));
                                        //Rectangle topSourceRect = currentHitBox.texBase.Bounds;
                                        //Console.WriteLine("TOPSLICE: " + topDest.ToString());

                                        topSlice = new SliceParticle(topDest, currentEnemy.getTextureBase(), topSourceRect, ScaleVec, 0.8f, new Vector2(player.velocity.X / 2, -50 - Math.Abs(player.velocity.X)));
                                        particleList.addReuse(topSlice);

                                        SliceParticle bottomSlice;
                                        Rectangle     bottomDest       = new Rectangle(currentHitBox.getBoundingBoxAA().X, (int)currentSlice.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, currentHitBox.getBoundingBoxAA().Y + currentHitBox.getBoundingBoxAA().Height - currentSlice.getBoundingBoxAA().Y);
                                        Rectangle     bottomSourceRect = new Rectangle(0, (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight), (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)(currentEnemy.texBase.Height - ((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight)));
                                        bottomSlice = new SliceParticle(bottomDest, currentEnemy.getTextureBase(), bottomSourceRect, ScaleVec, -0.8f, new Vector2(player.velocity.X / 2, 0 - Math.Abs(player.velocity.X) / 2));
                                        particleList.addReuse(bottomSlice);
                                        //Console.WriteLine("BOTTOMSLICE: " + bottomDest.ToString());

                                        if (!currentEnemy.canRespawn)
                                        {
                                            currentEnemy.setActive(false);
                                        }
                                        else
                                        {
                                            currentEnemy.isDead = true;
                                        }


                                        currentEnemy.setVisible(false);

                                        player.AbilityReset();


                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 8
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);

            mainCamera = new Camera();



            //Load all the textures and fonts
            gameOverText         = Content.Load <SpriteFont>("MedievalFont");
            directions           = Content.Load <SpriteFont>("Gold");
            font                 = Content.Load <SpriteFont>("MedievalFont");
            difficultySelectText = Content.Load <SpriteFont>("MedievalFont");

            startText      = Content.Load <SpriteFont>("Gold");
            texStartBanner = Util.texFromFile(GraphicsDevice, dir + "startBanner.png");
            texGoldBanner  = Util.texFromFile(GraphicsDevice, dir + "goldBanner.png");
            texBook        = Util.texFromFile(GraphicsDevice, dir + "openBookWithText.png");
            texHorseRun    = Util.texFromFile(GraphicsDevice, dir + "horseRun.png");
            texEnemy       = Util.texFromFile(GraphicsDevice, dir + "Enemy.png");
            texBlood       = Util.texFromFile(GraphicsDevice, dir + "bloodSide.png");
            texArrow       = Util.texFromFile(GraphicsDevice, dir + "Arrow.png");
            texWorldMap    = Util.texFromFile(GraphicsDevice, dir + "FantasyWorldMap_2.png");

            //Define playarea
            playArea = new Rectangle(lhs, top, rhs - lhs, bot - top); // width and height

            //Load sprites and change size if necessary
            worldMap = new Sprite3(true, texWorldMap, -2000, -1000);
            worldMap.setWidthHeight(6400, 4800);
            book = new Sprite3(true, texBook, 50, 50);
            book.setWidthHeight(700, 500);
            startBanner = new Sprite3(true, texStartBanner, 0, 0);
            startBanner.setWidthHeight(800, 600);
            goldBanner = new Sprite3(true, texGoldBanner, 15, 15);
            goldBanner.setWidthHeight(130, 40);
            horse = new Sprite3(true, texHorseRun, xx, yy);



            //Load some empty spritelists
            enemies    = new SpriteList();
            bloodSplat = new SpriteList();
            horseRun   = new SpriteList();
            quiver     = new SpriteList();

            for (int a = 0; a < 5; a++)
            {
                arrow = new Sprite3(false, texArrow, 0, 0);
                arrow.setWidthHeight(arrow.getWidth() * 0.09f, arrow.getHeight() * 0.09f);
                quiver.addSpriteReuse(arrow);
            }

            //Used to change size of sprites
            float scale = 0.5f;


            //Player animation setup
            horse.setXframes(8);
            horse.setWidthHeight(1568 / 8 * scale, texHorseRun.Height * scale);
            horse.setBB(30, 10, (horse.getWidth() / scale) - 60, horse.getHeight() / scale - 20);
            for (int h = 0; h < anim.Length; h++)
            {
                anim[h].X = h;
            }
            horseRun.addSpriteReuse(horse);

            //enemy.setBBToTexture();

            //Enemy animation setup
            for (int k = 0; k < 100; k++)
            {
                enemy = new Sprite3(false, texEnemy, 850, 400);
                enemy.setXframes(10);
                enemy.setYframes(5);
                enemy.setWidthHeight(320 / 10, 160 / 5);
                enemy.setBB(0, 0, enemy.getWidth(), enemy.getHeight());
                int count = 0;
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        animEnemy[count].X = j;
                        animEnemy[count].Y = i;
                        count++;
                    }
                }
                enemy.setAnimationSequence(animEnemy, 20, 29, 15);
                enemy.setAnimFinished(0);
                enemy.animationStart();
                enemy.setVisible(false);
                enemies.addSpriteReuse(enemy);
            }
            //Load scrolling background images
            scrolling1 = new Scrolling(Util.texFromFile(GraphicsDevice, dir + "GPT Background 800x600.png"), new Rectangle(0, 0, 800, 600), scrollingSpeed);
            scrolling2 = new Scrolling(Util.texFromFile(GraphicsDevice, dir + "GPT Background2 800x600.png"), new Rectangle(800, 0, 800, 600), scrollingSpeed);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public override void Draw(GameTime gameTime)
        {
            if (score >= 300)
            {
                status = "NEXT LEVEL!";
            }
            else
            {
                status = "Missile Left: " + missileCount;
            }

            graphicsDevice.Clear(Color.Aqua);
            spriteBatch.Begin();

            Dir.background.Draw(spriteBatch);
            player.draw(spriteBatch);

            enemyList.Draw(spriteBatch);
            missileSmoke.Draw(spriteBatch);
            spriteBatch.DrawString(scoreFont, "Score: " + score + "/300", new Vector2(20, 20), Color.Black); // Draw Score on top left
            spriteBatch.DrawString(scoreFont, status, new Vector2(1100, 20), Color.Black);                   // Draw missile count

            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 (collision1 == true)
            {
                drawMissile = false;
                drawExplosion(currXMissile, currYMissile);
                enemy1.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                if (explostionTimer == 110)
                {
                    collision1      = false;
                    score          += 50;
                    explostionTimer = 0;
                    missileSmoke.deActivate();
                }
            }
            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 (collision3 == true)
            {
                drawMissile = false;
                drawExplosion(currXMissile, currYMissile);
                enemy3.setPos(Dir.rnd.Next(-400, -250), Dir.rnd.Next(200, 700));
                if (explostionTimer == 80)
                {
                    score          += 50;
                    collision3      = false;
                    explostionTimer = 0;
                    missileSmoke.deActivate();
                }
            }

            if (showBoundary)
            {
                //LineBatch.drawLineRectangle(spriteBatch, new Rectangle(1, 0, rightBoundary+4, bottomBoundary), Color.Blue);
                player.drawInfo(spriteBatch, Color.Yellow, Color.Red);
                missile.drawInfo(spriteBatch, Color.Black, Color.Red);
                enemyList.drawInfo(spriteBatch, Color.Yellow, Color.Purple);
            }
            spriteBatch.End();
        }
Ejemplo 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)
        {
            // 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);
        }
 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);
     }
 }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public override void LoadContent()
        {
            enemyList = 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);
            enemy3YLocation = enemyYLocation + Dir.rnd.Next(100, 200);

            // Image Locations
            Dir.texBackground      = 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\explode1.png");

            scoreFont       = Content.Load <SpriteFont>("display");
            helpFont        = Content.Load <SpriteFont>("helpText");
            explostionSound = Content.Load <SoundEffect>("bazooka_fire");
            exLimSound      = new LimitSound(explostionSound, 3);

            // Set Sprites
            Dir.background     = new ImageBackground(Dir.texBackground, Color.White, graphicsDevice);
            player             = new Sprite3(true, texPlayer, playerXLocation, playerYLocation);
            enemy1             = new Sprite3(true, texEnemy1, enemyXLocation, enemyYLocation);
            enemy2             = new Sprite3(true, texEnemy2, enemy2XLocation, enemyYLocation);
            enemy3             = new Sprite3(true, texEnemy1, enemyXLocation, enemy3YLocation);
            missile            = new Sprite3(true, texMissile, playerXLocation, playerYLocation);
            explosionAnimation = new Sprite3(true, texExplostionAnimation, 0, playerYLocation);

            // Adjusting sprite image sizes to suit my taste
            player.setWidthHeight(210, 64);
            enemy1.setWidthHeight(256, 64);
            enemy2.setWidthHeight(enemy1.getWidth() / 2, 64);
            enemy3.setWidthHeight(256, 64);
            missile.setWidthHeight(missile.getWidth() / 2, missile.getHeight() / 2);

            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 h3 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true);

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

            // Add to sprite list
            enemyList.addSpriteReuse(enemy1);
            enemyList.addSpriteReuse(enemy2);
            enemyList.addSpriteReuse(enemy3);

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

            drawSmoke();
        }
Ejemplo n.º 16
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            selector.Update(gameTime);

            //MOVE OPTION
            if (InputManager.Instance.KeyPressed(Keys.Up) || InputManager.Instance.ButtonPressed(Buttons.DPadUp))
            {
                menuSelector -= 1;
                if (menuSelector < 0)
                {
                    menuSelector = menuStrings.Count - 1;
                }
                soundMenu.Play();
            }
            if (InputManager.Instance.KeyPressed(Keys.Down) || InputManager.Instance.ButtonPressed(Buttons.DPadDown))
            {
                menuSelector += 1;
                if (menuSelector > menuStrings.Count - 1)
                {
                    menuSelector = 0;
                }
                soundMenu.Play();
            }

            //SELECT OPTION
            if (notSelected)
            {
                if (InputManager.Instance.KeyPressed(Keys.Z) || InputManager.Instance.ButtonPressed(Buttons.A))
                {
                    notSelected = false;
                    switch (menuStrings[menuSelector])
                    {
                    case "START GAME":
                        BaseLevel.isChallengeMode = false;
                        Task.Delay(1000).ContinueWith(t => gameStateManager.setLevel(1));
                        break;

                    case "TUTORIAL":
                        BaseLevel.isChallengeMode = false;
                        Task.Delay(1000).ContinueWith(t => gameStateManager.setLevel(0));
                        break;

                    case "EXIT GAME":
                        Task.Delay(1000).ContinueWith(t => Game1.game1.Exit());
                        break;

                    case "CHALLENGE MODE":
                        BaseLevel.isChallengeMode = true;
                        Task.Delay(1000).ContinueWith(t => gameStateManager.setLevel(1));
                        break;

                    default:
                        Game1.game1.Exit();
                        break;
                    }
                    sliceList.addSpriteReuse(new Slice(selector.getPosX(), selector.getPosY() + selector.getHeight() / 2));
                }
            }

            //
            particleList.Update(gameTime);
            sliceList.Update(gameTime);

            //DETECT COLLISION BETWEEN SLICES AND TARGETS
            for (int i = 0; i < enemyList.count(); i++)
            {
                //Get current enemy to test.
                //If not active, skip.
                Sprite3 currentSprite = enemyList.getSprite(i);
                if (currentSprite == null)
                {
                    continue;
                }
                if (currentSprite.active != true)
                {
                    continue;
                }
                if (currentSprite.visible != true)
                {
                    continue;
                }
                if (currentSprite is Enemy == false)
                {
                    continue;
                }

                Enemy currentEnemy = currentSprite as Enemy;


                //Get current slice to test.
                //If not active, skip.
                for (int j = 0; j < sliceList.count(); j++)
                {
                    currentSprite = sliceList.getSprite(j);
                    if (currentSprite == null)
                    {
                        continue;
                    }
                    if (currentSprite.active != true)
                    {
                        continue;
                    }
                    if (currentSprite.visible != true)
                    {
                        continue;
                    }
                    if (currentSprite is Slice)
                    {
                        Slice currentSlice = currentSprite as Slice;
                        //loop thru all the current enemy's hitboxes until a slice collides with it.
                        for (int k = 0; k < currentEnemy.listHitbox.count(); k++)
                        {
                            Sprite3 currentHitBox = currentEnemy.listHitbox.getSprite(k);
                            if (currentHitBox == null)
                            {
                                continue;
                            }
                            if (currentHitBox.active != true)
                            {
                                continue;
                            }
                            if (currentEnemy.active == false)
                            {
                                continue;
                            }


                            //Check if the slice has hit anything else yet.
                            if (currentSlice.canHit == true)
                            {
                                //SLICE HIT THE ENEMYHITBOX.
                                if (currentSlice.collision(currentHitBox))
                                {
                                    float sliceWidth  = currentSlice.getBB().Width;
                                    float sliceLeft   = currentSlice.getBoundingBoxMiddle().X - sliceWidth / 2;
                                    float sliceRight  = currentSlice.getBoundingBoxMiddle().X + sliceWidth / 2;
                                    float hitboxWidth = currentHitBox.getBB().Width;
                                    float hitboxLeft  = currentHitBox.getBoundingBoxMiddle().X - hitboxWidth / 2;
                                    float hitboxRight = currentHitBox.getBoundingBoxMiddle().X + hitboxWidth / 2;

                                    if (sliceLeft <= hitboxLeft && sliceRight >= hitboxRight)
                                    {
                                        //Console.WriteLine("FULL CUT");
                                        BaseLevel.soundSliceHit.Play();
                                        SliceParticle topSlice;
                                        float         scaleWidth  = currentHitBox.getWidth() / currentEnemy.getTextureBase().Width;
                                        float         scaleHeight = currentHitBox.getHeight() / currentEnemy.getTextureBase().Height;
                                        Vector2       ScaleVec    = new Vector2(scaleWidth, scaleHeight);


                                        Rectangle topDest = new Rectangle(currentHitBox.getBoundingBoxAA().X, currentHitBox.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, (int)currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y);
                                        float     topScaleX;
                                        float     topScaleY;
                                        Rectangle topSourceRect = new Rectangle(0, 0, (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight));
                                        //Rectangle topSourceRect = currentHitBox.texBase.Bounds;
                                        //Console.WriteLine("TOPSLICE: " + topDest.ToString());

                                        topSlice = new SliceParticle(topDest, currentEnemy.getTextureBase(), topSourceRect, ScaleVec, 0.8f, new Vector2(200, -50 - Math.Abs(100)));
                                        particleList.addReuse(topSlice);

                                        SliceParticle bottomSlice;
                                        Rectangle     bottomDest       = new Rectangle(currentHitBox.getBoundingBoxAA().X, (int)currentSlice.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, currentHitBox.getBoundingBoxAA().Y + currentHitBox.getBoundingBoxAA().Height - currentSlice.getBoundingBoxAA().Y);
                                        Rectangle     bottomSourceRect = new Rectangle(0, (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight), (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)(currentEnemy.texBase.Height - ((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight)));
                                        bottomSlice = new SliceParticle(bottomDest, currentEnemy.getTextureBase(), bottomSourceRect, ScaleVec, -0.8f, new Vector2(-100, 0 - Math.Abs(-5)));
                                        particleList.addReuse(bottomSlice);
                                        //Console.WriteLine("BOTTOMSLICE: " + bottomDest.ToString());

                                        currentEnemy.setActive(false);
                                        currentEnemy.setVisible(false);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 17
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.º 18
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);
                }
            }
        }