Start crash sound
This commit is contained in:
parent
367112dbd9
commit
b90f5bbfc8
4 changed files with 103 additions and 46 deletions
63
racing.h
63
racing.h
|
@ -45,6 +45,8 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
|
|||
#define LCR_CAR_DRIFT_THRESHOLD_1 (LCR_GAME_UNIT / 4)
|
||||
#define LCR_CAR_DRIFT_THRESHOLD_0 (LCR_GAME_UNIT / 200)
|
||||
|
||||
#define LCR_CAR_CRASH_SPEED_THRESHOLD 25
|
||||
|
||||
// multipliers (in 8ths) of friction and acceleration on concrete:
|
||||
#define LCR_CAR_GRASS_FACTOR 5
|
||||
#define LCR_CAR_DIRT_FACTOR 3
|
||||
|
@ -62,27 +64,35 @@ struct
|
|||
TPE_Connection carConnections[LCR_CAR_CONNECTIONS];
|
||||
|
||||
uint32_t tick;
|
||||
uint8_t wheelCollisions; /**< In individual bits records for each car wheel
|
||||
whether it's currently touching the ground.
|
||||
Lower bits record current collisions, higher
|
||||
bits the previous state (for averaging). */
|
||||
uint8_t wheelCollisions; /**< In individual bits records for each car wheel
|
||||
whether it's currently touching the ground.
|
||||
Lower bits record current collisions, higher
|
||||
bits the previous state (for averaging). */
|
||||
|
||||
TPE_Vec3 carPositions[2]; ///< Current and previous position in game units.
|
||||
TPE_Vec3 carRotations[2]; ///< Current and previous rotation in game units.
|
||||
uint8_t carDrifting; ///< Whether or not the car is currently in drift.
|
||||
TPE_Vec3 carPositions[2]; ///< Current and previous position in game units.
|
||||
TPE_Vec3 carRotations[2]; ///< Current and previous rotation in game units.
|
||||
uint8_t carDrifting; ///< Whether or not the car is currently in drift.
|
||||
|
||||
TPE_Unit fanForce; ///< Upwards acceleration caused by a fan.
|
||||
LCR_GameUnit wheelAngle; ///< Current wheel angle, 0 to LCR_GAME_UNIT.
|
||||
LCR_GameUnit wheelSteer; ///< Left/right steer with LCR_CAR_STEER_MAX bounds.
|
||||
TPE_Unit fanForce; ///< Upwards acceleration caused by a fan.
|
||||
LCR_GameUnit wheelAngle; ///< Current wheel angle, 0 to LCR_GAME_UNIT.
|
||||
LCR_GameUnit wheelSteer; ///< Left/right steer, LCR_CAR_STEER_MAX bounds.
|
||||
|
||||
LCR_GameUnit carSpeed; /**< Signed speed in game units per tick (negative
|
||||
if backwards) */
|
||||
LCR_GameUnit carSpeeds[2]; /**< Signed speed in game units per tick (negative
|
||||
if backwards) and its previous value. */
|
||||
|
||||
// for fixing physics bugs:
|
||||
TPE_Vec3 carOKPositions[LCR_CAR_JOINTS];
|
||||
uint8_t carNotOKCount;
|
||||
} LCR_racing;
|
||||
|
||||
/**
|
||||
Gets times of the run in milliseconds.
|
||||
*/
|
||||
uint32_t LCR_racingGetRunTimeMS()
|
||||
{
|
||||
return LCR_racing.tick * LCR_RACING_TICK_MS;
|
||||
}
|
||||
|
||||
TPE_Vec3 _LCR_TPE_vec3DividePlain(TPE_Vec3 v, TPE_Unit d)
|
||||
{
|
||||
v.x /= d; v.y /= d; v.z /= d;
|
||||
|
@ -483,13 +493,13 @@ TPE_Vec3 _LCR_racingEnvironmentFunction(TPE_Vec3 point, TPE_Unit maxDist)
|
|||
|
||||
LCR_GameUnit LCR_racingGetCarSpeedUnsigned(void)
|
||||
{
|
||||
return LCR_racing.carSpeed >= 0 ? LCR_racing.carSpeed :
|
||||
(-1 * LCR_racing.carSpeed);
|
||||
return LCR_racing.carSpeeds[0] >= 0 ? LCR_racing.carSpeeds[0] :
|
||||
(-1 * LCR_racing.carSpeeds[0]);
|
||||
}
|
||||
|
||||
LCR_GameUnit LCR_racingGetCarSpeedSigned(void)
|
||||
{
|
||||
return LCR_racing.carSpeed;
|
||||
return LCR_racing.carSpeeds[0];
|
||||
}
|
||||
|
||||
uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2,
|
||||
|
@ -569,7 +579,8 @@ void LCR_racingRestart(void)
|
|||
|
||||
LCR_racing.wheelAngle = 0;
|
||||
LCR_racing.wheelSteer = 0;
|
||||
LCR_racing.carSpeed = 0;
|
||||
LCR_racing.carSpeeds[0] = 0;
|
||||
LCR_racing.carSpeeds[1] = 0;
|
||||
LCR_racing.carDrifting = 0;
|
||||
|
||||
// make the car body:
|
||||
|
@ -874,8 +885,8 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
if(!(input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK)))
|
||||
LCR_racing.carBody.friction *= LCR_CAR_STAND_FRICTION_MULTIPLIER;
|
||||
else if (
|
||||
((input & LCR_RACING_INPUT_FORW) && (LCR_racing.carSpeed < 0)) ||
|
||||
((input & LCR_RACING_INPUT_BACK) && (LCR_racing.carSpeed > 0)))
|
||||
((input & LCR_RACING_INPUT_FORW) && (LCR_racing.carSpeeds[0] < 0)) ||
|
||||
((input & LCR_RACING_INPUT_BACK) && (LCR_racing.carSpeeds[0] > 0)))
|
||||
LCR_racing.carBody.friction *= 2 * LCR_CAR_STAND_FRICTION_MULTIPLIER;
|
||||
|
||||
if (input)
|
||||
|
@ -1066,11 +1077,23 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
TPE_worldStep(&(LCR_racing.physicsWorld));
|
||||
LCR_LOG2("stepping physics engine done");
|
||||
|
||||
LCR_racing.carSpeed = (TPE_vec3Len(carVel) * LCR_GAME_UNIT)
|
||||
int speedDiff = LCR_racing.carSpeeds[0] - LCR_racing.carSpeeds[1];
|
||||
|
||||
LCR_racing.carSpeeds[1] = LCR_racing.carSpeeds[0];
|
||||
|
||||
LCR_racing.carSpeeds[0] = (TPE_vec3Len(carVel) * LCR_GAME_UNIT)
|
||||
/ LCR_PHYSICS_UNIT;
|
||||
|
||||
if (TPE_vec3Dot(carVel,carForw) < 0)
|
||||
LCR_racing.carSpeed *= -1;
|
||||
LCR_racing.carSpeeds[0] *= -1;
|
||||
|
||||
else if (speedDiff < -1 * LCR_CAR_CRASH_SPEED_THRESHOLD)
|
||||
{
|
||||
result |= (speedDiff < -2 * LCR_CAR_CRASH_SPEED_THRESHOLD) ?
|
||||
LCR_RACING_EVENT_CRASH_BIG : LCR_RACING_EVENT_CRASH_SMALL;
|
||||
|
||||
LCR_racing.carSpeeds[1] = 0; // prevent several crash events in a row
|
||||
}
|
||||
|
||||
_LCR_racingUpdateCarPosRot();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue