Pararena2/Sources/Dynamics.c

1 line
15 KiB
C
Raw Permalink Normal View History

//============================================================ //============================================================ //== == //== Game Dynamics Routines == //== == //============================================================ //============================================================ //======================================================== Includes #include "Globals.h" #include "UnivUtilities.h" #include "Dynamics.h" #include "SoundUtils.h" #include "Render.h" #include "Ball.h" //======================================================== Functions //======================================================== DoPersonBallMerged void DoPersonBallMerged (playerType *who) { register long xMomentum, zMomentum; short strategum; PlaySoundSMS(kBallPickUpSound); // calc. components of momentum xMomentum = (who->xVel * kPersonMass) + (theBall.xVel * kBallMass); zMomentum = (who->zVel * kPersonMass) + (theBall.zVel * kBallMass); // momentum / mass = velocity who->xVel = xMomentum / kPersonBallMass; who->zVel = zMomentum / kPersonBallMass; if ((who->persona == kHumanPlayer) || (who->persona == kNetHuman)) { who->mouseWasLetUp = FALSE; } else { if (who->persona == kMisterEaze) { who->strategy = (short)RandomCoin(); } else if (who->persona == kMissTeak) { strategum = RandomInt(100); if (strategum < who->teaksThresh) who->strategy = kRunDiagonal; else who->strategy = kRunCircle; } } theBall.eraseTheBall = TRUE; drawThisFrame = TRUE; who->posture = kCarrying; theBall.mode = kBallHeld; if (who->selector == kPlayerSelector) { whosGotBall = kPlayerHasBall; theBall.modifier = kPlayerHolding; theOpponent.loopsBallHeld = 0; // zero out the other's timer if (thePlayer.loopsBallHeld == 0) // ??? thePlayer.loopsBallHeld = kLoopLimitOnHeldBall; } else { whosGotBall = kOpponentHasBall; theBall.modifier = kOpponentHolding; thePlayer.loopsBallHeld = 0; if (theOpponent.loopsBallHeld == 0) theOpponent.loopsBallHeld = kLoopLimitOnHeldBall; } UpdateBallTimers(&thePlayer); UpdateBallTimers(&theOpponent); UpdateArrows(); } //======================================================== DoPersonBallParted void DoPersonBallParted (playerType *who) { #define kBallDiskDistance 1216 #define kOffsetMultiplier 2 short deltaPX, deltaPZ; PlaySoundSMS(kBallDropSound); deltaPX = boardForceTable[who->direction][kXComponent] * kPersonImpulse; deltaPZ = boardForceTable[who->direction][kZComponent] * kPersonImpulse; theBall.xVel = who->xVel + (deltaPX / kBallMass); // momentum => velocity theBall.zVel = who->zVel + (deltaPZ / kBallMass); // x & z components theBall.xPos = who->xPos + (deltaPX * kOffsetMultiplier); // get ball clear<61> theBall.zPos = who->zPos + (deltaPZ * kOffsetMultiplier); // of disk. BallRectFromPosition(); who->xVel -= deltaPX / kPersonMass; who->zVel -= deltaPZ / kPersonMass; who->posture = kCrouching; theBall.mode = kBallRolling; whosGotBall = kBallRollsFreely; if (who->selector == kPlayerSelector) { theBall.modifier = kPlayerLastHeld; } else { theBall.modifier = kOpponentLastHeld; } if (thePlayer.persona == kMissTeak) { oldDistSquared = ((long)(thePlayer.xPos) * (long)(thePlayer.xPos)) + ((long)(thePlayer.zPos) * (long)(thePlayer.zPos)); } else if (theOpponent.persona == kMissTeak) { oldDistSquared = ((long)(theOpponent.xPos) * (long)(theOpponent.xPos)) + ((long)(theOpponent.zPos) * (long)(theOpponent.zPos)); } if ((who->persona == kHumanPlayer) || (who->persona == kNetHuman)) who->mouseWasLetUp = FALSE; UpdateArrows(); } //======================================================== DoPersonBallCollided void DoPersonBallCollided (playerType *who) { #define kPBLimitScale 512L // 1024 occ. probs, 2048 more probs short original2XVel, original2ZVel; long distX, distZ; long new1XVel, new1ZVel, new2XVel, new2ZVel; long distSquared, scalar1, scalar2; who->xPos -= (who->