Adjust GUI to different resolutions

This commit is contained in:
Miloslav Ciz 2025-03-07 16:18:25 +01:00
parent 9b2fc5f14c
commit 50ceea3f0a
4 changed files with 64 additions and 41 deletions

View file

@ -1,5 +1,7 @@
=========== GENERAL ============== =========== GENERAL ==============
- on tiny map 1 maybe add a few block below the first sharp ramp to prevent
those nasty piercing bugs
- car deglitch idea: deglitch only if the middle joint collided this frame? - car deglitch idea: deglitch only if the middle joint collided this frame?
- some kinda easteregg in menu or smt - some kinda easteregg in menu or smt
- make the U-ramp map taller due to new physics - make the U-ramp map taller due to new physics
@ -21,6 +23,7 @@
count count
- bonus maps in the external file (also 5?) - bonus maps in the external file (also 5?)
- map types: - map types:
- purely falling map
- traveling salesman kind of maze, with fans n shit - traveling salesman kind of maze, with fans n shit
- city map? - city map?
- some kinda buggy bumpy downhill - some kinda buggy bumpy downhill

38
game.h
View file

@ -264,6 +264,11 @@ static inline void LCR_gameDrawPixelXYSafe(unsigned int x, unsigned int y,
#define LCR_POPUP_STR_SIZE 16 #define LCR_POPUP_STR_SIZE 16
#define LCR_GUI_GAP \
((LCR_EFFECTIVE_RESOLUTION_X + LCR_EFFECTIVE_RESOLUTION_Y) / 128)
struct struct
{ {
uint8_t state; uint8_t state;
@ -1056,22 +1061,20 @@ void LCR_gameTimeToStr(uint32_t timeMS, char *str)
void LCR_gameDrawPopupMessage(void) void LCR_gameDrawPopupMessage(void)
{ {
#define TEXT_SIZE 5 #define _TEXT_SIZE 5
#define OFFSET_V (LCR_EFFECTIVE_RESOLUTION_Y / 6) #define _OFFSET_V (LCR_EFFECTIVE_RESOLUTION_Y / 6)
#define TEXT_PAD (LCR_EFFECTIVE_RESOLUTION_Y / 64)
int textH = LCR_rendererComputeTextHeight(TEXT_SIZE); int textH = LCR_rendererComputeTextHeight(_TEXT_SIZE);
int textW = LCR_rendererComputeTextWidth(LCR_game.popupStr,TEXT_SIZE); int textW = LCR_rendererComputeTextWidth(LCR_game.popupStr,_TEXT_SIZE);
LCR_rendererDrawRect((LCR_EFFECTIVE_RESOLUTION_X - textW - 2 * TEXT_PAD) / 2, LCR_rendererDrawRect((LCR_EFFECTIVE_RESOLUTION_X - textW - 2 * LCR_GUI_GAP)
OFFSET_V,textW + 2 * TEXT_PAD,textH + 2 * TEXT_PAD,0xffff,1); / 2,_OFFSET_V,textW + 2 * LCR_GUI_GAP,textH + 2 * LCR_GUI_GAP,0xffff,1);
LCR_rendererDrawText(LCR_game.popupStr,(LCR_EFFECTIVE_RESOLUTION_X - textW) LCR_rendererDrawText(LCR_game.popupStr,(LCR_EFFECTIVE_RESOLUTION_X - textW)
/ 2,OFFSET_V + TEXT_PAD,0x0300,TEXT_SIZE); / 2,_OFFSET_V + LCR_GUI_GAP,0x0300,_TEXT_SIZE);
#undef TEXT_PAD #undef _OFFSET_V
#undef OFFSET_V #undef _TEXT_SIZE
#undef TEXT_SIZE
} }
void LCR_gameDraw3DView(void) void LCR_gameDraw3DView(void)
@ -1134,14 +1137,15 @@ void LCR_gameDraw3DView(void)
str[3] = 0; str[3] = 0;
LCR_rendererDrawText(str,LCR_EFFECTIVE_RESOLUTION_X - LCR_rendererDrawText(str,LCR_EFFECTIVE_RESOLUTION_X -
LCR_rendererComputeTextWidth(str,2) - 20, LCR_rendererComputeTextWidth(str,2) - LCR_GUI_GAP,
LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) - 20,0,2); LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) -
LCR_GUI_GAP,0,2);
LCR_gameTimeToStr(LCR_timeTicksToMS(LCR_game.runTime),str); LCR_gameTimeToStr(LCR_timeTicksToMS(LCR_game.runTime),str);
if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED)
LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererDrawText(str,LCR_GUI_GAP,LCR_EFFECTIVE_RESOLUTION_Y -
LCR_rendererComputeTextHeight(2) - 45,0,2); LCR_rendererComputeTextHeight(2) - 3 * LCR_GUI_GAP,0,2);
else else
LCR_rendererDrawText(str,((LCR_EFFECTIVE_RESOLUTION_X - LCR_rendererDrawText(str,((LCR_EFFECTIVE_RESOLUTION_X -
LCR_rendererComputeTextWidth(str,4)) / 2), LCR_rendererComputeTextWidth(str,4)) / 2),
@ -1151,8 +1155,8 @@ void LCR_gameDraw3DView(void)
LCR_gameTimeToStr(LCR_currentMap.targetTime * LCR_RACING_TICK_MS,str); LCR_gameTimeToStr(LCR_currentMap.targetTime * LCR_RACING_TICK_MS,str);
LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererDrawText(str,LCR_GUI_GAP,LCR_EFFECTIVE_RESOLUTION_Y -
LCR_rendererComputeTextHeight(2) - 20,0x4208,2); LCR_rendererComputeTextHeight(2) - LCR_GUI_GAP,0x4208,2);
break; break;
} }

