Add accelerators
This commit is contained in:
parent
93cc5369bd
commit
6260ef1fcc
4 changed files with 46 additions and 40 deletions
35
racing.h
35
racing.h
|
@ -689,13 +689,16 @@ TPE_Unit _LCR_applyMaterialFactor(TPE_Unit value, uint8_t mat)
|
|||
}
|
||||
|
||||
void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir,
|
||||
uint8_t material)
|
||||
uint8_t material, uint8_t accelerator)
|
||||
{
|
||||
TPE_Unit acc =
|
||||
_LCR_applyMaterialFactor(LCR_CAR_ACCELERATION,material);
|
||||
|
||||
acc = acc / (1 + (LCR_racingGetCarSpeedUnsigned() / LCR_CAR_AIR_FRICTION));
|
||||
|
||||
if (accelerator)
|
||||
acc *= 2; // TODO: constant?
|
||||
|
||||
LCR_racing.carBody.joints[wheel].velocity[0] +=
|
||||
(dir.x * acc) / TPE_F;
|
||||
LCR_racing.carBody.joints[wheel].velocity[1] +=
|
||||
|
@ -727,23 +730,10 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
{
|
||||
LCR_LOG2("racing step start");
|
||||
|
||||
/*
|
||||
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
|
||||
printf(" %d: %d %d %d, %d %d %d\n",
|
||||
i,LCR_racing.carBody.joints[i].position.x,
|
||||
LCR_racing.carBody.joints[i].position.y,
|
||||
LCR_racing.carBody.joints[i].position.z,
|
||||
LCR_racing.carBody.joints[i].velocity[0],
|
||||
LCR_racing.carBody.joints[i].velocity[1],
|
||||
LCR_racing.carBody.joints[i].velocity[0]);
|
||||
|
||||
printf("------\n");
|
||||
*/
|
||||
|
||||
|
||||
uint32_t result = 0;
|
||||
TPE_Vec3 carForw, carRight, carUp, carVel;
|
||||
uint8_t groundMat = LCR_BLOCK_MATERIAL_CONCRETE; // material under wheels
|
||||
uint8_t onAccel = 0; // standing on accelerator?
|
||||
int groundBlockIndex = -1;
|
||||
|
||||
carForw = TPE_vec3Normalized(TPE_vec3Plus(
|
||||
|
@ -795,13 +785,20 @@ printf("------\n");
|
|||
}
|
||||
|
||||
if (groundBlockIndex != -1)
|
||||
{
|
||||
onAccel = LCR_mapBlockIsAccelerator(
|
||||
LCR_currentMap.blocks[groundBlockIndex * LCR_BLOCK_SIZE]);
|
||||
groundMat = LCR_mapBlockGetMaterial(
|
||||
LCR_currentMap.blocks + groundBlockIndex * LCR_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
LCR_racing.carBody.friction =
|
||||
_LCR_applyMaterialFactor(LCR_CAR_FORWARD_FRICTION,groundMat);
|
||||
|
||||
if (onAccel)
|
||||
input |= LCR_RACING_INPUT_FORW; // accelerator enforces this
|
||||
|
||||
if(!(input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK)))
|
||||
LCR_racing.carBody.friction *= LCR_CAR_STAND_FRICTION_MULTIPLIER;
|
||||
else if (
|
||||
|
@ -863,13 +860,13 @@ printf("------\n");
|
|||
{
|
||||
if (input & LCR_RACING_INPUT_FORW)
|
||||
{
|
||||
_LCR_racingWheelAccelerate(0,carForw,groundMat);
|
||||
_LCR_racingWheelAccelerate(1,carForw,groundMat);
|
||||
_LCR_racingWheelAccelerate(0,carForw,groundMat,onAccel);
|
||||
_LCR_racingWheelAccelerate(1,carForw,groundMat,onAccel);
|
||||
}
|
||||
else if (input & LCR_RACING_INPUT_BACK)
|
||||
{
|
||||
_LCR_racingWheelAccelerate(0,TPE_vec3TimesPlain(carForw,-1),groundMat);
|
||||
_LCR_racingWheelAccelerate(1,TPE_vec3TimesPlain(carForw,-1),groundMat);
|
||||
_LCR_racingWheelAccelerate(0,TPE_vec3TimesPlain(carForw,-1),groundMat,onAccel);
|
||||
_LCR_racingWheelAccelerate(1,TPE_vec3TimesPlain(carForw,-1),groundMat,onAccel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue