From 9fc88a91af0dfc3f3e2b9b3c1f16bc507d61f087 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Sun, 15 Dec 2024 22:09:22 +0100 Subject: [PATCH] Start fans --- assets.h | 2 +- map.h | 5 +++++ racing.h | 28 +++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/assets.h b/assets.h index 17e9fe7..f56a5a0 100644 --- a/assets.h +++ b/assets.h @@ -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 diff --git a/map.h b/map.h index f9389fe..29abb06 100644 --- a/map.h +++ b/map.h @@ -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. */ diff --git a/racing.h b/racing.h index ef8bafe..5960e50 100644 --- a/racing.h +++ b/racing.h @@ -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); } @@ -946,13 +955,22 @@ uint32_t LCR_racingStep(unsigned int input) LCR_racing.wheelSteer /= 2; 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;