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; } } } }