protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); fontLoader = new FontLoader(Content); playing = new PlayingStateClass(graphics, GraphicsDevice, Content); titleScreen = new TitleScreenClass(Content, GraphicsDevice, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); loading = new LoadingScreenClass(Content, null, false); Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2); menu = new MainMenuStateClass(Content, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), true); ChangeGameState(CurrentGameState); buttonSound = Content.Load <SoundEffect>("Sounds/button"); buttonClickSound = Content.Load <SoundEffect>("Sounds/buttonClick"); backSound = Content.Load <SoundEffect>("Sounds/back"); }
public void UpdatePosition(Vector3 moveVector, List <BoundingBox> boundingBoxes, GameTime gameTime, PlayingStateClass parent) { #region animation if (!Game1.SkipAnimation && !startAnimation[animationCount].hasFinished) { startAnimation[animationCount].Update(gameTime.ElapsedGameTime); yaw = startAnimation[animationCount].GetV2(0).X; pitch = startAnimation[animationCount].GetV2(0).Y; position = startAnimation[animationCount].GetV3(0); moveVector = Vector3.Zero; } else if (animationCount == startAnimation.Count - 1) { isAnimating = false; } else { animationCount++; } if (!isAnimating && TimeAfterAnimationOver.TotalMilliseconds != -100) { TimeAfterAnimationOver += gameTime.ElapsedGameTime; } if (TimeAfterAnimationOver.TotalMilliseconds >= 10) { position = new Vector3(-0.5f, 0, -0.2f); yaw = 0; pitch = -0.28f; TimeAfterAnimationOver = TimeSpan.FromMilliseconds(-100); } #endregion if (!isAnimating) { #region Bounderies moveVector.Y += jumpspeed / 40.0f; jumpspeed -= 0.3f; if (jumpspeed <= -4) { jumpspeed = -4; } if (!moveVector.Equals(Vector3.Zero)) { Matrix cameraRotation = Matrix.CreateRotationY(yaw); Vector3 rotatedVector = Vector3.Transform(moveVector, cameraRotation); if (isCrouched) { cameraSpeed /= 1.8f; characterCrounched_Y_Offset = characterOffset.Y * crouchCount / 20; } //if (!isCrouched && Math.Abs(characterCrounched_Y_Offset / characterOffset.Y) >= 0.1f) // if (!Check_CanGetUp(boundingBoxes)) // isCrouched = true; if (!isCrouched) { characterCrounched_Y_Offset = characterOffset.Y; } bool canX = true; bool canY = true; bool canZ = true; BoundingBox characterBoxX; BoundingBox characterBoxZ; BoundingBox characterBoxY; Vector3 newOriginPoint = position + new Vector3((cameraSpeed * rotatedVector.X), 0, 0); if (isCrouched) { characterBoxX = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterOffset.Y, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); } else { characterBoxX = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); } newOriginPoint = position + new Vector3(0, 0, (cameraSpeed * rotatedVector.Z)); if (isCrouched) { characterBoxZ = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterOffset.Y, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); } else { characterBoxZ = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); } newOriginPoint = position + new Vector3(0, rotatedVector.Y, 0); if (isCrouched) { characterBoxY = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterOffset.Y, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); } else { characterBoxY = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); } if (boundingBoxes[0].Contains(characterBoxX) != ContainmentType.Contains) { canX = false; } if (boundingBoxes[0].Contains(characterBoxZ) != ContainmentType.Contains) { canZ = false; } if (boundingBoxes[0].Contains(characterBoxY) != ContainmentType.Contains) { canY = false; } for (int i = 1; i < boundingBoxes.Count; i++) { if (boundingBoxes[i].Contains(characterBoxX) != ContainmentType.Disjoint) { canX = false; } if (boundingBoxes[i].Contains(characterBoxZ) != ContainmentType.Disjoint) { canZ = false; } if (boundingBoxes[i].Contains(characterBoxY) != ContainmentType.Disjoint) { canY = false; } } if (canX) { position.X += cameraSpeed * rotatedVector.X; } if (canZ) { position.Z += cameraSpeed * rotatedVector.Z; } if (canY) { position.Y += rotatedVector.Y; } else { if (rotatedVector.Y < 0 && isJumping) { if (jumpspeed >= 0) { jumpspeed = -0.01f; position.Y -= 0.01f; } else { isJumping = false; } } } if (isCrouched) { cameraSpeed *= 1.8f; } } #endregion } }
public void UpdatePosition(Vector3 moveVector, List<BoundingBox> boundingBoxes, GameTime gameTime, PlayingStateClass parent) { #region animation if (!Game1.SkipAnimation && !startAnimation[animationCount].hasFinished) { startAnimation[animationCount].Update(gameTime.ElapsedGameTime); yaw = startAnimation[animationCount].GetV2(0).X; pitch = startAnimation[animationCount].GetV2(0).Y; position = startAnimation[animationCount].GetV3(0); moveVector = Vector3.Zero; } else if (animationCount == startAnimation.Count - 1) isAnimating = false; else animationCount++; if (!isAnimating && TimeAfterAnimationOver.TotalMilliseconds != -100) TimeAfterAnimationOver += gameTime.ElapsedGameTime; if (TimeAfterAnimationOver.TotalMilliseconds >= 10) { position = new Vector3(-0.5f, 0, -0.2f); yaw = 0; pitch = -0.28f; TimeAfterAnimationOver = TimeSpan.FromMilliseconds(-100); } #endregion if (!isAnimating) { #region Bounderies moveVector.Y += jumpspeed / 40.0f; jumpspeed -= 0.3f; if (jumpspeed <= -4) jumpspeed = -4; if (!moveVector.Equals(Vector3.Zero)) { Matrix cameraRotation = Matrix.CreateRotationY(yaw); Vector3 rotatedVector = Vector3.Transform(moveVector, cameraRotation); if (isCrouched) { cameraSpeed /= 1.8f; characterCrounched_Y_Offset = characterOffset.Y * crouchCount / 20; } //if (!isCrouched && Math.Abs(characterCrounched_Y_Offset / characterOffset.Y) >= 0.1f) // if (!Check_CanGetUp(boundingBoxes)) // isCrouched = true; if (!isCrouched) characterCrounched_Y_Offset = characterOffset.Y; bool canX = true; bool canY = true; bool canZ = true; BoundingBox characterBoxX; BoundingBox characterBoxZ; BoundingBox characterBoxY; Vector3 newOriginPoint = position + new Vector3((cameraSpeed * rotatedVector.X), 0, 0); if (isCrouched) characterBoxX = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterOffset.Y, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); else characterBoxX = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); newOriginPoint = position + new Vector3(0, 0, (cameraSpeed * rotatedVector.Z)); if (isCrouched) characterBoxZ = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterOffset.Y, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); else characterBoxZ = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); newOriginPoint = position + new Vector3(0, rotatedVector.Y, 0); if (isCrouched) characterBoxY = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterOffset.Y, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); else characterBoxY = new BoundingBox(new Vector3(newOriginPoint.X - (characterOffset.X / 2), newOriginPoint.Y - characterCrounched_Y_Offset, newOriginPoint.Z - (characterOffset.Z / 2)), new Vector3(newOriginPoint.X + (characterOffset.X / 2), newOriginPoint.Y + 0.14f, newOriginPoint.Z + (characterOffset.Z / 2))); if (boundingBoxes[0].Contains(characterBoxX) != ContainmentType.Contains) canX = false; if (boundingBoxes[0].Contains(characterBoxZ) != ContainmentType.Contains) canZ = false; if (boundingBoxes[0].Contains(characterBoxY) != ContainmentType.Contains) canY = false; for (int i = 1; i < boundingBoxes.Count; i++) { if (boundingBoxes[i].Contains(characterBoxX) != ContainmentType.Disjoint) canX = false; if (boundingBoxes[i].Contains(characterBoxZ) != ContainmentType.Disjoint) canZ = false; if (boundingBoxes[i].Contains(characterBoxY) != ContainmentType.Disjoint) canY = false; } if (canX) position.X += cameraSpeed * rotatedVector.X; if (canZ) position.Z += cameraSpeed * rotatedVector.Z; if (canY) position.Y += rotatedVector.Y; else { if (rotatedVector.Y < 0 && isJumping) if (jumpspeed >= 0) { jumpspeed = -0.01f; position.Y -= 0.01f; } else isJumping = false; } if (isCrouched) cameraSpeed *= 1.8f; } #endregion } }
public void RestartGame() { playing = new PlayingStateClass(graphics, GraphicsDevice, new ContentManager(Content.ServiceProvider, Content.RootDirectory)); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); fontLoader = new FontLoader(Content); playing = new PlayingStateClass(graphics, GraphicsDevice, Content); titleScreen = new TitleScreenClass(Content, GraphicsDevice, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); loading = new LoadingScreenClass(Content, null, false); Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2); menu = new MainMenuStateClass(Content, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), true); ChangeGameState(CurrentGameState); buttonSound = Content.Load<SoundEffect>("Sounds/button"); buttonClickSound = Content.Load<SoundEffect>("Sounds/buttonClick"); backSound = Content.Load<SoundEffect>("Sounds/back"); }
public void RestartGame() { playing = new PlayingStateClass(graphics, GraphicsDevice, new ContentManager(Content.ServiceProvider, Content.RootDirectory)); }