View file

@ -7,13 +7,14 @@ by drummyfish, released under CC0 1.0, public domain
~~~ GENERAL ~~~ ~~~ GENERAL ~~~
Licar is a relatively simple 3D stunt racing game inspired by other popular Licar is a relatively simple 3D stunt racing game inspired by other popular
games of this genre. Unlike most games in existence, Licar is completely free games of this genre. Unlike most games in existence, Licar is completely libre,
as in freedom (meaning its source code is available for any use), gratis, and free as in freedom (meaning its source code is available for any use whatsoever),
its focus lies on being well programmed by employing minimalism and rejecting gratis (free of cost), and its focus lies on being well programmed by employing
harmful "modern" programming practice. The game aims to seflessly bring minimalism and rejecting harmful "modern" programming practice. The game aims to
happiness to all people, even those who have no money, own only very old and seflessly bring happiness to all people who might enjoy it, even those who have
weak computers etc. It is not a commercial product and has been made purely out no money, own only very old and weak computers etc. It is not a commercial
of love by a single man. product and has been made purely out of love by a single man. It is also more
than a game, for example it can be used for educational purposes.
The game runs on many platforms and comes in different versions depending on The game runs on many platforms and comes in different versions depending on
what the platforms allow. Some versions may have more features or visual what the platforms allow. Some versions may have more features or visual
@ -71,7 +72,7 @@ speed, times at checkpoints etc.
Controls are extremely simple. The car is only controlled by 4 directional Controls are extremely simple. The car is only controlled by 4 directional
keys: up (accelerate), down (deccelerate, reverse), left (steer left) and keys: up (accelerate), down (deccelerate, reverse), left (steer left) and
right (steer right). There are two additional keys, A and B (depending on your right (steer right). There are two additional keys, A and B (depending on your
platform these may be e.g. the K and L letter or RETURN and SPACE keys), for platform these may be e.g. the K and L letter or RETURN and ESCAPE keys), for
restarting runs and handling menu. restarting runs and handling menu.
PRO TIP: pressing brake while in air stops the car's horizontal rotation! PRO TIP: pressing brake while in air stops the car's horizontal rotation!
@ -96,15 +97,16 @@ replay data. For example a map named "mymap" will start with "Mmymap;".
~~~ CONFIGURATION ~~~ ~~~ CONFIGURATION ~~~
The game offers a very high level of configuration and customization. Very basic The game offers a very high level of configuration and customization, and those
settings (such as turning the music off or switching between windowed and with at least basic programming skill will be able to implement any changes
fullscreen mode) are accessible either in the game menu, or as a commandline imaginable. Very basic settings (such as turning the music off or switching
flag (run the game with -h flag to see the options). All other settings, between windowed and fullscreen mode) are accessible either in the game menu,
however, are kept at the source code level and so changing them requires or as a commandline flag (run the game with -h flag to see the options). All
recompiling the whole game from source code (which is nonetheless very simple). other settings, however, are kept at the source code level and so changing them
All user settings, along with their descriptions, are located in the settings.h requires recompiling the whole game from source code (which is nonetheless very
source file. The game also comes in several precompiled versions with different simple). All user settings, along with their descriptions, are located in the
settings. settings.h source file. The game also comes in several precompiled versions with
different settings.
~~~ REPLAYS ~~~ ~~~ REPLAYS ~~~
@ -141,7 +143,7 @@ and/or flipped. Additionally each block also has a material (concrete, grass,
...). The finish, checkpoints and car start position can also be seen as block. ...). The finish, checkpoints and car start position can also be seen as block.
The format of the map data string is described in the map.h file, refer to it The format of the map data string is described in the map.h file, refer to it
for details. In short: TODO for details. In short: TODO (also small example)
Under the asset directory there is a helper file for Blender (a FOSS 3D editor) Under the asset directory there is a helper file for Blender (a FOSS 3D editor)
with which a map layout can be comfortably created. But Blender is not required with which a map layout can be comfortably created. But Blender is not required
@ -150,12 +152,12 @@ or -- for simpler maps -- it may be possible to just imagine them in one's head.
The "workflow" for making maps is roughly the following: The "workflow" for making maps is roughly the following:
1. Drawing the map (in Blender, on paper, ...). 1. Drawing the map (in Blender, on paper, with Lego, ...).
2. Rewriting this to the map text format in the data file. The edited map should 2. Rewriting this to the map text format in the data file. The edited map should
be the very last item in the data file so that it can be quickly loaded with be the very last item in the data file so that it can be quickly loaded with
the -M command line argument. the -M command line argument.
3. Testing the map in game. This is easily done by running the game with -M 3. Testing the map in game. This is easily done by running the game with -M
argument (and possibly also other arguments, e.g. to start with free camera) argument (and possibly also other ones, e.g. -c3 to start with free camera)
to instantly load the edited map. If something needs changing, we return to to instantly load the edited map. If something needs changing, we return to
1. or 2. 1. or 2.
@ -170,3 +172,10 @@ most difficult tasks to create a flawless physics engine. We apologize for any
frustration but unless you want to fix this yourself, you'll have to just accept frustration but unless you want to fix this yourself, you'll have to just accept
it, the game is meant to be a simple entertainment. In other words this is a it, the game is meant to be a simple entertainment. In other words this is a
feature :) feature :)
Q: I have some other question.
A: My email is currently drummyfish@disroot.org, feel free to ask me anything,
but please remember I am not very social and don't enjoy too much engaging in
smalltalk or lengthy discussions about worldviews etcetc.

