public void Update() { if (shakeTimer <= 0) { return; } shake.xPosition += shake.xSpeed; shake.yPosition += shake.ySpeed; if (shake.xPosition >= Constants.PI_) { shake.xPosition -= (2 * Constants.PI_); } if (shake.yPosition >= Constants.PI_) { shake.yPosition -= (2 * Constants.PI_); } float size; const float kIncProportion = 0.94f; if (shakeTimer >= (shakeTime * kIncProportion)) { size = 1 - Utilities.GetCosInterpolationHalfP1P2(shakeTimer, (shakeTime * kIncProportion), shakeTime); } else { size = Utilities.GetCosInterpolationHalfP1P2(shakeTimer, 0, (shakeTime * kIncProportion)); } x = (float)Math.Cos(shake.xPosition) * shake.xSize * size; y = (float)Math.Cos(shake.yPosition) * shake.ySize * size; shakeTimer -= Constants.kFrameRate; }
public void UpdateXPosition() { const float kCurveInDistance = 1000.0f; const float kCurveXSize = 450.0f; float distanceFromStart = position.y - myFlock.yPositionStart; if (distanceFromStart <= kCurveInDistance) { float xCurveIn = 1.0f - Utilities.GetCosInterpolationHalfP1P2(distanceFromStart, 0, kCurveInDistance); position.x = xLinePosition + (xCurveIn * kCurveXSize); return; } float distanceToEnd = myFlock.yPositionEnd - position.y; if (distanceToEnd <= kCurveInDistance) { float xCurveIn = 1.0f - Utilities.GetCosInterpolationHalfP1P2(distanceToEnd, 0, kCurveInDistance); position.x = xLinePosition - (xCurveIn * kCurveXSize); return; } position.x = xLinePosition; }
public bool Update() { if (!active) { return(false); } if (startTimer < waitToBegin) { startTimer += Constants.kFrameRate; } switch (type) { case InterpolationType.kInterp_Accelerate: value += velocity; velocity += acceleration; break; case InterpolationType.kInterp_Lag: value = value + ((1 - value) * lag); break; case InterpolationType.kInterp_Linear: break; case InterpolationType.kInterp_Cos: timer += Constants.kFrameRate; value = Utilities.GetCosInterpolationHalfP1P2(timer, 0, time); break; case InterpolationType.kInterp_Boing: if (phase == (int)Enum.kInterp_Phase1) { value += velocity; if (value >= 1) { acceleration = (-velocity * 0.1f); phase = (int)Enum.kInterp_Phase2; } } else { velocity += acceleration; value += velocity; velocity *= 0.95f; if (((acceleration > 0) && (value >= 1)) || ((acceleration < 0) && (value <= 1))) { acceleration = (-acceleration * 1.05f); if (Utilities.GetABS(acceleration) >= Utilities.GetABS((velocity))) { value = 1; active = false; return(true); } } } break; } switch (endParameter) { case InterpolationEndParameter.kInterpEnd_Time: if (timer >= time) { active = false; return(true); } break; case InterpolationEndParameter.kInterpEnd_Value: if (value >= endValue) { value = endValue; active = false; return(true); } break; default: break; } return(false); }