Fix crash sounds a bit
This commit is contained in:
parent
bf06697917
commit
e695921c5c
4 changed files with 36 additions and 11 deletions
1
TODO.txt
1
TODO.txt
|
@ -33,6 +33,7 @@
|
|||
=========== HANDLED ==============
|
||||
|
||||
- allow stopping car rotation in air like in Trackmania
|
||||
- option to disable crash sounds (and so code that detects crashes)
|
||||
- drawing dithered transparent objects fills z-buffer in the transparent parts
|
||||
and then the geometry behind it isn't drawn <- PARTIALLY FIXED, LOOKS GOOD
|
||||
- starting test replay two twice in a row breaks it
|
||||
|
|
2
audio.h
2
audio.h
|
@ -70,7 +70,7 @@ uint8_t LCR_audioGetNextSample(void)
|
|||
case LCR_SOUND_CRASH_SMALL:
|
||||
case LCR_SOUND_CRASH_BIG:
|
||||
{
|
||||
int limit = (LCR_audio.soundPlayed == LCR_SOUND_CRASH_BIG ? 256 : 128) -
|
||||
int limit = (LCR_audio.soundPlayed == LCR_SOUND_CRASH_BIG ? 256 : 96) -
|
||||
(LCR_audio.soundPlayedFrame * 256) / LCR_AUDIO_CRASH_LEN;
|
||||
|
||||
if (LCR_audio.frame % 2 || // lower frequency
|
||||
|
|
39
racing.h
39
racing.h
|
@ -66,8 +66,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_DIFF 25
|
||||
#define LCR_CAR_CRASH_SPEED_THRESHOLD 70
|
||||
#define LCR_CAR_CRASH_SPEED_SMALL 400
|
||||
#define LCR_CAR_CRASH_SPEED_BIG 800
|
||||
|
||||
// multipliers (in 8ths) of friction and acceleration on concrete:
|
||||
#define LCR_CAR_GRASS_FACTOR 5
|
||||
|
@ -108,6 +108,8 @@ struct
|
|||
TPE_Vec3 carOKPositions[LCR_CAR_JOINTS];
|
||||
uint8_t carNotOKCount;
|
||||
|
||||
uint16_t crashState;
|
||||
|
||||
uint8_t playingReplay;
|
||||
} LCR_racing;
|
||||
|
||||
|
@ -795,6 +797,20 @@ uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2,
|
|||
{
|
||||
// check which wheels are touching the ground.
|
||||
|
||||
#if LCR_SETTING_CRASH_SOUNDS
|
||||
TPE_Unit speed = TPE_vec3Len( // detect crashes
|
||||
TPE_vec3Project(
|
||||
TPE_vec3(
|
||||
LCR_racing.carBody.joints[j1].velocity[0],
|
||||
LCR_racing.carBody.joints[j1].velocity[1],
|
||||
LCR_racing.carBody.joints[j1].velocity[2]),
|
||||
TPE_vec3Minus(p,
|
||||
LCR_racing.carBody.joints[j1].position)));
|
||||
|
||||
LCR_racing.crashState |= ((speed >= LCR_CAR_CRASH_SPEED_BIG) << 1) |
|
||||
(speed >= LCR_CAR_CRASH_SPEED_SMALL);
|
||||
#endif
|
||||
|
||||
if (j1 < 4) // wheel joint?
|
||||
LCR_racing.wheelCollisions |= 0x01 << j1;
|
||||
|
||||
|
@ -872,6 +888,7 @@ void LCR_racingRestart(uint8_t replay)
|
|||
LCR_racing.carSpeeds[0] = 0;
|
||||
LCR_racing.carSpeeds[1] = 0;
|
||||
LCR_racing.carDrifting = 0;
|
||||
LCR_racing.crashState = 0;
|
||||
|
||||
// make the car body:
|
||||
TPE_makeCenterRectFull(LCR_racing.carJoints,
|
||||
|
@ -1339,14 +1356,14 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
LCR_racing.fanForce = 0;
|
||||
}
|
||||
|
||||
#if LCR_SETTING_CRASH_SOUNDS
|
||||
LCR_racing.crashState <<= 2;
|
||||
#endif
|
||||
|
||||
LCR_LOG2("stepping physics (start)");
|
||||
TPE_worldStep(&(LCR_racing.physicsWorld));
|
||||
LCR_LOG2("stepping physics (end)");
|
||||
|
||||
int speedDiff =
|
||||
TPE_abs(LCR_racing.carSpeeds[0]) -
|
||||
TPE_abs(LCR_racing.carSpeeds[1]);
|
||||
|
||||
LCR_racing.carSpeeds[1] = LCR_racing.carSpeeds[0];
|
||||
|
||||
LCR_racing.carSpeeds[0] = (TPE_vec3Len(carVel) * LCR_GAME_UNIT)
|
||||
|
@ -1355,10 +1372,12 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
if (TPE_vec3Dot(carVel,carForw) < 0)
|
||||
LCR_racing.carSpeeds[0] *= -1;
|
||||
|
||||
if (speedDiff < -1 * LCR_CAR_CRASH_SPEED_DIFF &&
|
||||
TPE_abs(LCR_racing.carSpeeds[0]) <= LCR_CAR_CRASH_SPEED_THRESHOLD)
|
||||
result |= (speedDiff < -2 * LCR_CAR_CRASH_SPEED_DIFF) ?
|
||||
LCR_RACING_EVENT_CRASH_BIG : LCR_RACING_EVENT_CRASH_SMALL;
|
||||
#if LCR_SETTING_CRASH_SOUNDS
|
||||
if (LCR_racing.crashState == 1)
|
||||
result |= LCR_RACING_EVENT_CRASH_SMALL;
|
||||
else if (LCR_racing.crashState == 3)
|
||||
result |= LCR_RACING_EVENT_CRASH_BIG;
|
||||
#endif
|
||||
|
||||
_LCR_racingUpdateCarPosRot();
|
||||
|
||||
|
|
|
@ -225,4 +225,9 @@
|
|||
#define LCR_SETTING_CAR_RENDER_DISTANCE 25
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_CRASH_SOUNDS
|
||||
/** Whether or not to detect crashes and play their sounds. */
|
||||
#define LCR_SETTING_CRASH_SOUNDS 1
|
||||
#endif
|
||||
|
||||
#endif // guard
|
||||
|
|
Loading…
Reference in a new issue