Start fans

This commit is contained in:
Miloslav Ciz 2024-12-15 22:09:22 +01:00
parent 6260ef1fcc
commit 9fc88a91af
3 changed files with 29 additions and 6 deletions

View file

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

5
map.h
View file

@ -642,6 +642,11 @@ uint8_t LCR_mapBlockIsAccelerator(uint8_t block)
return block == LCR_BLOCK_FULL_ACCEL;
}
uint8_t LCR_mapBlockIsFan(uint8_t block)
{
return block == LCR_BLOCK_FULL_FAN;
}
/**
Macro that transforms coordinates according to block transformation.
*/

View file

@ -30,6 +30,8 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
// TODO: move some of this to constants?
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 160)
#define LCR_FAN_FORCE 3
#define LCR_FAN_FORCE_DECREASE 6
#define LCR_CAR_FORWARD_FRICTION (TPE_F / 180)
#define LCR_CAR_AIR_FRICTION 32
@ -71,6 +73,7 @@ struct
TPE_Vec3 carOKPositions[LCR_CAR_JOINTS];
uint8_t carNotOKCount;
TPE_Unit fanForce; ///* Upwards acceleration caused by a fan.
LCR_GameUnit wheelRotation;
LCR_GameUnit wheelSteer;
@ -514,6 +517,7 @@ void LCR_racingRestart(void)
LCR_LOG0("restarting race");
LCR_racing.tick = 0;
LCR_racing.fanForce = 0;
TPE_bodyActivate(&(LCR_racing.carBody));
LCR_racing.wheelCollisions = 0;
@ -786,8 +790,13 @@ uint32_t LCR_racingStep(unsigned int input)
if (groundBlockIndex != -1)
{
onAccel = LCR_mapBlockIsAccelerator(
LCR_currentMap.blocks[groundBlockIndex * LCR_BLOCK_SIZE]);
uint8_t b = LCR_currentMap.blocks[groundBlockIndex * LCR_BLOCK_SIZE];
onAccel = LCR_mapBlockIsAccelerator(b);
if (LCR_mapBlockIsFan(b))
LCR_racing.fanForce = LCR_GRAVITY * LCR_FAN_FORCE;
groundMat = LCR_mapBlockGetMaterial(
LCR_currentMap.blocks + groundBlockIndex * LCR_BLOCK_SIZE);
}
@ -947,12 +956,21 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.wheelCollisions <<= 4;
if (LCR_racing.fanForce)
{
TPE_bodyAccelerate(&(LCR_racing.carBody),TPE_vec3(0,LCR_racing.fanForce,0));
LCR_racing.fanForce -= LCR_GRAVITY / LCR_FAN_FORCE_DECREASE;
if (LCR_racing.fanForce < 0)
LCR_racing.fanForce = 0;
}
LCR_LOG2("gonna step physics engine");
TPE_worldStep(&(LCR_racing.physicsWorld));
LCR_LOG2("stepping physics engine done");
LCR_racing.carSpeed = (TPE_vec3Len(carVel) * LCR_GAME_UNIT)
/ LCR_PHYSICS_UNIT;