Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            ticks++;

            //load animation
            //anmiation1.animationTick();
            dragonList.animationTick();
            if (scrolling1.rectangle.X + scrolling1.texture.Width <= 0)
            {
                scrolling1.rectangle.X = scrolling2.rectangle.X + scrolling2.texture.Width;
            }
            if (scrolling2.rectangle.X + scrolling2.texture.Width <= 0)
            {
                scrolling2.rectangle.X = scrolling1.rectangle.X + scrolling1.texture.Width;
            }

            scrolling1.Update();
            scrolling2.Update();

            for (int i = 0; i < dragonList.count(); i++)
            {
                Sprite3 s = dragonList.getSprite(i);
                if (s == null)
                {
                    continue;
                }
                if (!s.active)
                {
                    continue;
                }
                if (!s.visible)
                {
                    continue;
                }
                if (ball.getBoundingBoxAA().Intersects(s.getBoundingBoxAA()))
                {
                    baz.Play();
                    s.setActive(false);
                    scoure++;
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                    setSys5();
                    p.Update(gameTime);
                }
            }

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

            if (k.IsKeyDown(Keys.Right))
            {
                if (paddle.getPosX() < rhs - texpaddle.Width)
                {
                    paddle.setPosX(paddle.getPosX() + paddleSpeed);
                }
            }

            if (k.IsKeyDown(Keys.Left))
            {
                if (paddle.getPosX() > lhs)
                {
                    paddle.setPosX(paddle.getPosX() - paddleSpeed);
                }
            }

            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
            }

            //if (ballStuck)
            //{
            //    ball.setPos(paddle.getPos() + ballOffset);
            //    if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
            //    {
            //        ballStuck = false;
            //        ball.setDeltaSpeed(new Vector2(1, -3));
            //    }
            //}
            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
            }

            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
                if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
                {
                    ballStuck = false;
                    ball.setDeltaSpeed(new Vector2(2, -3));
                }
            }
            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
                Rectangle ballbb = ball.getBoundingBoxAA();

                if (ballbb.X + ballbb.Width > rhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.X < lhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.Y < top)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }

                //pedal intersects

                if (ballbb.Intersects(paddle.getBoundingBoxAA()))

                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }
            }
            if (k.IsKeyDown(Keys.P))
            {
                gameStateManager.setLevel(0);
            }
            if (k.IsKeyDown(Keys.M))
            {
                gameStateManager.setLevel(0);
                ball.setPos(xx, yy);
                paddle.setPos(xx, bot - texpaddle.Height);
                scoure = 0;
                //ball.setDeltaSpeed(new Vector2(0,0));
                for (int i = 0; i < dragonList.count(); i++)
                {
                    Sprite3 s = dragonList.getSprite(i);
                    s.setActive(true);
                }
            }


            if (ball.getPosY() > bot)
            {
                gameStateManager.setLevel(5);
                ball.setPos(xx, yy);
                paddle.setPos(xx, bot - texpaddle.Height);
                scoure = 0;
                //ball.setDeltaSpeed(new Vector2(0,0));
                for (int i = 0; i < dragonList.count(); i++)
                {
                    Sprite3 s = dragonList.getSprite(i);
                    s.setActive(true);
                    // p.Update(gameTime);
                }
            }
            // next leve condition
            if (scoure >= 15)
            {
                gameStateManager.setLevel(0);
                limSound.playSound();
            }
            ballPos = new Vector2(ball.getPosX(), ball.getPosY());
            if (p != null)
            {
                p.Update(gameTime);
            }
            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            prevK = k;
            k     = Keyboard.GetState();

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

            if (k.IsKeyDown(Keys.Right))
            {
                if (paddle.getPosX() < rhs - texpaddle.Width)
                {
                    paddle.setPosX(paddle.getPosX() + paddleSpeed);
                }
            }

            if (k.IsKeyDown(Keys.Left))
            {
                if (paddle.getPosX() > lhs)
                {
                    paddle.setPosX(paddle.getPosX() - paddleSpeed);
                }
            }
            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
                if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
                {
                    ballStuck = false;
                    ball.setDeltaSpeed(new Vector2(2, -3));
                }
            }

            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
                Rectangle ballbb = ball.getBoundingBoxAA();

                if (ballbb.X + ballbb.Width > rhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.X < lhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.Y < top)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }

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



            // TODO: Add your update logic here

            base.Update(gameTime);
        }