protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            if (currentGameState == GameState.Playing1 || currentGameState == GameState.Playing2)
            {
                //Increase the timer by the number of milliseconds since update was last called
                timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                interval += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                KeyboardState keyboardState = Keyboard.GetState();
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    blueTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                    controller.MoveArrowRight();
                }
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    blueTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                    controller.MoveArrowLeft();
                }
                if (keyboardState.IsKeyDown(Keys.Up) || interval >= AUTO_FIRE)
                {
                    movingBall = loadedBall;
                    if (loadedBall.velocity.Y == 0)
                    {
                        Stats.ballsFired++;
                        movingBall.velocity = 10 * controller.getArrowVector();
                    }
                    interval = 0;
                }

                if (movingBall != null)
                {
                    greenTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (greenTimer >= SPRITE_TIMER - 25)
                    {
                        greenCurrentFrame = (greenCurrentFrame+1);
                        if (greenCurrentFrame >= 4)
                            greenCurrentFrame = 3;
                        greenTimer = 0;
                    }
                    movingBall.Move();
                    if (controller.collides(movingBall))
                    {
                        greenTimer = 0;
                        greenCurrentFrame = 0;

                        movingBall.texture = pokeBalls;
                        controller.addBubble(movingBall);
                        controller.popBubbles(movingBall);
                        controller.fallBubbles();

                        loadedBall = sackBall;
                        loadedBall.positionPixels = new Vector2(306, 360);
                        loadedBall.worldPosition = new Vector3(0, -10, 0);

                        sackBall = new Bubble((PuzzleBobbleA2.Bubble.Colors)controller.generateColor());
                        movingBall = null;
                    }
                }
                //Check to see if we shoudl drop down one level
                if (Stats.ballsFired >= (controller.ceiling + 1) * (Stats.bubbleCount / 2 + (DIFFICULTY_RATING - controller.level)))
                {
                    controller.ceiling++;
                }

                //Check the timer is more than the chosen interval
                controller.Pop(gameTime);
                if (controller.GameOver())
                {
                    currentGameState = GameState.GameOver;
                    //this.Exit();
                }
                if (blueTimer >= SPRITE_TIMER)
                {
                    blueTimer = 0;
                    blueCurrentFrame = (blueCurrentFrame + 1) % 6;
                }

            }
            if (currentGameState == GameState.Playing2)
            {
                if (Stats.bubbleCount == 0 && controller.fallingBubbles.Count == 0 && controller.poppingBubbles.Count == 0)
                {
                    currentGameState = GameState.Credits;
                    //controller = new GameController(1);
                    //Initialize();
                }
                return;
            }
            if (currentGameState == GameState.Playing1)
            {
                if (Stats.bubbleCount == 0 && controller.fallingBubbles.Count == 0 && controller.poppingBubbles.Count == 0)
                {
                    currentGameState = GameState.Playing2;
                    controller = new GameController(2, graphics);
                    int oldscore = Stats.score;
                    Initialize();
                    Stats.score = oldscore;
                }
                return;
            }
            if (currentGameState == GameState.MainMenu)
            {
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (keyboardState1.IsKeyDown(Keys.Space))
                {
                    currentGameState = GameState.Playing1;
                }
                return;
            }
            if (currentGameState == GameState.GameOver)
            {
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (keyboardState1.IsKeyDown(Keys.Space))
                {
                    currentGameState = GameState.Playing1;
                    controller = new GameController(1, graphics);
                    Initialize();
                }
                return;
            }
            if (currentGameState == GameState.Credits)
            {
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (keyboardState1.IsKeyDown(Keys.Space))
                {
                    currentGameState = GameState.MainMenu;
                    controller = new GameController(1, graphics);
                    Initialize();
                }
                return;
            }

            base.Update(gameTime);
        }
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

               //     graphics.IsFullScreen = true;
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            controller = new GameController(1, graphics);
        }
