//----------------------- Feng ------------------------------------------------ // 检测车辆是否碰到了障碍物 private bool CheckCollision(Hazard theHazard, int n) { // 分别计算并使用封闭(包裹)盒给障碍物和车 BoundingBox aHazardBox = new BoundingBox(new Vector3(theHazard.Position.X, theHazard.Position.Y, 0), new Vector3(theHazard.Position.X + (mHazard.Width * .4f), theHazard.Position.Y + ((mHazard.Height - 50) * .4f), 0)); BoundingBox aCarBox = new BoundingBox(new Vector3(mCarPosition.X, mCarPosition.Y, 0), new Vector3(mCarPosition.X + (mCar.Width * .2f), mCarPosition.Y + (mCar.Height * .2f), 0)); if (aHazardBox.Intersects(aCarBox) == true) // 碰上了吗? { int temp = 5; if (mCartype == 2) { temp = 3; } else if (mCartype == 3) { temp = 4; } if (n == 1) {//碰到障碍物 mCurrentState = State.Crash; mCarsRemaining -= 1; } else {//碰到医药包 mCarsRemaining += 1; mCurrentState = State.AddLife; } if (mCarsRemaining <= 0) { mCurrentState = State.GameOver; mExitCountDown = 10; } else if (mCarsRemaining > temp) { mCarsRemaining = temp; } return(true); } return(false); }
//----------------------- Feng ------------------------------------------------ // 检测车辆是否碰到了障碍物 private bool CheckCollision(Hazard theHazard) { // 分别计算并使用封闭(包裹)盒给障碍物和车 BoundingBox aHazardBox = new BoundingBox(new Vector3(theHazard.Position.X, theHazard.Position.Y, 0), new Vector3(theHazard.Position.X + (mHazard.Width * .2f), theHazard.Position.Y + ((mHazard.Height - 50) * .2f), 0)); BoundingBox aCarBox = new BoundingBox(new Vector3(mCarPosition.X, mCarPosition.Y, 0), new Vector3(mCarPosition.X + (mCar.Width * .2f), mCarPosition.Y + (mCar.Height * .2f), 0)); if (aHazardBox.Intersects(aCarBox) == true) // 碰上了吗? { mCurrentState = State.Crash; mCarsRemaining -= 1; if (mCarsRemaining < 0) { mCurrentState = State.GameOver; mExitCountDown = 10; } return(true); } return(false); }
private void AddLifeBox() { int aRoadPosition = mRandom.Next(1, 100); int aPosition = 110; if ((aRoadPosition % 3) == 0) { aPosition = 275; } else if ((aRoadPosition % 5) == 0) { aPosition = 440; } else if ((aRoadPosition % 7) == 0) { aPosition = 590; } bool aAddNewLifeBox = true; foreach (Hazard aLifeBox in mLifeBoxs) { if (aLifeBox.Visible == false) { aAddNewLifeBox = false; aLifeBox.Visible = true; aLifeBox.Position = new Vector2(aPosition, -mLifeBox.Height); break; } } if (aAddNewLifeBox == true) { //Add a hazard to the left side of the Road Hazard aLifeBox = new Hazard(); aLifeBox.Position = new Vector2(aPosition, -mLifeBox.Height); mLifeBoxs.Add(aLifeBox); } }
private void AddHazard2() { int aRoadPosition2 = mRandom.Next(1, 5); int aPosition2 = 135; if (aRoadPosition2 == 2) { aPosition2 = 440; } if (aRoadPosition2 == 3) { aPosition2 = 585; } if (aRoadPosition2 == 4) { aPosition2 = 275; } bool aAddNewHazard2 = true; foreach (Hazard aHazard in mHazards2) { if (aHazard.Visible == false) { aAddNewHazard2 = false; aHazard.Visible = true; aHazard.Position = new Vector2(aPosition2, -mCar2.Height); break; } } if (aAddNewHazard2 == true) { //Add a hazard to the left side of the Road Hazard aHazard = new Hazard(); aHazard.Position = new Vector2(aPosition2, -mCar2.Height); mHazards2.Add(aHazard); } }
private void AddHazard() { int aRoadPosition = mRandom.Next(1, 100); int aPosition = 110; if ((aRoadPosition % 4) == 1) { aPosition = 275; } else if ((aRoadPosition % 4) == 2) { aPosition = 440; } else if ((aRoadPosition % 4) == 3) { aPosition = 590; } bool aAddNewHazard = true; foreach (Hazard aHazard in mHazards) { if (aHazard.Visible == false) { aAddNewHazard = false; aHazard.Visible = true; aHazard.Position = new Vector2(aPosition, -mHazard.Height); break; } } if (aAddNewHazard == true) { //Add a hazard to the left side of the Road Hazard aHazard = new Hazard(); aHazard.Position = new Vector2(aPosition, -mHazard.Height); mHazards.Add(aHazard); } }
//----------------------- Tian --------------------- private void MoveHazard(Hazard theHazard) { theHazard.Position.Y += mVelocityY; if (theHazard.Position.Y > graphics.GraphicsDevice.Viewport.Height && theHazard.Visible == true) { theHazard.Visible = false; mHazardsPassed += 1; if (mHazardsPassed >= 100) // 如果通过100个障碍物,成功! { mCurrentState = State.Success; mExitCountDown = 10; } mIncreaseVelocity -= 1; if (mIncreaseVelocity < 0) { mIncreaseVelocity = 5; mVelocityY += 1; } } }
//----------------------- Tian --------------------- private void MoveHazard(Hazard theHazard) { theHazard.Position.Y += mVelocityY; if (theHazard.Position.Y > graphics.GraphicsDevice.Viewport.Height && theHazard.Visible == true) { theHazard.Visible = false; mHazardsPassed += 1; score += 5; if (mHazardsPassed >= 200) // 如果超过200个障碍物,通关游戏 { MediaPlayer.Pause(); cheer.Play(); mCurrentState = State.Success; mExitCountDown = 10; } mIncreaseVelocity -= 1; if (mIncreaseVelocity < 0) { mIncreaseVelocity = 5; mVelocityY += 1; } } }
//----------------------- Tian --------------------- private void MoveHazard(Hazard theHazard) { int temp = 0; if (mCartype == 1) { temp = 10; } else if (mCartype == 2) { temp = 0; } else if (mCartype == 3) { temp = 5; } theHazard.Position.Y += (mVelocityY + temp); //改变Hazard的Y坐标,让障碍移动;不同类型速度不一样 if (theHazard.Position.Y > graphics.GraphicsDevice.Viewport.Height && theHazard.Visible == true) { // 检测路障有没有移出游戏窗口 theHazard.Visible = false; mHazardsPassed += 1; if (mHazardsPassed >= 100) // 如果通过100个障碍物,成功! { mCurrentState = State.Success; mExitCountDown = 10; //游戏结束倒计时 } mIncreaseVelocity -= 1; if (mIncreaseVelocity < 0) { mIncreaseVelocity = 5; mVelocityY += 1; } } }
//----------------------- Feng ------------------------------------------------ // 检测车辆是否碰到了障碍物 private bool CheckCollision(Hazard theHazard) { // 分别计算并使用封闭(包裹)盒给障碍物和车 BoundingBox aHazardBox = new BoundingBox(new Vector3(theHazard.Position.X, theHazard.Position.Y, 0), new Vector3(theHazard.Position.X + (mHazard.Width * .2f), theHazard.Position.Y + ((mHazard.Height - 50) * .2f), 0)); BoundingBox aCarBox = new BoundingBox(new Vector3(mCarPosition.X, mCarPosition.Y, 0), new Vector3(mCarPosition.X + (mCar.Width * .2f), mCarPosition.Y + (mCar.Height * .2f), 0)); if (aHazardBox.Intersects(aCarBox) == true) // 碰上了吗? { mCurrentState = State.Crash; mCarsRemaining -= 1; if (mCarsRemaining < 0) { mCurrentState = State.GameOver; mExitCountDown = 10; } return true; } return false; }
private void AddHazard() { int aRoadPosition = mRandom.Next(1, 5); int aPosition = 275; if (aRoadPosition == 2) { aPosition = 440; } else if (aRoadPosition == 3) { aPosition = 565; } else if (aRoadPosition == 4) { aPosition = 125; } bool aAddNewHazard = true; foreach (Hazard aHazard in mHazards) { if (aHazard.Visible == false) { aAddNewHazard = false; aHazard.Visible = true; aHazard.Position = new Vector2(aPosition, -mHazard.Height); break; } } if (aAddNewHazard == true) { //Add a hazard to the left side of the Road Hazard aHazard = new Hazard(); aHazard.Position = new Vector2(aPosition, -mHazard.Height); mHazards.Add(aHazard); } }
private void AddHazard() { int aRoadPosition = mRandom.Next(1, 5);//哪条道出障碍 int aPosition = 10 + 140 * aRoadPosition; bool aAddNewHazard = true; foreach (Hazard aHazard in mHazards) { if (aHazard.Visible == false) { aAddNewHazard = false; aHazard.Visible = true; aHazard.Position = new Vector2(aPosition, -mHazard.Height); break; } } if (aAddNewHazard == true) { //Add a hazard to the left side of the Road Hazard aHazard = new Hazard(); aHazard.Position = new Vector2(aPosition, -mHazard.Height); mHazards.Add(aHazard); } }
private void AddHazard() { int aRoadPosition = mRandom.Next(1, 8); int aPosition = 90 + mRandom.Next(-40,40); if (aRoadPosition == 2) { aPosition = 265 + mRandom.Next(-40, 40); } else if (aRoadPosition == 3 ) { aPosition = 455 + mRandom.Next(-40, 40); } else if (aRoadPosition == 4) { aPosition = 610 + mRandom.Next(-40, 40); } else if (aRoadPosition == 5) { aPosition = 180 + mRandom.Next(-20, 20); } else if (aRoadPosition == 6 ) { aPosition = 530 + mRandom.Next(-20, 20); } else if (aRoadPosition == 7) { aPosition = 360 + mRandom.Next(-20, 20); } bool aAddNewHazard = true; foreach (Hazard aHazard in mHazards) { if (aHazard.Visible == false) { aAddNewHazard = false; aHazard.Visible = true; aHazard.Position = new Vector2(aPosition, -mHazard.Height); break; } } if (aAddNewHazard == true) { //Add a hazard to the left side of the Road Hazard aHazard = new Hazard(); aHazard.Position = new Vector2(aPosition, -mHazard.Height); mHazards.Add(aHazard); } }