/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { BoundingRenderer.InitializeGraphics(graphics.GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice); player.LoadModel(Content, "Ship"); player.rotation = new Vector3(0f, 0f, 0f); player.position.X = 0; player.position.Y = 0; player.position.Z = 0; player.scale = 0.1f; rock.LoadModel(Content, "Meteor"); rock.scale = 0.1f; rock.position = new Vector3(25, 60, -50); for (int c = 0; c < walls.Length; c++) { walls[c] = new basicCuboid(GraphicsDevice); walls[c].LoadContent(Content, "WallTexture"); walls[c].scale = new Vector3(5, 30, 60); if (c < 5) { walls[c].SetUpVertices(new Vector3(-70, 0, 60 * (c + 1))); } else if (c < 10) { walls[c].SetUpVertices(new Vector3(-70, 0, -60 * (c - 4))); } else { walls[c].scale = new Vector3(60, 30, 5); walls[c].SetUpVertices(new Vector3(-70 + (c - 10) * 60, 0, -300)); } } door = new basicCuboid(GraphicsDevice); door.LoadContent(Content, "WallTexture"); door.scale = new Vector3(5, 30, 60); door.SetUpVertices(new Vector3(-70, 0, 0)); TriggerBoxDoorOpen = new BoundingBox(new Vector3(-95, 0, 0), new Vector3(- 45, 10, 60)); TriggerBoxRockFall = new BoundingBox(new Vector3(-5, -5, -55), new Vector3(55, 5, -45)); sunlight.diffuseColor = new Vector3(10); sunlight.specularColor = new Vector3(1f, 1f, 1f); sunlight.direction = Vector3.Normalize(new Vector3(1.5f, -1.5f, -1.5f)); //music this.BGM = Content.Load <Song>("GameofBlades-TrailsofCold SteelOST"); MediaPlayer.Play(BGM); //the following line will also loop the song MediaPlayer.IsRepeating = true; MediaPlayer.MediaStateChanged += MediaPlayer_MediaStateChanged; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { BoundingRenderer.InitializeGraphics(graphics.GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice); player.LoadModel(Content, "Ship"); player.rotation = new Vector3(1.5f, 0f, 0f); player.position.X = 0; player.position.Y = 0; player.position.Z = 0; player.scale = 0.1f; //player.collisionOffset = new Vector3(0, 100.0f, 0); rock.LoadModel(Content, "Meteor"); rock.scale = 0.1f; rock.position = new Vector3(25, 60, -50); for (int c = 0; c < walls.Length; c++) { walls[c] = new basicCuboid(GraphicsDevice); walls[c].LoadContent(Content, "WallTexture"); walls[c].scale = new Vector3(5, 30, 60); if (c < 5) { walls[c].SetUpVertices(new Vector3(-70, 0, 60 * (c + 1))); } else if (c < 10) { walls[c].SetUpVertices(new Vector3(-70, 0, -60 * (c - 4))); } else { walls[c].scale = new Vector3(60, 30, 5); walls[c].SetUpVertices(new Vector3(-70 + (c - 10) * 60, 0, -300)); } } door = new basicCuboid(GraphicsDevice); door.LoadContent(Content, "WallTexture"); door.scale = new Vector3(5, 30, 60); door.SetUpVertices(new Vector3(-70, 0, 0)); TriggerBoxDoorOpen = new BoundingBox(new Vector3(-95, 0, 0), new Vector3(- 45, 10, 60)); TriggerBoxRockFall = new BoundingBox(new Vector3(-5, -5, -55), new Vector3(55, 5, -45)); sunlight.diffuseColor = new Vector3(10); sunlight.specularColor = new Vector3(1f, 1f, 1f); sunlight.direction = Vector3.Normalize(new Vector3(1.5f, -1.5f, -1.5f)); }
/// <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(); } int dt = gameTime.ElapsedGameTime.Milliseconds; base.Update(gameTime); player.storedPos = player.position; Vector3 storedAcc = acceleration; acceleration = new Vector3(0, 0, 0); if (Keyboard.GetState().IsKeyDown(Keys.Left)) { player.rotation.Y += 0.1f; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { player.rotation.Y -= 0.1f; } player.velocity *= 0.9f; // friction if (Keyboard.GetState().IsKeyDown(Keys.Up)) { acceleration.X = (float)Math.Sin(player.rotation.Y) * 0.001f; acceleration.Z = (float)Math.Cos(player.rotation.Y) * 0.001f; } // camera follow gamecam.position = new Vector3(50, 50, 50) + player.position; gamecam.target = player.position; MovePlayer(dt); foreach (basicCuboid WallSegment in walls) { if (player.hitBox.Intersects(WallSegment.collisionbox)) { ElasticCollision(WallSegment); } } if (player.hitBox.Intersects(door.collisionbox)) { ElasticCollision(door); } if (player.hitBox.Intersects(TriggerBoxRockFall) && !rockFalling) { rockFalling = true; fallStart = (float)gameTime.TotalGameTime.TotalSeconds; } if (rockFalling) { Vector3 gravity = new Vector3(0, -100f, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 4 SHOULD BE ENTERED HERE // Calculate time since rocks started falling // Calculate rock's new T position using the derived equation //Stop when you reach the ground Vector3 rockStartPos = new Vector3(25, 60, -50); float timeSinceFall = (float)gameTime.TotalGameTime.TotalSeconds - fallStart; rock.position.Y = gravity.Y * timeSinceFall * timeSinceFall / 2f + rock.velocity.Y * timeSinceFall + rockStartPos.Y; if (rock.position.Y < 0f) { rock.position.Y = 0f; fallStart = 0f; } // /////////////////////////////////////////////////////////////////// } if (player.hitBox.Intersects(TriggerBoxDoorOpen)) { doorOpening = true; } if (doorOpening) { Vector3 newPos = new Vector3(0, 0, 0); Vector3 doorStartPoint = new Vector3(-70, 0, 0); Vector3 doorEndPoint = new Vector3(-70, 30, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 5 SHOULD BE ENTERED HERE doorSequenceTimer += gameTime.ElapsedGameTime.Milliseconds; if (doorSequenceTimer >= doorSequenceFinalTime) { //Timer finished doorSequenceTimer = doorSequenceFinalTime; } newPos = CubicInterpolation(doorStartPoint, doorEndPoint, (float)doorSequenceTimer, (float)doorSequenceFinalTime); door.SetUpVertices(newPos); // /////////////////////////////////////////////////////////////////// } 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(); } int dt = gameTime.ElapsedGameTime.Milliseconds; base.Update(gameTime); player.storedPos = player.position; Vector3 storedAcc = acceleration; acceleration = new Vector3(0, 0, 0); if (Keyboard.GetState().IsKeyDown(Keys.Left)) { player.rotation.Y += 0.1f; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { player.rotation.Y -= 0.1f; } player.velocity *= 0.9f; // friction if (Keyboard.GetState().IsKeyDown(Keys.Up)) { acceleration.X = (float)Math.Sin(player.rotation.Y) * -0.001f; acceleration.Z = (float)Math.Cos(player.rotation.Y) * -0.001f; } // camera follow gamecam.position = new Vector3(50, 50, 50) + player.position; gamecam.target = player.position; MovePlayer(dt); foreach (basicCuboid WallSegment in walls) { if (player.hitBox.Intersects(WallSegment.collisionbox)) { ElasticCollision(WallSegment); } } if (player.hitBox.Intersects(door.collisionbox)) { ElasticCollision(door); } if (player.hitBox.Intersects(TriggerBoxRockFall) && !rockFalling) { rockFalling = true; rock.velocity = new Vector3(0, 0, 0); } if (rockFalling && rock.position.Y >= 0) { Vector3 gravity = new Vector3(0, -100, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 4 SHOULD BE ENTERED HERE // Vector3 rockstartpos = new Vector3(25, 60, -50); millisecondsSinceRockFall += dt; //float timeSinceRockFall = (float)gameTime.ElapsedGameTime.TotalSeconds - rockFallStart; float timeSinceRockFall = ((float)millisecondsSinceRockFall) / 1000f; rock.position.Y = (gravity.Y * timeSinceRockFall * timeSinceRockFall) / 2f + rockstartpos.Y; /////////////////////////////////////////////////////////////////// } if (player.hitBox.Intersects(TriggerBoxDoorOpen)) { doorOpening = true; } if (doorOpening) { Vector3 newPosition = new Vector3(); Vector3 doorClosed = new Vector3(-70, 0, 0); Vector3 doorOpen = new Vector3(-70, 30, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 5 SHOULD BE ENTERED HERE // //get game time doorAnimationTimer += gameTime.ElapsedGameTime.Milliseconds; if (doorAnimationTimer >= doorAnimationTimeFinished) { //reset timer doorAnimationTimer = doorAnimationTimeFinished; } newPosition = CubicInterpolation(doorClosed, doorOpen, (float)doorAnimationTimer, (float)doorAnimationTimeFinished); door.SetUpVertices(newPosition); /////////////////////////////////////////////////////////////////// } 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(); } int dt = gameTime.ElapsedGameTime.Milliseconds; base.Update(gameTime); player.storedPos = player.position; Vector3 storedAcc = acceleration; acceleration = new Vector3(0, 0, 0); if (Keyboard.GetState().IsKeyDown(Keys.Left)) { player.rotation.Y += 0.1f; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { player.rotation.Y -= 0.1f; } player.velocity *= 0.9f; // friction if (Keyboard.GetState().IsKeyDown(Keys.Up)) { acceleration.X = (float)Math.Sin(player.rotation.Y + Math.PI) * 0.001f; acceleration.Z = (float)Math.Cos(player.rotation.Y + Math.PI) * 0.001f; } // camera follow gamecam.position = new Vector3(50, 50, 50) + player.position; gamecam.target = player.position; // added time step //timeStep = (float)gameTime.ElapsedGameTime.TotalSeconds; MovePlayer(dt); foreach (basicCuboid WallSegment in walls) { if (player.hitBox.Intersects(WallSegment.collisionbox)) { ElasticCollision(WallSegment); } } if (player.hitBox.Intersects(door.collisionbox)) { ElasticCollision(door); } if (player.hitBox.Intersects(TriggerBoxRockFall) && !rockFalling) { rockFalling = true; //rock.velocity = new Vector3(0, 0.0f, 0); rockStart = gameTime.ElapsedGameTime.TotalSeconds; rockStartLocation = rock.position.Y; // assign rock fall start time } if (rockFalling) { Vector3 gravity = new Vector3(0, -100.0f, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 4 SHOULD BE ENTERED HERE // /////////////////////////////////////////////////////////////////// // calculate time since rocks started falling // remember ot add a variable to keep track of when rock stated falling // add // calculate rock's new y position using the derived equation // stop when you reach the ground (0) if (rockStart != 0.0f) { //float timeSinceFall = (float)(gameTime.TotalGameTime.TotalSeconds - rockStart); timeSinceFall += dt / 1000.0f; rock.position.Y = (gravity.Y / 2) * timeSinceFall * timeSinceFall + rockStartLocation; if (rock.position.Y < 0f) { //rock.position.Y = 0; rock.position.Y = 0; //rockStart = 0; } } } if (player.hitBox.Intersects(TriggerBoxDoorOpen)) { doorOpening = true; } if (doorOpening) { Vector3 newPos = new Vector3(); Vector3 doorStartPoint = new Vector3(-70, 0, 0); Vector3 doorEndPoint = new Vector3(-70, 30, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 5 SHOULD BE ENTERED HERE // /////////////////////////////////////////////////////////////////// //doorSequenceTimer += (int)((float)gameTime.TotalGameTime.TotalMiliSeconds); doorSequenceTimer += gameTime.ElapsedGameTime.Milliseconds; if (doorSequenceTimer >= doorSequenceFinalTime) { // reset timer doorSequenceTimer = doorSequenceFinalTime; } newPos = CubicInterpolation(doorStartPoint, doorEndPoint, (float)doorSequenceTimer, (float)doorSequenceFinalTime); door.SetUpVertices(newPos); } 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(); } int dt = gameTime.ElapsedGameTime.Milliseconds; base.Update(gameTime); player.storedPos = player.position; Vector3 storedAcc = acceleration; acceleration = new Vector3(0, 0, 0); if (Keyboard.GetState().IsKeyDown(Keys.Left)) { player.rotation.Y += 0.1f; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { player.rotation.Y -= 0.1f; } player.velocity *= 0.9f; // friction if (Keyboard.GetState().IsKeyDown(Keys.Up)) { acceleration.X = (float)Math.Sin(player.rotation.Y + Math.PI) * 0.001f; acceleration.Z = (float)Math.Cos(player.rotation.Y + Math.PI) * 0.001f; } // camera follow gamecam.position = new Vector3(50, 50, 50) + player.position; gamecam.target = player.position; MovePlayer(dt); foreach (basicCuboid WallSegment in walls) { if (player.hitBox.Intersects(WallSegment.collisionbox)) { ElasticCollision(WallSegment); } } if (player.hitBox.Intersects(door.collisionbox)) { ElasticCollision(door); } if (player.hitBox.Intersects(TriggerBoxRockFall) && !rockFalling) { rockFalling = true; //assign rock falls start time RockFallStart = (float)gameTime.TotalGameTime.TotalSeconds; rock.velocity = new Vector3(0, 0.2f, 0); } if (rockFalling && rock.position.Y >= 0) //if the rock is falling AND it is not already on the floor do this { /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 4 HERE // /////////////////////////////////////////////////////////////////// //calculate time since rocks started falling //calculate the rock's new y position using the derived equation //stop when you reach the ground (0) Vector3 gravity = new Vector3(0, -100f, 0); Vector3 rockStartpos = new Vector3(25, 60, -50); float timeSinceFall = (float)gameTime.TotalGameTime.TotalSeconds - RockFallStart; //rock position in the Y axis = 0.1 X timeSinceFall^2 /2 + velocity.y X timeSinceFall + original start Y rock.position.Y = (gravity.Y * timeSinceFall * timeSinceFall) / 2f + rockStartpos.Y; if (rock.position.Y < 0f) { rock.position.Y = 0f; RockFallStart = 0f; } } if (player.hitBox.Intersects(TriggerBoxDoorOpen)) { doorOpening = true; } if (doorOpening) { Vector3 newPos = new Vector3(); Vector3 doorStartPoint = new Vector3(-70, 0, 0); Vector3 doorEndPoint = new Vector3(-70, 30, 0); /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 5 HERE // /////////////////////////////////////////////////////////////////// // ------------------------------ // EASING // ------------------------------ //get game time doorSequenceTimer += gameTime.ElapsedGameTime.Milliseconds; if (doorSequenceTimer >= doorSequenceFinalTime) { //reset timer doorSequenceTimer = doorSequenceFinalTime; } newPos = CubicInterpolation(doorStartPoint, doorEndPoint, (float)doorSequenceTimer, (float)doorSequenceFinalTime); door.SetUpVertices(newPos); } base.Update(gameTime); }