Esempio n. 3
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            if (currentGameState == GameState.Playing1 || currentGameState == GameState.Playing2)
            {
                //Increase the timer by the number of milliseconds since update was last called
                timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                interval += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                KeyboardState keyboardState = Keyboard.GetState();
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    blueTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                    controller.MoveArrowRight();
                }
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    blueTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                    controller.MoveArrowLeft();
                }
                if (keyboardState.IsKeyDown(Keys.Up) || interval >= AUTO_FIRE )
                {
                    movingBall = loadedBall;
                    if (loadedBall.velocity3D.Length() == 0)
                    {
                        Stats.ballsFired++;
                        movingBall.heading = (float)Math.Atan(controller.getArrowVector().X / controller.getArrowVector().Y);
                        movingBall.velocity3D = new Vector3(-INITIAL_VELOCITY * (float)Math.Sin(movingBall.heading), 0, -INITIAL_VELOCITY * (float)Math.Cos(movingBall.heading));
                    }
                    interval = 0;
                }
                if (keyboardState.IsKeyDown(Keys.W))
                {
                   // view = Matrix.CreateLookAt(new Vector3(0, viewDist++, 10), new Vector3(0, 0, 0), Vector3.UnitY);
                    angle = 0.005f;
                    view = view * Matrix.CreateRotationX(angle);
                }
                if (keyboardState.IsKeyDown(Keys.S))
                {
                   // view = Matrix.CreateLookAt(new Vector3(0, viewDist--, 10), new Vector3(0, 0, 0), Vector3.UnitY);
                    angle = -0.005f;
                    view = view * Matrix.CreateRotationX(angle);
                }
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    view = Matrix.CreateLookAt(new Vector3(pane--, 0, 10), new Vector3(0, 0, 0), Vector3.UnitY);
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    view = Matrix.CreateLookAt(new Vector3(pane++, 0, 10), new Vector3(0, 0, 0), Vector3.UnitY);
                }
                if (keyboardState.IsKeyDown(Keys.D1))
                {
                    view = Matrix.CreateLookAt(new Vector3(0, -11, 16), new Vector3(0, -10f, 15), Vector3.UnitY);
                }
                if (keyboardState.IsKeyDown(Keys.D3))
                {
                    view = Matrix.CreateLookAt(new Vector3(0, -5, 25), new Vector3(0, 2f, 0), Vector3.UnitY);
                }

                if (movingBall != null)
                {
                    greenTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (greenTimer >= SPRITE_TIMER - 25)
                    {
                        greenCurrentFrame = (greenCurrentFrame+1);
                        if (greenCurrentFrame >= 4)
                            greenCurrentFrame = 3;
                        greenTimer = 0;
                    }
                    sackBall.Roll();
                    movingBall.Move();
                    if (controller.collides(movingBall))
                    {
                        greenTimer = 0;
                        greenCurrentFrame = 0;

                        movingBall.texture = pokeBalls;
                        controller.addBubble(movingBall);
                        controller.popBubbles(movingBall);
                        controller.fallBubbles();

                        loadedBall = sackBall;
                        loadedBall.positionPixels = new Vector2(306, 360);
                        loadedBall.worldPosition = new Vector3(0, 1-RAMP_SIZE, RAMP_SIZE - 2);

                        sackBall = new Bubble((PuzzleBobbleA2.Bubble.Colors)controller.generateColor());
                        movingBall = null;
                    }
                }
                //Check to see if we shoudl drop down one level
                if (Stats.ballsFired >= (controller.ceiling + 1) * (Stats.bubbleCount / 2 + (DIFFICULTY_RATING - controller.level)))
                {
                   controller.ceiling++;
                }

                //Check the timer is more than the chosen interval
                controller.Pop(gameTime);
                if (controller.GameOver())
                {
                    currentGameState = GameState.GameOver;
                    //this.Exit();
                }
                if (blueTimer >= SPRITE_TIMER)
                {
                    blueTimer = 0;
                    blueCurrentFrame = (blueCurrentFrame + 1) % 6;
                }

            }

            int count = 0;
            //CHECK FOR BUBBLE COUNT INCONSISTENCY
            foreach (Bubble b in controller.grid)
            {
                if (b != null)
                    count++;
            }
            if (Stats.bubbleCount != count)
            {
                Stats.bubbleCount = count;
            }

            if (currentGameState == GameState.Playing2)
            {
                if (count == 0 && controller.fallingBubbles.Count == 0 && controller.poppingBubbles.Count == 0)
                {
                    currentGameState = GameState.Credits;
                    //controller = new GameController(1);
                    //Initialize();
                }
                return;
            }
            if (currentGameState == GameState.Playing1)
            {

                if (count == 0 && controller.fallingBubbles.Count == 0 && controller.poppingBubbles.Count == 0)
                {
                    currentGameState = GameState.Playing2;
                    controller = new GameController(2, graphics);
                    int oldscore = Stats.score;
                    Initialize();
                    Stats.score = oldscore;
                }
                return;
            }
            if (currentGameState == GameState.MainMenu)
            {
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (keyboardState1.IsKeyDown(Keys.Space))
                {
                    currentGameState = GameState.Playing1;
                }
                return;
            }
            if (currentGameState == GameState.GameOver)
            {
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (keyboardState1.IsKeyDown(Keys.Space))
                {
                    currentGameState = GameState.Playing1;
                    controller = new GameController(1, graphics);
                    Initialize();
                }
                return;
            }
            if (currentGameState == GameState.Credits)
            {
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (keyboardState1.IsKeyDown(Keys.Space))
                {
                    currentGameState = GameState.MainMenu;
                    controller = new GameController(1, graphics);
                    Initialize();
                }
                return;
            }

            base.Update(gameTime);
        }