Ejemplo n.º 1
0
        /// <summary>
        ///  Update metod som "resettar" spelets state tillbaka till ursprung, kollar också ifall bollen är utanför skärmen(hela tiden)
        ///  Har också timer för att pausa mellan ronderna efter bollen gått bakom respektive sida går denna timer av och varar i 3 sekunder.
        /// </summary>
        #region Update metod
        public void Update(Paddle leftPaddle, Paddle rightPaddle, Ball ball1, GameWindow Window, Bonus box, GameTime gameTime)
        {
            if (ball1.BallPos.X <= 0 || ball1.BallPos.X >= 785)
            {
                newRound = true;
            }

            if (newRound == false)
            {
                startRound = true;
            }

            //ifall bollen gått längre än 785 på x värdet så får spelare 1 poäng och spelet resettas
            if (ball1.BallPos.X >= 785)
            {
                Score_1++;
                box.Intersect = false;

                ball1.BallPos = new Vector2((Window.ClientBounds.Width / 2) - 20, (Window.ClientBounds.Height / 2) - 20);

                leftPaddle.PaddlePos  = new Vector2(0, 340);
                rightPaddle.PaddlePos = new Vector2(779, 340);

                leftPaddle.PaddleHitbox  = new Rectangle((int)leftPaddle.PaddlePos.X, (int)leftPaddle.PaddlePos.Y, 21, 148);
                rightPaddle.PaddleHitbox = new Rectangle((int)rightPaddle.PaddlePos.X, (int)rightPaddle.PaddlePos.Y, 21, 148);

                box.BonusPos = new Vector2(1000, 1000);

                //Kollar ifall paddeln är liten, isåfall gör den stor igen nästa runda
                leftPaddle.Small = false;
                leftPaddle.Big   = true;

                rightPaddle.Small = false;
                rightPaddle.Big   = true;
            }

            //ifall bollen gått mindre än 0 på x värdet så får spelare 2 poäng och spelet resettas
            if (ball1.BallPos.X <= 0)
            {
                Score_2++;

                box.Intersect = false;

                ball1.BallPos = new Vector2((Window.ClientBounds.Width / 2) - 20, (Window.ClientBounds.Height / 2) - 20);

                leftPaddle.PaddlePos  = new Vector2(0, 340);
                rightPaddle.PaddlePos = new Vector2(779, 340);

                leftPaddle.PaddleHitbox  = new Rectangle((int)leftPaddle.PaddlePos.X, (int)leftPaddle.PaddlePos.Y, 21, 148);
                rightPaddle.PaddleHitbox = new Rectangle((int)rightPaddle.PaddlePos.X, (int)rightPaddle.PaddlePos.Y, 21, 148);

                box.BonusPos = new Vector2(1000, 1000);

                //Kollar ifall paddeln är liten, isåfall gör den stor igen nästa runda
                leftPaddle.Small = false;
                leftPaddle.Big   = true;

                rightPaddle.Small = false;
                rightPaddle.Big   = true;
            }

            //Timer som pausar spelet direkt efter en spelare gjort mål, spelet pausas i 3 sekunder
            if (newRound == true)
            {
                timer     += gameTime.ElapsedGameTime.TotalSeconds;
                startRound = false;

                if (timer >= 3)
                {
                    timer      = 0;
                    newRound   = false;
                    startRound = true;
                }
            }
        }
Ejemplo n.º 2
0
 protected override void LoadContent()
 {
     this.spriteBatch = new SpriteBatch(GraphicsDevice);
     explosionSpriteP1 = Content.Load<Texture2D>("explosion");
     explosionSpriteP2 = Content.Load<Texture2D>("explosion");
     shieldTexture = Content.Load<Texture2D>("shield_anim");
     exp = Content.Load<SoundEffect>("soundExplosion");
     this.p1.loadContent(Content, "green_tank_base");
     this.p2.loadContent(Content, "orange_tank_base");
     this.game_font = Content.Load<SpriteFont>("SquaredDisplay");
     this.ui = Content.Load<Texture2D>("ui_repeat");
     this.background = Content.Load<Texture2D>("background");
     this.road = Content.Load<Texture2D>("road");
     this.tree = Content.Load<Texture2D>("tree");
     this.life_p1 = Content.Load<Texture2D>("lifebar");
     this.life_p2 = Content.Load<Texture2D>("lifebar2");
     this.xbox_button_a = Content.Load<Texture2D>("Xbox A Button");
     this.key_r = Content.Load<Texture2D>("Key R");
     Bonus speed = new Bonus("SPEED", Window.ClientBounds.Width / 2, 0);
     speed.loadContent(Content, "speed");
     listBonus.Add(speed);
     Bonus shield = new Bonus("SHIELD", Window.ClientBounds.Width / 2, 0);
     shield.loadContent(Content, "shield");
     listBonus.Add(shield);
     Bonus canon = new Bonus("CANON", Window.ClientBounds.Width / 2, 0);
     canon.loadContent(Content, "canon");
     listBonus.Add(canon);
 }