/// <summary> /// Updates the game state /// </summary> public void UpdateGame() { #region Step 4a. Update Rocket control mRocket.RotateAngleInRadian += MathHelper.ToRadians(InputWrapper.ThumbSticks.Right.X); mRocket.Position += InputWrapper.ThumbSticks.Left; #endregion #region Step 4b. Update net in flight /// Set net to flight if (InputWrapper.Buttons.A == ButtonState.Pressed) { mNetInFlight = true; mNet.RotateAngleInRadian = mRocket.RotateAngleInRadian; mNet.Position = mRocket.Position; mNetVelocity = ShowVector.RotateVectorByAngle( mRocketInitDirection, mNet.RotateAngleInRadian) * mNetSpeed; } #endregion #region Step 4c. Update bee respawn if (!mInsectPreset) { float x = 15f + ((float)Game1.sRan.NextDouble() * 30f); float y = 15f + ((float)Game1.sRan.NextDouble() * 30f); mInsect.Position = new Vector2(x, y); mInsectPreset = true; } #endregion #region Step 5. Inter-object interaction: Net in flight and collision with insect if (mNetInFlight) { mNet.Position += mNetVelocity; if (mNet.PrimitivesTouches(mInsect)) { mInsectPreset = false; mNetInFlight = false; mNumInsectShot++; } if ((Camera.CollidedWithCameraWindow(mNet) != Camera.CameraWindowCollisionStatus.InsideWindow)) { mNetInFlight = false; mNumMissed++; } } #endregion }
public bool PixelTouches(TexturedPrimitive otherPrim, out Vector2 collidePoint) { bool touches = PrimitivesTouches(otherPrim); collidePoint = Position; if (touches) { bool pixelTouch = false; #region Step 3a. Vector2 myXDir = ShowVector.RotateVectorByAngle(Vector2.UnitX, RotateAngleInRadian); Vector2 myYDir = ShowVector.RotateVectorByAngle(Vector2.UnitY, RotateAngleInRadian); Vector2 otherXDir = ShowVector.RotateVectorByAngle(Vector2.UnitX, otherPrim.RotateAngleInRadian); Vector2 otherYDir = ShowVector.RotateVectorByAngle(Vector2.UnitY, otherPrim.RotateAngleInRadian); #endregion #region Step 3b. int i = 0; while ((!pixelTouch) && (i < mImage.Width)) { int j = 0; while ((!pixelTouch) && (j < mImage.Height)) { collidePoint = IndexToCameraPosition(i, j, myXDir, myYDir); Color myColor = GetColor(i, j); if (myColor.A > 0) { Vector2 otherIndex = otherPrim.CameraPositionToIndex(collidePoint, otherXDir, otherYDir); int xMin = (int)otherIndex.X; int yMin = (int)otherIndex.Y; if ((xMin >= 0) && (xMin < otherPrim.mImage.Width) && (yMin >= 0) && (yMin < otherPrim.mImage.Height)) { pixelTouch = (otherPrim.GetColor(xMin, yMin).A > 0); } } j++; } i++; } #endregion touches = pixelTouch; } return(touches); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public void UpdateGame() { #region Step 3a. Change current selected vector if (InputWrapper.Buttons.A == ButtonState.Pressed) { mCurrentLocator = mPa; } else if (InputWrapper.Buttons.B == ButtonState.Pressed) { mCurrentLocator = mPb; } else if (InputWrapper.Buttons.X == ButtonState.Pressed) { mCurrentLocator = mPx; } else if (InputWrapper.Buttons.Y == ButtonState.Pressed) { mCurrentLocator = mPy; } #endregion #region Step 3b. Move Vector // Change the current locator position mCurrentLocator.Position += InputWrapper.ThumbSticks.Right; #endregion #region Step 3c. Rotate Vector // Left thumbstick-X rotates the vector at Py float rotateYByRadian = MathHelper.ToRadians( InputWrapper.ThumbSticks.Left.X); #endregion #region Step 3d. Increase/Decrease the length of vector // Left thumbstick-Y increase/decrease the length of vector at Py float vecYLen = mVectorAtPy.Length(); vecYLen += InputWrapper.ThumbSticks.Left.Y; #endregion #region Step 3e. Compute vector changes // Compute the rotated direction of vector at Py mVectorAtPy = ShowVector.RotateVectorByAngle(mVectorAtPy, rotateYByRadian); mVectorAtPy.Normalize(); // Normalize vectorATY to size of 1f mVectorAtPy *= vecYLen; // Scale the vector to the new size #endregion }
/// <summary> /// This is called when the game should draw itself. /// </summary public void DrawGame() { // Drawing the vectors Vector2 v = mPb.Position - mPa.Position; // Vector V is from Pa to Pb // Draw Vector-V at Pa, and Px ShowVector.DrawFromTo(mPa.Position, mPb.Position); ShowVector.DrawPointVector(mPx.Position, v); // Draw VectorAtY at Py ShowVector.DrawPointVector(mPy.Position, mVectorAtPy); mPa.Draw(); mPb.Draw(); mPx.Draw(); mPy.Draw(); // Print out text message to echo status FontSupport.PrintStatus("Locator Positions: A=" + mPa.Position + " B=" + mPb.Position, null); }