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); }
public void UpdateL1(GameTime gameTime) { ks = Keyboard.GetState(); yarnBalls.moveDeltaXY(); // collision test for (int i = 0; i < yarnBalls.count(); i++) { Sprite3 s = yarnBalls.getSprite(i); bool coll = playerSprite.collision(s); if (coll) { kachingSound.playSoundIfOk(); s.setActive(false); points++; } } // used to move the kitty cat to the left if (ks.IsKeyDown(Keys.Left)) { playerSprite.moveByDeltaXY(); playerSprite.animationTick(gameTime); successSound.playSoundIfOk(); playerSprite.active = true; background.Update(gameTime); } if (ks.IsKeyDown(Keys.Right)) { // NOTE: the move right functionality does not work currently background.Update(gameTime); } if (ks.IsKeyDown(Keys.B)) { showBB = !showBB; } /// increases the player's jump speed - this is a secret function if (ks.IsKeyDown(Keys.Z)) { playerJumpSpeed++; } // decreases the player's jump speed - this is another secret function if (ks.IsKeyDown(Keys.X)) { playerJumpSpeed--; } // this gives the small kitty cat the ability to jump around the screen if (playerJump) { playerVec.Y += playerJumpSpeed; playerJumpSpeed += 1; playerSprite.setPosY(playerVec.Y); if (playerVec.Y >= prevPos.Y) { playerSprite.setPosY(prevPos.Y); playerJump = false; } } else { if (ks.IsKeyDown(Keys.Up)) { playerJump = true; jumpoSound.playSoundIfOk(); playerJumpSpeed = -14; playerSprite.setPosY(playerVec.Y); } } // transition over to level 2 if (points == 5) { state = 3; } }
public void UpdateL2(GameTime gameTime) { // the crazy dog will be running towards the right and will // appear randomly on the screen crazyDog.visible = true; crazyDog.moveByDeltaXY(); crazyDog.animationTick(gameTime); crazyDog.active = true; doggyVec.X++; crazyDog.setPosX(doggyVec.X); if (crazyDog.getPosX() > 800) { doggyVec.X = 0; } if (doggyVec.X == 20 || doggyVec.X == 400) { barkoSound.playSoundIfOk(); } // check whether the player sprite has clashed with the crazy dog colWBB = playerSprite.collision(crazyDog); // play the sound if this is true if (colWBB == true && doggyVec.X == playerVec.X) { yowlinSound.playSoundIfOk(); lives--; } // play the kaching sound if the player sprite passes over // the dog and also does not colide if (colWBB == false && doggyVec.X == playerVec.X) { kachingSound.playSoundIfOk(); points++; } ks = Keyboard.GetState(); // this is really bad practice to repeat code from another method // but have no time right now to implement something better if (ks.IsKeyDown(Keys.Left)) { playerSprite.moveByDeltaXY(); playerSprite.animationTick(gameTime); successSound.playSoundIfOk(); playerSprite.active = true; background.Update(gameTime); } if (ks.IsKeyDown(Keys.Right)) { // NOTE: the move right functionality does not work currently background.Update(gameTime); } if (ks.IsKeyDown(Keys.B)) { showBB = !showBB; } /// increases the player's jump speed - this is a secret function if (ks.IsKeyDown(Keys.Z)) { playerJumpSpeed++; } // decreases the player's jump speed - this is another secret function if (ks.IsKeyDown(Keys.X)) { playerJumpSpeed--; } // this gives the small kitty cat the ability to jump around the screen if (playerJump) { playerVec.Y += playerJumpSpeed; playerJumpSpeed += 1; playerSprite.setPosY(playerVec.Y); if (playerVec.Y >= prevPos.Y) { playerSprite.setPosY(prevPos.Y); playerJump = false; } } else { if (ks.IsKeyDown(Keys.Up)) { playerJump = true; playerJumpSpeed = -14; jumpoSound.playSoundIfOk(); playerSprite.setPosY(playerVec.Y); } } // transition to end of game if user reaches 5 pts if (points == 5) { state = 6; } if (lives == 0) { state = 7; } }
/// <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); }