diff --git a/assets.h b/assets.h index 072cb03..5511e7e 100644 --- a/assets.h +++ b/assets.h @@ -126,8 +126,18 @@ uint16_t LCR_getFontChar(char c) case 'X': case 'x': _F(12,15, 3, 4, 6, 9, 9, 9, 9, 9) case 'Y': case 'y': _F(12, 6, 9, 7, 8, 8, 8, 8, 8, 8) case ':': _F( 4, 8, 8, 8, 8, 8, 8, 8, 8, 8) + case '!': _F( 1, 8, 8, 8, 8, 8, 8, 8, 8, 8) + case '?': _F( 0, 2, 9, 6, 7, 7, 7, 7, 7, 7) + case ';': _F( 0, 7, 7, 7, 7, 7, 7, 7, 7, 7) case '.': _F( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8) case ',': _F( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7) + case '-': _F( 4, 6, 6, 6, 6, 6, 6, 6, 6, 6) + case '\'': _F( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5) + case '"': _F( 1, 5, 5, 5, 5, 5, 5, 5, 5, 5) + case '+': _F( 4, 6, 5, 7, 7, 7, 7, 7, 7, 7) + case '_': _F( 8,10,10,10,10,10,10,10,10,10) + case '|': _F( 5, 7, 7, 7, 7, 7, 7, 7, 7, 7) + case '=': _F( 4, 6, 0, 2, 2, 2, 2, 2, 2, 2) default: return 0; break; } diff --git a/game.h b/game.h index 6d5ca53..791a185 100644 --- a/game.h +++ b/game.h @@ -179,6 +179,13 @@ void LCR_gameSetState(uint8_t state) LCR_game.stateStartTime = LCR_game.time; } +LCR_GameUnit LCR_carSpeedKMH(void) +{ + return // we use 28/8 as an approximation of 3.6 to convers MPS to KMH + (28 * LCR_SETTING_METERS_PER_BLOCK * LCR_racingGetCarSpeedUnsigned() * + LCR_RACING_FPS) / (8 * LCR_GAME_UNIT); +} + void LCR_gameResetRun(void) { LCR_LOG0("resetting run"); @@ -233,14 +240,6 @@ uint8_t LCR_gameStep(uint32_t time) LCR_keyStates[i] = LCR_keyPressed(i) ? (LCR_keyStates[i] < 255 ? LCR_keyStates[i] + 1 : 255) : 0; -//S3L_logTransform3D(LCR_renderer.scene.camera.transform); - -if ((LCR_racing.tick % 32) == 0) -{ - printf("speed: %d\n",LCR_racingGetCarSpeedSigned()); - -} - uint32_t sleep = 0; if (LCR_keyStates[LCR_KEY_B] == 1) @@ -365,7 +364,34 @@ LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT - LCR_rendererDraw(); -LCR_rendererDrawText("abcdefghijklmnopqrstuvwxyz",10,20,0,2); + int val = LCR_carSpeedKMH(); + + if (val < 5) // don't show tiny oscillations when still + val = 0; + + char str[6]; + + str[0] = val >= 100 ? '0' + (val / 100) % 10 : ' '; + str[1] = val >= 10 ? '0' + (val / 10) % 10 : ' '; + str[2] = '0' + val % 10; + str[3] = 0; + + LCR_rendererDrawText(str, + LCR_EFFECTIVE_RESOLUTION_X - + LCR_rendererComputeTextWidth(str,2) - 20, + LCR_EFFECTIVE_RESOLUTION_Y - + LCR_rendererComputeTextHeight(2) - 20,0,2); + +str[0] = '1'; // TODO +str[1] = '2'; +str[2] = '\''; +str[3] = '3'; +str[4] = '4'; +str[5] = 0; + + LCR_rendererDrawText(str,20, + LCR_EFFECTIVE_RESOLUTION_Y - + LCR_rendererComputeTextHeight(2) - 20,0,2); if (LCR_game.debugDraw) { diff --git a/racing.h b/racing.h index 5960e50..170172e 100644 --- a/racing.h +++ b/racing.h @@ -80,10 +80,13 @@ struct - LCR_GameUnit carSpeed; ///* Signed speed (negative if backwards) + LCR_GameUnit carSpeed; /**< Signed speed in game units per tick (negative + if backwards) */ } LCR_racing; + + TPE_Vec3 _LCR_TPE_vec3DividePlain(TPE_Vec3 v, TPE_Unit d) { v.x /= d; v.y /= d; v.z /= d; @@ -974,7 +977,6 @@ uint32_t LCR_racingStep(unsigned int input) LCR_racing.carSpeed = (TPE_vec3Len(carVel) * LCR_GAME_UNIT) / LCR_PHYSICS_UNIT; - if (TPE_vec3Dot(carVel,carForw) < 0) LCR_racing.carSpeed *= -1; diff --git a/renderer.h b/renderer.h index 586ba41..d8d05ba 100644 --- a/renderer.h +++ b/renderer.h @@ -31,7 +31,7 @@ #define LCR_RENDERER_MODEL_COUNT 10 #define LCR_RENDERER_CAR_SCALE (LCR_RENDERER_UNIT / 4) -#define LCR_RENDERER_FONT_SEGMENT_SIZE 4 +#define LCR_RENDERER_FONT_SEGMENT_SIZE (2 + LCR_EFFECTIVE_RESOLUTION_X / 512) /** For some reason the map model is a bit misaligned with physics world, this kinda hotfixes it -- later try to discover source of this bug. TODO */ @@ -128,6 +128,28 @@ void _LCR_rendererDrawFontPixel(int x, int y, uint16_t color) #endif } +int LCR_rendererComputeTextWidth(const char *text, int size) +{ + int r = 0; + size *= LCR_RENDERER_FONT_SEGMENT_SIZE; + + while (*text) + { + text++; + r += 2 * size; + + if (text[1]) + r += 3 * size / 4; + } + + return r + LCR_FONT_PIXEL_SIZE - 1; +} + +int LCR_rendererComputeTextHeight(int size) +{ + return 2 * size * LCR_RENDERER_FONT_SEGMENT_SIZE + LCR_FONT_PIXEL_SIZE - 1; +} + void LCR_rendererDrawText(const char *text, int x, int y, uint16_t color, int size) { diff --git a/settings.h b/settings.h index 5ea3b76..cc1d6cd 100644 --- a/settings.h +++ b/settings.h @@ -153,4 +153,10 @@ #define LCR_SETTING_LOG_LEVEL 1 #endif +#ifndef LCR_SETTING_METERS_PER_BLOCK + /** How many meters one game block is considered to measure (horizontally). + This is for calculating speed etc. */ + #define LCR_SETTING_METERS_PER_BLOCK 4 +#endif + #endif // guard