Add accelerators

This commit is contained in:
Miloslav Ciz 2024-12-15 21:43:43 +01:00
parent 93cc5369bd
commit 6260ef1fcc
4 changed files with 46 additions and 40 deletions

View file

@ -1,5 +1,8 @@
=========== GENERAL ==============
- rework the code for special blocks, we have to literally remember the last
block, not the pointer, now it won't work e.g. if wanting to repeat an
empty block
- allow stopping car rotation in air like in Trackmania
- maybe allow some more air control, like slowing down with brakes, like in TM
- sound engine: probably all SFX will be procedurally generated, ok?

View file

@ -40,7 +40,8 @@ static const char *LCR_maps[] =
"#=f0s0 #f11d0"
"#=c0p0 #f11d0"
"#=C0s1 #fd190" // big dirt
"#>C0s0 #fd190" // big dirt
// "#=C0s1 #fd190" // big dirt
"#=M0s2 #fd190" // big grass
"#=W0s3 #fd190" // big ice

13
map.h
View file

@ -637,6 +637,11 @@ void _LCR_addBlockShapeByte(uint8_t *bytes, uint8_t *byteCount,
*byteCount += 1;
}
uint8_t LCR_mapBlockIsAccelerator(uint8_t block)
{
return block == LCR_BLOCK_FULL_ACCEL;
}
/**
Macro that transforms coordinates according to block transformation.
*/
@ -825,9 +830,9 @@ void LCR_mapGetBlockShape(uint8_t blockType, uint8_t transform,
break;
}
case LCR_BLOCK_CORNER_CONVEX:
case LCR_BLOCK_CORNER_CONCAVE:
{
case LCR_BLOCK_CORNER_CONVEX:
case LCR_BLOCK_CORNER_CONCAVE:
{
uint8_t
mx = blockType == LCR_BLOCK_CORNER_CONVEX ? 4 : 2,
mz = blockType == LCR_BLOCK_CORNER_CONVEX ? 2 : 4;
@ -845,7 +850,7 @@ case LCR_BLOCK_CORNER_CONCAVE:
ADD(0,0,0) ADD(0,0,6) ADD(mx,0,mz) // bottom
ADD(0,0,6) ADD(6,0,6) ADD(mx,0,mz)
break;
}
}
case LCR_BLOCK_BUMP:
ADD(3,0,0) ADD(6,0,3) ADD(3,1,3) // top

View file

@ -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);
}
}