Do some tuning
This commit is contained in:
parent
4754b33dfe
commit
b6d28c2886
4 changed files with 70 additions and 16 deletions
37
racing.h
37
racing.h
|
@ -14,7 +14,7 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
|
|||
#define LCR_RACING_INPUT_BACK 0x04
|
||||
#define LCR_RACING_INPUT_LEFT 0x08
|
||||
|
||||
#define LCR_PHYSICS_UNIT 1024 ///< length of map square for physics engine
|
||||
#define LCR_PHYSICS_UNIT 2048 ///< length of map square for physics engine
|
||||
|
||||
#include "map.h"
|
||||
#include "tinyphysicsengine.h"
|
||||
|
@ -23,12 +23,22 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
|
|||
#define LCR_CAR_CONNECTIONS 10
|
||||
|
||||
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 100)
|
||||
#define LCR_CAR_FORWARD_FRICTION TPE_F / 14
|
||||
#define LCR_CAR_FORWARD_FRICTION (TPE_F / 11)
|
||||
#define LCR_CAR_TURN_FRICTION (4 * TPE_F / 4)
|
||||
#define LCR_CAR_ELASTICITY (TPE_F / 100)
|
||||
#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 15)
|
||||
#define LCR_CAR_TURN_SPEED (LCR_GAME_UNIT / 16)
|
||||
#define LCR_CAR_TURN_MAX (LCR_GAME_UNIT / 4)
|
||||
|
||||
/*
|
||||
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 100)
|
||||
#define LCR_CAR_FORWARD_FRICTION (TPE_F / 14)
|
||||
#define LCR_CAR_TURN_FRICTION (3 * TPE_F / 4)
|
||||
#define LCR_CAR_ELASTICITY (TPE_F / 100)
|
||||
#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 20)
|
||||
#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 18)
|
||||
#define LCR_CAR_TURN_SPEED (LCR_GAME_UNIT / 3)
|
||||
#define LCR_CAR_TURN_MAX (LCR_GAME_UNIT / 4)
|
||||
*/
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -36,6 +46,7 @@ struct
|
|||
TPE_Body carBody;
|
||||
TPE_Joint carJoints[LCR_CAR_JOINTS];
|
||||
TPE_Connection carConnections[LCR_CAR_CONNECTIONS];
|
||||
uint32_t tick;
|
||||
uint8_t wheelCollisions; /**< In individual bits records for each car wheel
|
||||
whether it's currently touching the ground.
|
||||
Lower bits record current collisions, higher
|
||||
|
@ -89,6 +100,8 @@ uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2,
|
|||
*/
|
||||
void LCR_racingRestart(void)
|
||||
{
|
||||
LCR_racing.tick = 0;
|
||||
|
||||
TPE_bodyActivate(&(LCR_racing.carBody));
|
||||
LCR_racing.wheelCollisions = 0;
|
||||
|
||||
|
@ -233,28 +246,32 @@ void LCR_racingStep(unsigned int input)
|
|||
|
||||
if (input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK))
|
||||
{
|
||||
// TODO: in air always rotate wheels
|
||||
LCR_GameUnit rotateBy =
|
||||
(LCR_racing.wheelCollisions & 0x0f) ? // on ground slow down wheel rot.
|
||||
(LCR_racingGetCarSpeed() / 16) : LCR_GAME_UNIT / 32;
|
||||
|
||||
LCR_racing.wheelRotation = LCR_racing.wheelRotation +
|
||||
(LCR_racingGetCarSpeed() / 32)
|
||||
% LCR_GAME_UNIT;
|
||||
if (!(input & LCR_RACING_INPUT_BACK))
|
||||
rotateBy *= -1;
|
||||
|
||||
LCR_racing.wheelRotation =
|
||||
(LCR_racing.wheelRotation + rotateBy) % LCR_GAME_UNIT;
|
||||
|
||||
if (LCR_racing.wheelRotation < 0)
|
||||
LCR_racing.wheelRotation += LCR_GAME_UNIT;
|
||||
|
||||
}
|
||||
|
||||
if (input & LCR_RACING_INPUT_RIGHT)
|
||||
{
|
||||
steering = 2;
|
||||
|
||||
LCR_racing.wheelSteer = TPE_min(
|
||||
LCR_racing.wheelSteer + LCR_CAR_TURN_SPEED,
|
||||
LCR_CAR_TURN_MAX);
|
||||
}
|
||||
|
||||
else if (input & LCR_RACING_INPUT_LEFT)
|
||||
{
|
||||
steering = 1;
|
||||
|
||||
LCR_racing.wheelSteer = TPE_max(
|
||||
LCR_racing.wheelSteer - LCR_CAR_TURN_SPEED,
|
||||
-1 * LCR_CAR_TURN_MAX);
|
||||
|
@ -350,6 +367,8 @@ LCR_racing.carPositions[0] =
|
|||
);
|
||||
|
||||
LCR_racing.carPositions[1] = tmpVec;
|
||||
|
||||
LCR_racing.tick++;
|
||||
}
|
||||
|
||||
void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue