/// <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(); } spelare.Update(gameTime); boll.Update(gameTime); // TODO: Add your update logic here if (boll.Rec.Intersects(spelare.Rec)) { boll.StudsaBräda(); } foreach (Kloss element in klosslista) { if (boll.Rec.Intersects(element.Rec)) { boll.StudsaX(false); element.Krossa(); ljud.Play(); } } if (boll.Rec.Intersects(vägg1)) { boll.StudsaX(true); } if (boll.Rec.Intersects(vägg2)) { boll.StudsaX(true); } if (boll.Rec.Intersects(tak)) { boll.StudsaX(false); } if (boll.Rec.Intersects(golv)) { Exit(); } base.Update(gameTime); }
/// <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(); spelare.Update(gameTime); boll.Update(gameTime); // TODO: Add your update logic here //bollen studsar om den träffar spelaren if (boll.Rec.Intersects(spelare.Rec)) { boll.StudsaBräda(); } foreach (Kloss element in klosslista) { //studsar om den träffar en kloss if (boll.Rec.Intersects(element.Rec)) { //studsar åt rätt håll if (boll.Rec.Intersects(element.Rec2)) { boll.StudsaX(false); element.Krossa(); poäng.AddPoint(); } else if (boll.Rec.Intersects(element.Rec1)) { boll.StudsaX(true); element.Krossa(); poäng.AddPoint(); } else if (boll.Rec.Intersects(element.Rec3)) { boll.StudsaX(true); element.Krossa(); poäng.AddPoint(); } else if (boll.Rec.Intersects(element.Rec4)) { boll.StudsaX(false); element.Krossa(); poäng.AddPoint(); } } } //studsa på väggarna if (boll.Rec.Intersects(vägg1)) { boll.StudsaX(true); } if (boll.Rec.Intersects(vägg2)) { boll.StudsaX(true); } if (boll.Rec.Intersects(tak)) { boll.StudsaX(false); } if (boll.Rec.Intersects(golv)) { Exit(); } base.Update(gameTime); }