View file

@ -1871,20 +1871,27 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items,
s2++; s2++;
} }
#define _MENU_ITEM_HEIGHT (LCR_EFFECTIVE_RESOLUTION_Y / 20)
#define _FONT_SIZE (2 + LCR_EFFECTIVE_RESOLUTION_Y / 512)
if (j == selectedItem + 1) if (j == selectedItem + 1)
for (int y = i - 10; y < i + LCR_rendererComputeTextHeight(3) + 10; ++y) for (int y = i - 7; y < i + LCR_rendererComputeTextHeight(_FONT_SIZE) + 7;
++y)
for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4; for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4;
x < LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4; ++x) x < LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4; ++x)
LCR_gameDrawPixelXYSafe(x,y,0x5c1b + 4 * ((x & 0x10) == (y & 0x10))); LCR_gameDrawPixelXYSafe(x,y,0x5c1b + 4 * ((x & 0x10) == (y & 0x10)));
LCR_rendererDrawText(s,(LCR_EFFECTIVE_RESOLUTION_X - LCR_rendererDrawText(s,(LCR_EFFECTIVE_RESOLUTION_X -
LCR_rendererComputeTextWidth(s,3)) / 2,i, LCR_rendererComputeTextWidth(s,_FONT_SIZE)) / 2,i,
(j == 0 || j == selectedItem + 1) ? 0xf79c : textColor,3); (j == 0 || j == selectedItem + 1) ? 0xf79c : textColor,_FONT_SIZE);
if (j == 0) if (j == 0)
i = stripHeight + stripHeight2; i = stripHeight + stripHeight2;
i += LCR_rendererComputeTextHeight(5); i += _MENU_ITEM_HEIGHT;
#undef _FONT_SIZE
#undef _MENU_ITEM_HEIGHT
} }
#if !LCR_SETTING_POTATO_GRAPHICS #if !LCR_SETTING_POTATO_GRAPHICS