public override void LoadLevel() { base.LoadLevel(); Sprite3 newPlatform; //DASH LEVEL OutOfBounds = new Rectangle(-100, 0, 7000, 1000); ////debug //newPlatform = new Sprite3(true, texPixel, 0, 700); //newPlatform.setWidthHeight(7000, 30); //platformList.addSpriteReuse(newPlatform); //start platform newPlatform = new Sprite3(true, texPixel, 200, 600); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); PlayerSpawnPosition = new Vector2(newPlatform.getBoundingBoxAA().X + newPlatform.getBoundingBoxAA().Width / 2 - player.getWidth() / 2, newPlatform.getBoundingBoxAA().Y - 100); newPlatform = new Sprite3(true, texPixel, 3000, 600); newPlatform.setWidthHeight(300, 30); platformList.addSpriteReuse(newPlatform); //make goal on last platform goal = new GoalZone(newPlatform); if (!isChallengeMode) { targetSpawnPositions.Add(new Vector2(512, 429)); targetSpawnPositions.Add(new Vector2(833, 422)); targetSpawnPositions.Add(new Vector2(1119, 424)); //targetSpawnPositions.Add(new Vector2(1430, 422)); targetSpawnPositions.Add(new Vector2(1745, 422)); //targetSpawnPositions.Add(new Vector2(2065, 422)); targetSpawnPositions.Add(new Vector2(2378, 422)); //targetSpawnPositions.Add(new Vector2(2725, 422)); } else { //ceiling newPlatform = new Sprite3(true, texPixel, 0, 400); newPlatform.setWidthHeight(7000, 30); platformList.addSpriteReuse(newPlatform); targetSpawnPositions.Add(new Vector2(512, 429)); targetSpawnPositions.Add(new Vector2(833, 422)); targetSpawnPositions.Add(new Vector2(1119, 424)); targetSpawnPositions.Add(new Vector2(1430, 422)); targetSpawnPositions.Add(new Vector2(1745, 422)); targetSpawnPositions.Add(new Vector2(2065, 422)); targetSpawnPositions.Add(new Vector2(2378, 422)); targetSpawnPositions.Add(new Vector2(2725, 422)); targetSpawnPositions.Add(new Vector2(2992, 422)); } }
public override void LoadLevel() { base.LoadLevel(); Sprite3 newPlatform; //PIT LEVEL. OutOfBounds = new Rectangle(-100, 0, Game1.SCREEN_WIDTH + 100, 1000); newPlatform = new Sprite3(true, texPixel, 200, 600); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); PlayerSpawnPosition = new Vector2(newPlatform.getBoundingBoxAA().X + newPlatform.getBoundingBoxAA().Width / 2 - player.getWidth() / 2, newPlatform.getBoundingBoxAA().Y - 100); targetSpawnPositions.Add(new Vector2(135, 79)); targetSpawnPositions.Add(new Vector2(411, 53)); targetSpawnPositions.Add(new Vector2(295, 295)); targetSpawnPositions.Add(new Vector2(270, 145)); targetSpawnPositions.Add(new Vector2(515, 376)); targetSpawnPositions.Add(new Vector2(484, 213)); targetSpawnPositions.Add(new Vector2(123, 461)); targetSpawnPositions.Add(new Vector2(164, 246)); targetSpawnPositions.Add(new Vector2(400, 502)); targetSpawnPositions.Add(new Vector2(399, 368)); targetSpawnPositions.Add(new Vector2(701, 511)); targetSpawnPositions.Add(new Vector2(562, 461)); targetSpawnPositions.Add(new Vector2(642, 261)); targetSpawnPositions.Add(new Vector2(907, 494)); targetSpawnPositions.Add(new Vector2(730, 381)); targetSpawnPositions.Add(new Vector2(628, 93)); targetSpawnPositions.Add(new Vector2(839, 52)); targetSpawnPositions.Add(new Vector2(945, 378)); targetSpawnPositions.Add(new Vector2(819, 201)); targetSpawnPositions.Add(new Vector2(847, 410)); targetSpawnPositions.Add(new Vector2(976, 200)); targetSpawnPositions.Add(new Vector2(1082, 499)); targetSpawnPositions.Add(new Vector2(1077, 293)); newPlatform = new Sprite3(true, texPixel, 1100, 150); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); //make goal on platform // goal = new GoalZone(new Vector2(700, PlayerSpawnPosition.Y), 100, 100); goal = new GoalZone(newPlatform); player.LoadPlatformsPlayer(platformList); }
void checkIfIAmShot() { Rectangle r = shooter.getBoundingBoxAA(); int temp = targets.collisionWithRect(r); if (temp == -1) { return; } Sprite3 s = targets.getSprite(temp); makeExplosion(shooter.getPos()); makeExplosion(s.getPos()); adjustScore(scoreIfPlayerHit, s.getPosX(), s.getPosY()); s.active = false; s.visible = false; //shooter.visible = false; lives = lives - 1; mgState = 2; timeIn2 = 0; if (lives <= 0) { mgState = 4; } }
public override void LoadLevel() { Game1.TimeScore = 0; base.LoadLevel(); Sprite3 newPlatform; OutOfBounds = new Rectangle(0, 0, Game1.SCREEN_WIDTH, 1000); newPlatform = new Sprite3(true, texPixel, 200, 500); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); PlayerSpawnPosition = new Vector2(newPlatform.getBoundingBoxAA().X + newPlatform.getBoundingBoxAA().Width / 2 - player.getWidth() / 2, newPlatform.getBoundingBoxAA().Y - 100); newPlatform = new Sprite3(true, texPixel, 900, 500); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); if (!isChallengeMode) { targetSpawnPositions.Add(new Vector2(380, 362)); targetSpawnPositions.Add(new Vector2(552, 359)); targetSpawnPositions.Add(new Vector2(717, 354)); } else { targetSpawnPositions.Add(new Vector2(74, 396)); targetSpawnPositions.Add(new Vector2(69, 537)); targetSpawnPositions.Add(new Vector2(70, 682)); targetSpawnPositions.Add(new Vector2(272, 675)); targetSpawnPositions.Add(new Vector2(471, 664)); targetSpawnPositions.Add(new Vector2(668, 656)); targetSpawnPositions.Add(new Vector2(850, 654)); targetSpawnPositions.Add(new Vector2(1018, 647)); targetSpawnPositions.Add(new Vector2(1158, 650)); targetSpawnPositions.Add(new Vector2(1144, 545)); targetSpawnPositions.Add(new Vector2(1144, 420)); } goal = new GoalZone(newPlatform); }
public override void LoadLevel() { base.LoadLevel(); Sprite3 newPlatform; OutOfBounds = new Rectangle(0, 0, Game1.SCREEN_WIDTH, 1000); platformList = new SpriteList(); newPlatform = new Sprite3(true, texPixel, 200, 700); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); targetSpawnPositions = new List <Vector2>(); PlayerSpawnPosition = new Vector2(newPlatform.getBoundingBoxAA().X + newPlatform.getBoundingBoxAA().Width / 2 - player.getWidth() / 2, newPlatform.getBoundingBoxAA().Y - 100); newPlatform = new Sprite3(true, texPixel, 700, 150); newPlatform.setWidthHeight(100, 30); platformList.addSpriteReuse(newPlatform); if (!isChallengeMode) { targetSpawnPositions.Add(new Vector2(280, 586)); targetSpawnPositions.Add(new Vector2(325, 487)); targetSpawnPositions.Add(new Vector2(367, 394)); targetSpawnPositions.Add(new Vector2(414, 294)); targetSpawnPositions.Add(new Vector2(469, 188)); targetSpawnPositions.Add(new Vector2(526, 82)); } else { targetSpawnPositions.Add(new Vector2(68, 608)); targetSpawnPositions.Add(new Vector2(68, 497)); targetSpawnPositions.Add(new Vector2(67, 399)); targetSpawnPositions.Add(new Vector2(72, 293)); targetSpawnPositions.Add(new Vector2(79, 185)); targetSpawnPositions.Add(new Vector2(78, 90)); } goal = new GoalZone(newPlatform); player.LoadPlatformsPlayer(platformList); }
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); }
/// <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> /// This is a mess, please forgive me protected override void Update(GameTime gameTime) { //Console.WriteLine(enemies.count()); curPos = horse.getPos(); bool keyDown = false; switch (level) { case 1: horse.setWidthHeight(1568 / 8 * 0.3f, texHorseRun.Height * 0.3f); k = Keyboard.GetState(); if (!started) { started = true; StartMovement(8); } if (k.IsKeyDown(Keys.Down)) { keyDown = true; horse.setPosY(horse.getPosY() + movementSpeed - 2); } if (k.IsKeyDown(Keys.Up)) { keyDown = true; horse.setPosY(horse.getPosY() - movementSpeed + 2); } if (k.IsKeyDown(Keys.Left)) { keyDown = true; horse.setFlip(SpriteEffects.FlipHorizontally); horse.setPosX(horse.getPosX() - movementSpeed + 2); } if (k.IsKeyDown(Keys.Right)) { keyDown = true; horse.setFlip(SpriteEffects.None); horse.setPosX(horse.getPosX() + movementSpeed - 2); } if (!keyDown) { horse.setAnimationSequence(anim, 0, 7, 0); } else { horse.setAnimationSequence(anim, 0, 7, 8); } //387 330 if (curPos.X >= -155 && curPos.X <= -75 && curPos.Y >= 330 && curPos.Y <= 387) { horse.setPos(xx, yy); started = false; horse.setFlip(SpriteEffects.None); level = 0; } horseRun.animationTick(gameTime); mainCamera.Follow(horse); break; default: if (!started) { if (k.IsKeyDown(Keys.D1) || k.IsKeyDown(Keys.NumPad1)) { difficulty = 1; } else if (k.IsKeyDown(Keys.D2) || k.IsKeyDown(Keys.NumPad2)) { difficulty = 2; } else if (k.IsKeyDown(Keys.D3) || k.IsKeyDown(Keys.NumPad3)) { difficulty = 3; } } switch (difficulty) { case 1: difficultyOffset = 1; break; case 2: difficultyOffset = 0.5f; break; case 3: difficultyOffset = 0.1f; break; default: break; } horse.setWidthHeight(1568 / 8 * 0.5f, texHorseRun.Height * 0.5f); //This timer makes basic instructions disappear after 3 seconds if (textFadeTimer < 3 && started) { textFadeTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (started) { enemySpawnTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (enemySpawnTimer > difficultyOffset) { enemySpawnTimer = 0; LoadEnemies(); } //Escape key exits game if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } //Keyboard current and previous state prevK = k; k = Keyboard.GetState(); //Begin all game functionality essentially if (k.IsKeyDown(Keys.Enter) && !started) { started = true; StartMovement(8); } if (started) { //Bounding box activation key if (k.IsKeyDown(Keys.B) && prevK.IsKeyUp(Keys.B)) { showbb = !showbb; } //Game over is a bool that is used to ensure the player can't move horse after it is dead, causes errors otherwise if (!gameOver) { //Player movement down if (k.IsKeyDown(Keys.Down)) { if (horseRun.getSprite(0).getPosY() < bot - horse.getHeight()) { horseRun.getSprite(0).setPosY(horseRun.getSprite(0).getPosY() + movementSpeed); } } //Player movement up if (k.IsKeyDown(Keys.Up)) { if (horseRun.getSprite(0).getPosY() > top) { horseRun.getSprite(0).setPosY(horseRun.getSprite(0).getPosY() - movementSpeed); } } } for (int e = 0; e < enemies.count(); e++) { if (enemies[e].getVisible()) { enemies[e].setPosX(enemies[e].getPosX() - enemyMovementSpeed); } if (enemies[e].getPosX() < 0 - texEnemy.Width) { enemies[e].setVisible(false); } } //Collision detection, arrow to enemy for (int ea = 0; ea < quiver.count(); ea++) { int ac = enemies.collisionWithRect(quiver[ea].getBoundingBoxAA()); if (ac != -1) { score++; Blood(enemies.getSprite(ac).getPosX(), enemies.getSprite(ac).getPosY(), false); enemies.getSprite(ac).setVisible(false); quiver[ea].setVisible(false); quiver[ea].setPos(new Vector2(0, 0)); //LoadEnemies(); } } //Allow player to increase or decrease speed if (Keyboard.GetState().IsKeyDown(Keys.Right)) { enemyMovementSpeed = fastEnemy; horse.setAnimationSequence(anim, 0, 7, fastPlayer); } else if (Keyboard.GetState().IsKeyDown(Keys.Left)) { enemyMovementSpeed = slowEnemy; horse.setAnimationSequence(anim, 0, 7, slowPlayer); } else if (started) { enemyMovementSpeed = normalEnemy; horse.setAnimationSequence(anim, 0, 7, normalPlayer); } //Scrolling background functionality 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(); //Game over is a bool that is used to ensure the player can't move horse after it is dead, causes errors otherwise if (!gameOver) { //Collision detection, enemy to player int rc = enemies.collisionWithRect(horse.getBoundingBoxAA()); if (rc != -1) { Blood(horse.getPosX(), horse.getPosY(), true); movementSpeed = 0; enemyMovementSpeed = 0; scrolling1.speed = 0; scrolling2.speed = 0; for (int i = 0; i < horseRun.count(); i++) { horseRun.deleteSprite(i); } gameOver = true; } } //Shooting arrow functionality if (Keyboard.GetState().IsKeyDown(Keys.Space) && !arrowShot) { Arrow(); arrowShot = true; } for (int a = 0; a < quiver.count(); a++) { if (quiver[a].getVisible()) { quiver[a].savePosition(); quiver[a].moveByDeltaXY(); } if (quiver[a].getPosX() > 800) { quiver[a].setVisible(false); } } if (arrowShot) { arrowTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (arrowTimer > 0.5f) { arrowTimer = 0; arrowShot = false; } } //Animation ticks for anything that is being animated horseRun.animationTick(gameTime); enemies.animationTick(gameTime); bloodSplat.animationTick(gameTime); if (gameOver) { deathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; } break; } 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(); } 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); }
public override void Update(GameTime gameTime) { base.Update(gameTime); float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; //MOVEMENT //ALL CHECKS AND CHANGES BEFORE THE POSITION SET. //PLAYER SLICE COOLDOWN if (canSlice == false) { sliceTimer += deltaTime; } if (sliceTimer > sliceCooldown) { sliceTimer = 0; canSlice = true; iconSlice.isReady = true; } //DASH MECHANIC...no gravity for a duration //if (justDashed) //{ // acceleration.Y = 0; // noGravityTimer += deltaTime; // if(noGravityTimer > noGravityLimit) // { // noGravityTimer = 0; // justDashed = false; // } //} velocity += acceleration * deltaTime; if (velocity.X > velocityHorizontalMovespeedCap) { velocity.X -= accelerationDecay.X * deltaTime; if (velocity.X < velocityHorizontalMovespeedCap) { velocity.X = velocityHorizontalMovespeedCap; } acceleration.X = 0; } else if (velocity.X < -velocityHorizontalMovespeedCap) { velocity.X += accelerationDecay.X * deltaTime; if (velocity.X > -velocityHorizontalMovespeedCap) { velocity.X = -velocityHorizontalMovespeedCap; } acceleration.X = 0; } //FINALLY SET POSITION //set x pos. setPosX(getPosX() + velocity.X * deltaTime); //check horizontal collisions //COLLISION TEST WITH PLATFORMS for (int i = 0; i < platformList.count(); i++) { Sprite3 currentPlatform = platformList.getSprite(i); if (this.collision(currentPlatform)) { if (velocity.X > 0) { velocity.X = 0; this.setPosX(currentPlatform.getPosX() - this.getWidth()); } else if (velocity.X < 0) { velocity.X = 0; this.setPosX(currentPlatform.getPosX() + currentPlatform.getWidth()); } } } setPosY(getPosY() + velocity.Y * deltaTime); //COLLISION TEST WITH PLATFORMS for (int i = 0; i < platformList.count(); i++) { Sprite3 currentPlatform = platformList.getSprite(i); if (this.collision(currentPlatform)) { if (velocity.Y >= 0 && this.getPosY() <= currentPlatform.getPosY()) { this.setPos(getPosX(), currentPlatform.getPosY() - this.getHeight()); velocity.Y = 0; IsOnGround = true; } else if (velocity.Y < 0 && this.getPosY() >= currentPlatform.getPosY()) { this.setPos(getPosX(), currentPlatform.getPosY() + currentPlatform.getHeight()); velocity.Y = 0; } } } //If no input movement, slow down player if (canPlayerMove) { if (InputManager.Instance.KeyUp(Keys.Left) && InputManager.Instance.KeyUp(Keys.Right) && GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X == 0) { acceleration.X = 0; if (velocity.X != 0) { if (velocity.X > 0) { velocity.X -= deltaTime * velocityDecay.X; if (velocity.X < 0) { velocity.X = 0; } } else if (velocity.X < 0) { velocity.X += deltaTime * velocityDecay.X; if (velocity.X > 0) { velocity.X = 0; } } } } else { //If travelling right and player moves left, increase the acceleration to opposite if (InputManager.Instance.KeyDown(Keys.Left)) { if (acceleration.X > -HorizontalMoveSpeed) { acceleration.X = -HorizontalMoveSpeed; } //If player velocity is more than the cap, slowly decay to the cap. if (velocity.X > 0) { velocity.X -= deltaTime * velocityDecay.X; if (velocity.X < 0) { velocity.X = 0; } } } if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X != 0) { acceleration.X = HorizontalMoveSpeed * GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X; if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0) { if (velocity.X < 0) { velocity.X += deltaTime * velocityDecay.X; if (velocity.X > 0) { velocity.X = 0; } } } else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0) { if (velocity.X > 0) { velocity.X -= deltaTime * velocityDecay.X; if (velocity.X < 0) { velocity.X = 0; } } } } if (InputManager.Instance.KeyDown(Keys.Right)) { if (acceleration.X < HorizontalMoveSpeed) { acceleration.X = HorizontalMoveSpeed; } if (velocity.X < 0) { velocity.X += deltaTime * velocityDecay.X; if (velocity.X > 0) { velocity.X = 0; } } } //If both left and right pressed down, 0 acceleration if (InputManager.Instance.KeyDown(Keys.Right) && InputManager.Instance.KeyDown(Keys.Left)) { acceleration.X = 0; } } } //Is the player currently on a platform? bool isOnPlatform = false; for (int i = 0; i < platformList.count(); i++) { Sprite3 currentPlatform = platformList.getSprite(i); if (currentPlatform.getActive()) { if (currentPlatform.getBoundingBoxAA().Intersects(rectPlatformCheck)) { isOnPlatform = true; } } } if (isOnPlatform == false) { IsOnGround = false; } //PLAYER JUMP. if (canPlayerMove) { if (InputManager.Instance.KeyPressed(Keys.Z) || InputManager.Instance.ButtonPressed(Buttons.A)) { if (IsOnGround) { velocity.Y = -jumpVelocity; IsOnGround = false; soundJump.Play(); } else { if (canDoubleJump == true) { velocity.Y = -doubleJumpVelocity; canDoubleJump = false; iconDoubleJump.isReady = false; soundDoubleJump.Play(); } } } } //If player holds the jump button, gets maximum jump, otherwise fall faster. if (canPlayerMove) { if (InputManager.Instance.KeyDown(Keys.Z) || InputManager.Instance.ButtonDown(Buttons.A) && IsOnGround == false) { acceleration.Y = accelerationPlayerFall.Y; } else { acceleration.Y = accelerationDefault.Y; } } //PLAYER DASH if (canPlayerMove) { if (InputManager.Instance.KeyPressed(Keys.C) || InputManager.Instance.ButtonPressed(Buttons.B)) { if (canDash) { if (InputManager.Instance.KeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0) { velocity.X = horizontalDashVelocity; velocity.Y = -20; canDash = false; iconDash.isReady = false; noGravityTimer = 0; justDashed = true; soundDash.Play(); } else if (InputManager.Instance.KeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0) { velocity.X = -horizontalDashVelocity; velocity.Y = -20; canDash = false; iconDash.isReady = false; noGravityTimer = 0; justDashed = true; soundDash.Play(); } } } } if (IsOnGround == false) { if (velocity.Y > 0) { //check for platforms isCheckGroundPlatforms = true; } } else { isCheckGroundPlatforms = false; } rectPlatformCheck = new Rectangle((int)this.getPosX(), (int)this.getPosY() + (int)this.getHeight(), (int)this.getWidth(), 5); }
public override void Update(GameTime gameTime) { base.Update(gameTime); float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; Game1.TimeScore += deltaTime; cam.Pos = new Vector2(cam.Pos.X, Game1.SCREEN_HEIGHT / 2); if (InputManager.Instance.KeyDown(Keys.W)) { cam.Pos = new Vector2(cam.Pos.X, cam.Pos.Y - 5); } if (InputManager.Instance.KeyDown(Keys.S)) { cam.Pos = new Vector2(cam.Pos.X, cam.Pos.Y + 5); } if (InputManager.Instance.KeyDown(Keys.A)) { cam.Pos = new Vector2(cam.Pos.X - 5, cam.Pos.Y); } if (InputManager.Instance.KeyDown(Keys.D)) { cam.Pos = new Vector2(cam.Pos.X + 5, cam.Pos.Y); } if (InputManager.Instance.KeyPressed(Keys.Back)) { gameStateManager.setLevel(gameStateManager.getCurrentLevelNum() - 1); } //CAMERA STICK ON PLAYER. if (cam.Pos.X < player.getPosX() - 100) { cam.Pos = new Vector2(player.getPosX() - 100, cam.Pos.Y); } else if (cam.Pos.X > player.getPosX() + player.getWidth() + 100) { cam.Pos = new Vector2(player.getPosX() + player.getWidth() + 100, cam.Pos.Y); } ////Move camera to infront of player. //if (player.velocity.X > 0) //{ // CamPlayerPositiveVelocity = true; //} //else if (player.velocity.X < 0) //{ // CamPlayerPositiveVelocity = false; //} //if (CamPlayerPositiveVelocity) //{ // cam.Pos = new Vector2(cam.Pos.X + 10, cam.Pos.Y); //} //else //{ // cam.Pos = new Vector2(cam.Pos.X - 10, cam.Pos.Y); //} if (cam.Pos.X < CamOriginalPosition.X) { cam.Pos = new Vector2(CamOriginalPosition.X, cam.Pos.Y); } else if (cam.Pos.X + Game1.SCREEN_WIDTH / 2 > OutOfBounds.X + OutOfBounds.Width) { cam.Pos = new Vector2(OutOfBounds.X + OutOfBounds.Width - CamOriginalPosition.X, cam.Pos.Y); } //cam.Pos = new Vector2(Game1.SCREEN_WIDTH/2, Game1.SCREEN_HEIGHT/2); if (InputManager.Instance.KeyPressed(Keys.B)) { showbb = !showbb; } if (InputManager.Instance.MousePressed(MouseButton.Left)) { Slice newSlice = new Slice((float)InputManager.Instance.GetMousePositionX() - Slice.sliceWidth / 2 + cam.Pos.X - Game1.SCREEN_WIDTH / 2, (float)InputManager.Instance.GetMousePositionY()); sliceList.addSpriteReuse(newSlice); for (int i = 0; i < enemyList.count(); i++) { Sprite3 currentEnemy = enemyList.getSprite(i); } } //PLAYER SLICE if (InputManager.Instance.KeyPressed(Keys.X) || InputManager.Instance.ButtonPressed(Buttons.RightShoulder)) { if (player.canSlice == true) { Slice newSlice = new Slice(player.getBoundingBoxMiddle().X - Slice.sliceWidth / 2, player.getBoundingBoxMiddle().Y); sliceList.addSpriteReuse(newSlice); player.Slice(); soundSlice.Play(); } } if (InputManager.Instance.MousePressed(MouseButton.Right)) { TestEnemy newEnemy = new TestEnemy(InputManager.Instance.GetMousePosition() + cam.Pos - new Vector2(Game1.SCREEN_WIDTH / 2 + 70 / 2, Game1.SCREEN_HEIGHT / 2 + 70 / 2)); enemyList.addSpriteReuse(newEnemy); Console.WriteLine("targetSpawnPositions.Add(new Vector2(" + newEnemy.getPos().X + "," + newEnemy.getPos().Y + "));"); } player.Update(gameTime); sliceList.Update(gameTime); particleList.Update(gameTime); enemyList.Update(gameTime); platformList.Update(gameTime); goal.Update(gameTime); //GOAL CONDITION if (player.getBoundingBoxAA().Intersects(goal.rectGoalZone)) { if (player.IsOnGround) { //WIN player.SetCanPlayerMove(false); player.velocity = Vector2.Zero; player.acceleration = new Vector2(0, 1000f); NextLevel(); } } //update abilities abilityIconDoubleJump.Update(gameTime); abilityIconDash.Update(gameTime); abilityIconSlice.Update(gameTime); //IF PLAYER IS OUT OF BOUNDS if (player.getPosX() < OutOfBounds.X || player.getPosX() > OutOfBounds.X + OutOfBounds.Width || player.getPosY() + player.getHeight() * 2 < OutOfBounds.Y || player.getPosY() > OutOfBounds.Y + OutOfBounds.Height) { soundDeath.Play(); player.SetCanPlayerMove(false); player.AbilityReset(); ResetPlayer(); } //DETECT COLLISION BETWEEN SLICES AND TARGETS for (int i = 0; i < enemyList.count(); i++) { //Get current enemy to test. //If not active, skip. Sprite3 currentSprite = enemyList.getSprite(i); if (currentSprite == null) { continue; } if (currentSprite.active != true) { continue; } if (currentSprite.visible != true) { continue; } if (currentSprite is Enemy == false) { continue; } TestEnemy currentEnemy = currentSprite as TestEnemy; //Get current slice to test. //If not active, skip. for (int j = 0; j < sliceList.count(); j++) { currentSprite = sliceList.getSprite(j); if (currentSprite == null) { continue; } if (currentSprite.active != true) { continue; } if (currentSprite.visible != true) { continue; } if (currentSprite is Slice) { Slice currentSlice = currentSprite as Slice; //loop thru all the current enemy's hitboxes until a slice collides with it. for (int k = 0; k < currentEnemy.listHitbox.count(); k++) { Sprite3 currentHitBox = currentEnemy.listHitbox.getSprite(k); if (currentHitBox == null) { continue; } if (currentHitBox.active != true) { continue; } if (currentEnemy.active == false) { continue; } //Check if the slice has hit anything else yet. if (currentSlice.canHit == true) { //SLICE HIT THE ENEMYHITBOX. if (currentSlice.collision(currentHitBox)) { float sliceWidth = currentSlice.getBB().Width; float sliceLeft = currentSlice.getBoundingBoxMiddle().X - sliceWidth / 2; float sliceRight = currentSlice.getBoundingBoxMiddle().X + sliceWidth / 2; float hitboxWidth = currentHitBox.getBB().Width; float hitboxLeft = currentHitBox.getBoundingBoxMiddle().X - hitboxWidth / 2; float hitboxRight = currentHitBox.getBoundingBoxMiddle().X + hitboxWidth / 2; if (sliceLeft <= hitboxLeft && sliceRight >= hitboxRight) { //Console.WriteLine("FULL CUT"); soundSliceHit.Play(); SliceParticle topSlice; float scaleWidth = currentHitBox.getWidth() / currentEnemy.getTextureBase().Width; float scaleHeight = currentHitBox.getHeight() / currentEnemy.getTextureBase().Height; Vector2 ScaleVec = new Vector2(scaleWidth, scaleHeight); Rectangle topDest = new Rectangle(currentHitBox.getBoundingBoxAA().X, currentHitBox.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, (int)currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y); float topScaleX; float topScaleY; Rectangle topSourceRect = new Rectangle(0, 0, (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight)); //Rectangle topSourceRect = currentHitBox.texBase.Bounds; //Console.WriteLine("TOPSLICE: " + topDest.ToString()); topSlice = new SliceParticle(topDest, currentEnemy.getTextureBase(), topSourceRect, ScaleVec, 0.8f, new Vector2(player.velocity.X / 2, -50 - Math.Abs(player.velocity.X))); particleList.addReuse(topSlice); SliceParticle bottomSlice; Rectangle bottomDest = new Rectangle(currentHitBox.getBoundingBoxAA().X, (int)currentSlice.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, currentHitBox.getBoundingBoxAA().Y + currentHitBox.getBoundingBoxAA().Height - currentSlice.getBoundingBoxAA().Y); Rectangle bottomSourceRect = new Rectangle(0, (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight), (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)(currentEnemy.texBase.Height - ((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight))); bottomSlice = new SliceParticle(bottomDest, currentEnemy.getTextureBase(), bottomSourceRect, ScaleVec, -0.8f, new Vector2(player.velocity.X / 2, 0 - Math.Abs(player.velocity.X) / 2)); particleList.addReuse(bottomSlice); //Console.WriteLine("BOTTOMSLICE: " + bottomDest.ToString()); if (!currentEnemy.canRespawn) { currentEnemy.setActive(false); } else { currentEnemy.isDead = true; } currentEnemy.setVisible(false); player.AbilityReset(); break; } } } } } else { continue; } } } }
public override void Update(GameTime gameTime) { base.Update(gameTime); selector.Update(gameTime); //MOVE OPTION if (InputManager.Instance.KeyPressed(Keys.Up) || InputManager.Instance.ButtonPressed(Buttons.DPadUp)) { menuSelector -= 1; if (menuSelector < 0) { menuSelector = menuStrings.Count - 1; } soundMenu.Play(); } if (InputManager.Instance.KeyPressed(Keys.Down) || InputManager.Instance.ButtonPressed(Buttons.DPadDown)) { menuSelector += 1; if (menuSelector > menuStrings.Count - 1) { menuSelector = 0; } soundMenu.Play(); } //SELECT OPTION if (notSelected) { if (InputManager.Instance.KeyPressed(Keys.Z) || InputManager.Instance.ButtonPressed(Buttons.A)) { notSelected = false; switch (menuStrings[menuSelector]) { case "START GAME": BaseLevel.isChallengeMode = false; Task.Delay(1000).ContinueWith(t => gameStateManager.setLevel(1)); break; case "TUTORIAL": BaseLevel.isChallengeMode = false; Task.Delay(1000).ContinueWith(t => gameStateManager.setLevel(0)); break; case "EXIT GAME": Task.Delay(1000).ContinueWith(t => Game1.game1.Exit()); break; case "CHALLENGE MODE": BaseLevel.isChallengeMode = true; Task.Delay(1000).ContinueWith(t => gameStateManager.setLevel(1)); break; default: Game1.game1.Exit(); break; } sliceList.addSpriteReuse(new Slice(selector.getPosX(), selector.getPosY() + selector.getHeight() / 2)); } } // particleList.Update(gameTime); sliceList.Update(gameTime); //DETECT COLLISION BETWEEN SLICES AND TARGETS for (int i = 0; i < enemyList.count(); i++) { //Get current enemy to test. //If not active, skip. Sprite3 currentSprite = enemyList.getSprite(i); if (currentSprite == null) { continue; } if (currentSprite.active != true) { continue; } if (currentSprite.visible != true) { continue; } if (currentSprite is Enemy == false) { continue; } Enemy currentEnemy = currentSprite as Enemy; //Get current slice to test. //If not active, skip. for (int j = 0; j < sliceList.count(); j++) { currentSprite = sliceList.getSprite(j); if (currentSprite == null) { continue; } if (currentSprite.active != true) { continue; } if (currentSprite.visible != true) { continue; } if (currentSprite is Slice) { Slice currentSlice = currentSprite as Slice; //loop thru all the current enemy's hitboxes until a slice collides with it. for (int k = 0; k < currentEnemy.listHitbox.count(); k++) { Sprite3 currentHitBox = currentEnemy.listHitbox.getSprite(k); if (currentHitBox == null) { continue; } if (currentHitBox.active != true) { continue; } if (currentEnemy.active == false) { continue; } //Check if the slice has hit anything else yet. if (currentSlice.canHit == true) { //SLICE HIT THE ENEMYHITBOX. if (currentSlice.collision(currentHitBox)) { float sliceWidth = currentSlice.getBB().Width; float sliceLeft = currentSlice.getBoundingBoxMiddle().X - sliceWidth / 2; float sliceRight = currentSlice.getBoundingBoxMiddle().X + sliceWidth / 2; float hitboxWidth = currentHitBox.getBB().Width; float hitboxLeft = currentHitBox.getBoundingBoxMiddle().X - hitboxWidth / 2; float hitboxRight = currentHitBox.getBoundingBoxMiddle().X + hitboxWidth / 2; if (sliceLeft <= hitboxLeft && sliceRight >= hitboxRight) { //Console.WriteLine("FULL CUT"); BaseLevel.soundSliceHit.Play(); SliceParticle topSlice; float scaleWidth = currentHitBox.getWidth() / currentEnemy.getTextureBase().Width; float scaleHeight = currentHitBox.getHeight() / currentEnemy.getTextureBase().Height; Vector2 ScaleVec = new Vector2(scaleWidth, scaleHeight); Rectangle topDest = new Rectangle(currentHitBox.getBoundingBoxAA().X, currentHitBox.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, (int)currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y); float topScaleX; float topScaleY; Rectangle topSourceRect = new Rectangle(0, 0, (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight)); //Rectangle topSourceRect = currentHitBox.texBase.Bounds; //Console.WriteLine("TOPSLICE: " + topDest.ToString()); topSlice = new SliceParticle(topDest, currentEnemy.getTextureBase(), topSourceRect, ScaleVec, 0.8f, new Vector2(200, -50 - Math.Abs(100))); particleList.addReuse(topSlice); SliceParticle bottomSlice; Rectangle bottomDest = new Rectangle(currentHitBox.getBoundingBoxAA().X, (int)currentSlice.getBoundingBoxAA().Y, currentHitBox.getBoundingBoxAA().Width, currentHitBox.getBoundingBoxAA().Y + currentHitBox.getBoundingBoxAA().Height - currentSlice.getBoundingBoxAA().Y); Rectangle bottomSourceRect = new Rectangle(0, (int)((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight), (int)(currentHitBox.getBoundingBoxAA().Width / scaleWidth), (int)(currentEnemy.texBase.Height - ((currentSlice.getBoundingBoxMiddle().Y - currentHitBox.getBoundingBoxAA().Y) / scaleHeight))); bottomSlice = new SliceParticle(bottomDest, currentEnemy.getTextureBase(), bottomSourceRect, ScaleVec, -0.8f, new Vector2(-100, 0 - Math.Abs(-5))); particleList.addReuse(bottomSlice); //Console.WriteLine("BOTTOMSLICE: " + bottomDest.ToString()); currentEnemy.setActive(false); currentEnemy.setVisible(false); break; } } } } } else { continue; } } } }