/// <summary> /// This Method is called a Event Handler. It is the action that happens when the Button Click Event Happens /// </summary> /// <param name="sender">The object that sent the button click.</param> /// <param name="e">Arguments that come from the routed event</param> private void CalcButton_Click(object sender, RoutedEventArgs e) { decimal minutesLeft = decimal.Parse(txt_MinutesLeft.Text); //Gets mins as a decimal from the user. (Doesn't check if they dont enter a number) decimal distanceInMiles = decimal.Parse(txt_Distance.Text); //Gets miles as a decimal from the user. (Doesn't check if they dont enter a number) int speedInMPH = SpeedProvider.RequiredSpeedInMPH(distanceInMiles, minutesLeft); int speedinKPH = SpeedProvider.ConvertMPHtoKPH(speedInMPH); TxtBx_SpeedMph.Text = speedInMPH.ToString(); TxtBx_SpeedKph.Text = speedinKPH.ToString(); }
public void beKnockedBack(SpeedProvider chrc, Dir dir, int amount) { if (dir == Dir.LEFT) { if (leftBlocked) { return; } chrc.setSpeedX(-amount / 100f); } if (dir == Dir.RIGHT) { if (rightBlocked) { return; } chrc.setSpeedX(amount / 100f); } }
public void FixedUpdate(SpeedProvider chrc) { if (layerMask < 0) { layerMask = 1 << LayerMask.NameToLayer("Ground"); if (layerMask < 0) { return; } } Vector2 c = chrc.getCenter(); float speedX = chrc.getSpeedX(); float speedY = chrc.getSpeedY(); Vector2 normalX = new Vector2(Mathf.Sign(speedX), 0); Vector2 normalY = new Vector2(0, Mathf.Sign(speedY)); if (chrc.isRightFacing()) { rUp = doGetValidMovement(normalY, speedY, getTopLeftPlusDelta(c), getTopMiddle(c), getTopRightMinusDelta(c)); rDown = doGetValidMovement(normalY, speedY, getBotLeftPlusDelta(c), getBotMiddle(c), getBotRightMinusDelta(c)); } else { rUp = doGetValidMovement(normalY, speedY, getTopRightMinusDelta(c), getTopMiddle(c), getTopLeftPlusDelta(c)); rDown = doGetValidMovement(normalY, speedY, getBotRightMinusDelta(c), getBotMiddle(c), getBotLeftPlusDelta(c)); } if (speedX > 0) { if (isGrounded()) { rX = doGetValidMovement(normalX, speedX, getTopRight(c), getRight(c), getLowRight(c)); } else { rX = doGetValidMovement(normalX, speedX, getTopRight(c), getRight(c), getBotRight(c)); } if (rX.isHit()) { rightBlocked = true; } else { rightBlocked = false; } } else { if (isGrounded()) { rX = doGetValidMovement(normalX, speedX, getTopLeft(c), getLeft(c), getLowLeft(c)); } else { rX = doGetValidMovement(normalX, speedX, getTopLeft(c), getLeft(c), getBotLeft(c)); } if (rX.isHit()) { leftBlocked = true; } else { leftBlocked = false; } } }