feat: add limit fps setting feature and fix close window in settings
This commit is contained in:
@@ -5,6 +5,7 @@ window_width = 1280 ; in Pixel
|
|||||||
window_height = 720 ; in Pixel
|
window_height = 720 ; in Pixel
|
||||||
|
|
||||||
showFPS = 0 ; OFF = 0, ON = 1
|
showFPS = 0 ; OFF = 0, ON = 1
|
||||||
|
limitFPS = 1 ; OFF = 0, ON = 1
|
||||||
soundtrackOn = 1 ; OFF = 0, ON = 1
|
soundtrackOn = 1 ; OFF = 0, ON = 1
|
||||||
|
|
||||||
font_path = assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt
|
font_path = assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt
|
||||||
|
|||||||
+3
-2
@@ -118,8 +118,8 @@ typedef struct {
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Button showFPS;
|
Button showFPS;
|
||||||
|
Button limitFPS;
|
||||||
Button soundtrackOn;
|
Button soundtrackOn;
|
||||||
|
|
||||||
} MenuSettings;
|
} MenuSettings;
|
||||||
|
|
||||||
|
|
||||||
@@ -210,6 +210,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool showFPS;
|
bool showFPS;
|
||||||
|
bool limitFPS;
|
||||||
bool soundtrackOn;
|
bool soundtrackOn;
|
||||||
} Flags;
|
} Flags;
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ void RenderMenuMain(MenuMain *m, Font *font, const char *title, Flags *flags);
|
|||||||
void CleanupMenuMain(MenuMain *m);
|
void CleanupMenuMain(MenuMain *m);
|
||||||
|
|
||||||
void InitMenuSettings(MenuSettings *s);
|
void InitMenuSettings(MenuSettings *s);
|
||||||
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, Flags *flags);
|
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, State *state, Flags *flags);
|
||||||
void RenderMenuSettings(MenuSettings *s, Flags *flags);
|
void RenderMenuSettings(MenuSettings *s, Flags *flags);
|
||||||
void CleanupMenuSettings(MenuSettings *s);
|
void CleanupMenuSettings(MenuSettings *s);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ void ConfigApp(App* app){
|
|||||||
InitConfig(&app->config, "config/config.ini");
|
InitConfig(&app->config, "config/config.ini");
|
||||||
app->state.currentView = GetConfigInt(&app->config, "startView");
|
app->state.currentView = GetConfigInt(&app->config, "startView");
|
||||||
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
||||||
|
app->flags.limitFPS = GetConfigInt(&app->config, "limitFPS");
|
||||||
app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn");
|
app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn");
|
||||||
app->window.title = GetConfigString(&app->config, "window_title");
|
app->window.title = GetConfigString(&app->config, "window_title");
|
||||||
app->window.width = GetConfigInt(&app->config, "window_width");
|
app->window.width = GetConfigInt(&app->config, "window_width");
|
||||||
|
|||||||
+4
-1
@@ -56,8 +56,11 @@ void StartGame(App *app)
|
|||||||
void UpdateGame(App *app)
|
void UpdateGame(App *app)
|
||||||
{
|
{
|
||||||
GameState *g = &app->game;
|
GameState *g = &app->game;
|
||||||
|
if (app->flags.limitFPS){
|
||||||
|
SetTargetFPS(60);
|
||||||
|
} else {
|
||||||
SetTargetFPS(0);
|
SetTargetFPS(0);
|
||||||
|
}
|
||||||
|
|
||||||
StartGame(app);
|
StartGame(app);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ void UpdateMenu(MenuState *m, State *state, Flags *flags)
|
|||||||
|
|
||||||
case SETTINGS:
|
case SETTINGS:
|
||||||
{
|
{
|
||||||
UpdateMenuSettings(&m->menuSettings, &m->menuView, flags);
|
UpdateMenuSettings(&m->menuSettings, &m->menuView, state, flags);
|
||||||
}break;
|
}break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-5
@@ -10,19 +10,25 @@ void InitMenuSettings(MenuSettings *s)
|
|||||||
int standardSpacing = standardButtonDimensions.y / 2;
|
int standardSpacing = standardButtonDimensions.y / 2;
|
||||||
|
|
||||||
Vector2 button1Pos = {windowCenter.x, windowCenter.y};
|
Vector2 button1Pos = {windowCenter.x, windowCenter.y};
|
||||||
Vector2 button2Pos = {windowCenter.x, windowCenter.y + standardButtonDimensions.y + standardSpacing};
|
Vector2 button2Pos = {windowCenter.x, windowCenter.y + standardButtonDimensions.y * 1 + standardSpacing * 1};
|
||||||
|
Vector2 button3Pos = {windowCenter.x, windowCenter.y + standardButtonDimensions.y * 2 + standardSpacing * 2};
|
||||||
|
|
||||||
s->showFPS = initButton("showFPS", standardButtonDimensions, button1Pos);
|
s->showFPS = initButton("showFPS", standardButtonDimensions, button1Pos);
|
||||||
s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button2Pos);
|
s->limitFPS = initButton("limitFPS", standardButtonDimensions, button2Pos);
|
||||||
|
s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button3Pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView,Flags *flags)
|
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, State* state, Flags *flags)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(isButtonClicked(&s->showFPS)){
|
if(isButtonClicked(&s->showFPS)){
|
||||||
flags->showFPS = !flags->showFPS;
|
flags->showFPS = !flags->showFPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isButtonClicked(&s->limitFPS)){
|
||||||
|
flags->limitFPS = !flags->limitFPS;
|
||||||
|
}
|
||||||
|
|
||||||
if(isButtonClicked(&s->soundtrackOn)){
|
if(isButtonClicked(&s->soundtrackOn)){
|
||||||
flags->soundtrackOn = !flags->soundtrackOn;
|
flags->soundtrackOn = !flags->soundtrackOn;
|
||||||
}
|
}
|
||||||
@@ -31,6 +37,10 @@ void UpdateMenuSettings(MenuSettings *s, MenuView *menuView,Flags *flags)
|
|||||||
*menuView = MAIN;
|
*menuView = MAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)){
|
||||||
|
state->running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,13 +50,13 @@ void RenderMenuSettings(MenuSettings *s, Flags *flags)
|
|||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
renderButton(&s->showFPS);
|
renderButton(&s->showFPS);
|
||||||
|
renderButton(&s->limitFPS);
|
||||||
|
renderButton(&s->soundtrackOn);
|
||||||
|
|
||||||
if (flags->showFPS){
|
if (flags->showFPS){
|
||||||
DrawFPS(10,10);
|
DrawFPS(10,10);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderButton(&s->soundtrackOn);
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user