public override void Update(GameTime gameTime)
 {
     if (sb1 != null)
     {
         sb1.Update(gameTime);
     }
     if (sb2 != null)
     {
         sb2.Update(gameTime);
     }
     if (sb3 != null)
     {
         sb3.Update(gameTime);
     }
     if (sb4 != null)
     {
         sb4.Update(gameTime);
     }
 }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            //int mgStates = 0; // game state
            // 0=waiting startup
            // 1=playing
            // 2=waiting for respawn
            // 3=Ending count You Win
            // 4=Ending count You Looser
            // 5=Game over You Winner
            // 6=Game over You Looser

            ticks++;
            if (mgState == 2)
            {
                timeIn2++;
            }
            if (mgState == 5 || mgState == 6)
            {
                timeIn5or6++;
            }

            if (playStyle == 1)
            {
                return;                 // frozen
            }
            KeyboardState keyState = Keyboard.GetState();

            if (mgState == 3 || mgState == 4)
            {
                endingCount++;
            }
            if (mgState == 3 && targets.countActive() == 0 && endingCount > endingCountMax)
            {
                mgState = 5;
            }
            if (mgState == 4 && endingCount > endingCountMax)
            {
                mgState = 6;
            }

            if (mgState == 1 || mgState == 3)
            {
                checkIfIAmShot();
            }

            if (mgState == 2)
            {
                if (targets.countActive() == 0 && timeIn2 > timeIn2Max)
                {
                    mgState = 1;
                }
            }
            prevX = shooter.getPosX();
            if (playStyle == 2)
            {
                automove();     // auto playing fire();
            }
            if (playStyle == 0) // playing using keyboard
            {
                if (keyState.IsKeyDown(Keys.Space) && prevKeyState.IsKeyUp(Keys.Space))
                {
                    fire();
                }
                if (keyState.IsKeyDown(Keys.Left))
                {
                    shooter.setPosX(shooter.getPosX() - shooterSpeed);
                    if (shooter.getPosX() < innerRectangle.X)
                    {
                        shooter.setPosX(prevX);
                    }
                }
                if (keyState.IsKeyDown(Keys.Right))
                {
                    shooter.setPosX(shooter.getPosX() + shooterSpeed);
                    if (shooter.getPosX() + actualShooterSize.X > innerRectangle.X + innerRectangle.Width)
                    {
                        shooter.setPosX(prevX);
                    }
                }

                if (keyState.IsKeyDown(Keys.B) && !prevKeyState.IsKeyDown(Keys.B))
                {
                    showbb = !showbb;
                }

                //moveBullets();
                //if (mgState == 1) generateAliens();
                //targets.moveDeltaXY_A(true);
                //int i = targets.removeIfOutside(innerRectangle);
                //adjustScore(i * scoreIfTargetEscapes, -900, -900);
                //targets.animationTick();
            }

            if (playStyle == 2 || playStyle == 0)
            {
                moveBullets();
                if (mgState == 1)
                {
                    generateAliens();
                }
                targets.moveDeltaXY();
                int i = targets.removeIfOutside(innerRectangle);
                adjustScore(i * scoreIfTargetEscapes, -900, -900);
                targets.animationTick(gameTime);
                explosions.Update(gameTime);
                eyeCandy.Update(gameTime);
            }

            if (backGround != null)
            {
                backGround.Update(gameTime);
            }
            if (mgState == 0)
            {
                UpdateMG0();
            }
            if (mgState == 5)
            {
                UpdateMG5();
            }
            if (mgState == 6)
            {
                UpdateMG6();
            }
            prevKeyState = keyState;
        }