Beispiel #1
0
        public GamePlayScreen(Game1 game)
            : base(game, 0, 0)
        {
            ball = new Ball(0, 0, game.Content.Load <Texture2D>("ball"), 0.7f, 0.5f, 12.0f, 0.99f, this.getGame());
            bat  = new Bat(game.getScreenWidth() / 2 - game.Content.Load <Texture2D>("bat").Width / 2, game.getScreenHeight() - 50, game.Content.Load <Texture2D>("bat"), this.getGame());

            scoreHUD = new HUDScore(new Vector2(10, 10), game.Content.Load <SpriteFont>("Arial"), 0);
            livesHUD = new HUDLives(new Vector2(10, 30), game.Content.Load <SpriteFont>("Arial"), 5);

            pop = game.Content.Load <SoundEffect>("pop");

            levels = new Levels(game);
            SetUpLevel(game, levels.getLevel(currentLevel));
        }
Beispiel #2
0
        public bool checkCollision(Bat bat)
        {
            var batRect = bat.getRectangle();
            var hit     = checkCollision(batRect);

            if (hit)
            {
                Vector2 ballCentre = getBallCentre();
                int     py         = rect.Y;
                int     px         = rect.X;

                Region ballRegion = region(ballCentre, batRect);
                if (ballRegion == Region.TopCentre)
                {
                    var cx   = batRect.Center.X;
                    var sign = Math.Sign(direction.X);

                    if (bat.hasBatMovedLeft() && sign == 1)
                    {
                        this.setVelocityX(-this.getVelocity().X);
                    }

                    if (bat.hasBatMovedRight() && sign == -1)
                    {
                        this.setVelocityX(-this.getVelocity().X);
                    }

                    /*if (ballCentre.X < cx && sign == 1) {
                     *  this.setVelocityX(-this.getVelocity().X);
                     * }
                     *
                     * if (ballCentre.X > cx && sign == -1) {
                     *  this.setVelocityX(-this.getVelocity().X);
                     * }*/
                }
            }

            return(hit);
        }