void PySimple1::getGap(double ylast, double dy, double dy_old) { // For stability in Closure spring, may limit "dy" step size to avoid // overshooting on the closing of this gap. // TGap_y = ylast + dy; if(TGap_y > TClose_yright) {dy = 0.75*(TClose_yright - ylast);} if(TGap_y < TClose_yleft) {dy = 0.75*(TClose_yleft - ylast);} // Limit "dy" step size if it is oscillating in sign and not shrinking // if(dy*dy_old < 0.0 && fabs(dy/dy_old) > 0.5) dy = -dy_old/2.0; // Combine the Drag and Closure elements in parallel, starting by // resetting TGap_y in case the step size was limited. // TGap_y = ylast + dy; getClosure(ylast,dy); getDrag(ylast,dy); TGap_p = TDrag_p + TClose_p; TGap_tang = TDrag_tang + TClose_tang; // Ensure that |p|<pmax. // if(fabs(TGap_p)>=pult) TGap_p =(TGap_p/fabs(TGap_p))*(1.0-PYtolerance)*pult; return; }
void Character::movementScript(float movementSpeed) { float power = getDrag().x; if (isPressed("s2")) power *= 0.5; else if (isPressed("s1")) power *= 0.25; onSwing(power); if (isPressed("s1")) { if (isPressed("up")) { Vector2D v(0, -movementSpeed); v.rotate(getRotC().position); onPush(v); }else if (isPressed("down")) { Vector2D v(0, -movementSpeed * 0.125f); v.rotate(getRotC().position + 180); onPush(v); } return; } if (!(isPressed("up") && isPressed("down"))) { if (isPressed("up")) { Vector2D v(0, -movementSpeed); v.rotate(getRotC().position); if (!(isPressed("left") && isPressed("right"))) { if (isPressed("left")) { v.rotate(-45); } else if (isPressed("right")) { v.rotate(45); } } onPush(v); } if (isPressed("down")) { Vector2D v(0, movementSpeed); v.rotate(getRotC().position); if (!(isPressed("left") && isPressed("right"))) { if (isPressed("left")) { v.rotate(45); } else if (isPressed("right")) { v.rotate(-45); } } onPush(v); } } if (!(isPressed("left") && isPressed("right")) && !isPressed("up") && !isPressed("down")) { if (isPressed("left")) { Vector2D v(-movementSpeed, 0); v.rotate(getRotC().position); onPush(v); } else if (isPressed("right")) { Vector2D v(movementSpeed, 0); v.rotate(getRotC().position); onPush(v); } } }