From 3b3fe085fa07ad1c8d1eca6180ad7d5c7eebf8af Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Sun, 21 Aug 2022 23:49:36 +0100 Subject: [PATCH] Added effects reduction option for game speed up --- data/app/config.json | 2 + data/widgets/options.json | 14 ++++- src/battle/effects.c | 105 ++++++++++++++++++++++++++++++++++++++ src/defs.h | 3 +- src/game/options.c | 13 +++++ src/structs.h | 2 + src/system/init.c | 3 ++ 7 files changed, 140 insertions(+), 2 deletions(-) diff --git a/data/app/config.json b/data/app/config.json index 3f0ccb9..eefdd8c 100644 --- a/data/app/config.json +++ b/data/app/config.json @@ -1,6 +1,7 @@ { "winWidth" : 1280, "winHeight" : 720, + "effects" : 0, "fullscreen" : 0, "musicVolume" : 8, "soundVolume" : 10, @@ -41,3 +42,4 @@ "healthBars" : 1 } } + diff --git a/data/widgets/options.json b/data/widgets/options.json index ea431c4..ebca147 100644 --- a/data/widgets/options.json +++ b/data/widgets/options.json @@ -10,6 +10,17 @@ "w" : 400, "h": 34 }, + { + "name" : "effects", + "group" : "options", + "type" : "WT_SELECT", + "text" : "Effects Reduction", + "options" : "0;1;2", + "x" : -1, + "y" : 225, + "w" : 400, + "h": 34 + }, { "name" : "soundVolume", "group" : "options", @@ -17,7 +28,7 @@ "text" : "Sound Volume", "options" : "0;1;2;3;4;5;6;7;8;9;10", "x" : -1, - "y" : 250, + "y" : 275, "w" : 400, "h": 34 }, @@ -64,3 +75,4 @@ "h": 34 } ] + diff --git a/src/battle/effects.c b/src/battle/effects.c index ed7ff53..7d2c38f 100644 --- a/src/battle/effects.c +++ b/src/battle/effects.c @@ -203,6 +203,10 @@ void addBulletHitEffect(int x, int y, int r, int g, int b) e->type = EFFECT_TEXTURE; e->texture = explosionTexture; e->size = 16; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->x = x; e->y = y; @@ -216,6 +220,10 @@ void addBulletHitEffect(int x, int y, int r, int g, int b) e->b = b; e->a = 64; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } } } @@ -234,11 +242,19 @@ void addSmallFighterExplosion(void) e->y = self->y + (rand() % 16 - rand() % 16); e->texture = explosionTexture; e->size = 32; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } setRandomFlameHue(e); e->a = 128 + (rand() % 128); e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -259,11 +275,19 @@ void addDebrisFire(int x, int y) e->y = y + (rand() % 8 - rand() % 8); e->texture = explosionTexture; e->size = 4 + rand() % 12; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } setRandomFlameHue(e); e->a = rand() % 256; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -291,12 +315,20 @@ void addSmallExplosion(void) e->dy *= 0.025; e->texture = explosionTexture; e->size = 32 + (rand() % 64); + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->r = 255; setRandomFlameHue(e); e->a = 128 + (rand() % 128); e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -319,6 +351,10 @@ void addSmallExplosion(void) e->a = 128; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } setRandomFlameHue(e); } @@ -342,12 +378,20 @@ void addMineExplosion(void) e->y = self->y + rand() % 64 - rand() % 64; e->texture = explosionTexture; e->size = 64 + (rand() % 64); + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->r = 255; setRandomFlameHue(e); e->a = 32 + (rand() % 192); e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -363,6 +407,10 @@ void addMineExplosion(void) e->x = self->x; e->y = self->y; e->size = 64; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->scaleAmount = 6; e->texture = haloTexture; @@ -372,6 +420,10 @@ void addMineExplosion(void) e->a = 128; e->health = 128; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } } void addLargeExplosion(void) @@ -396,12 +448,20 @@ void addLargeExplosion(void) e->dy *= 0.01; e->texture = explosionTexture; e->size = 128 + (rand() % 512); + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->r = 255; setRandomFlameHue(e); e->a = 128 + (rand() % 128); e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -417,6 +477,10 @@ void addLargeExplosion(void) e->x = self->x; e->y = self->y; e->size = 256; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->scaleAmount = 4; e->texture = haloTexture; @@ -426,6 +490,10 @@ void addLargeExplosion(void) e->a = 255; e->health = 255; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } } void addMissileExplosion(Bullet *b) @@ -450,12 +518,20 @@ void addMissileExplosion(Bullet *b) e->dy *= 0.025; e->texture = explosionTexture; e->size = 32 + (rand() % 64); + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->r = 255; setRandomFlameHue(e); e->a = 128 + (rand() % 128); e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -478,6 +554,10 @@ void addMissileExplosion(Bullet *b) e->a = 128; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } setRandomFlameHue(e); } @@ -508,12 +588,20 @@ void addEngineEffect(void) e->texture = explosionTexture; e->size = 16; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->r = 128; e->g = 128; e->b = 255; e->a = 64; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -541,12 +629,20 @@ void addLargeEngineEffect(void) e->texture = explosionTexture; e->size = 64; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } e->r = 128; e->g = 128; e->b = 255; e->a = 64; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -574,10 +670,18 @@ void addMissileEngineEffect(Bullet *b) e->texture = explosionTexture; e->size = 12; + if (app.effects > 0) + { + e->size = e->size / (app.effects * 2); + } setRandomFlameHue(e); e->a = 128; e->health = e->a; + if (app.effects > 0) + { + e->health = e->health / (app.effects * 2); + } e->x -= e->size / 2; e->y -= e->size / 2; @@ -695,3 +799,4 @@ void destroyEffects(void) effectsToDraw = NULL; } + diff --git a/src/defs.h b/src/defs.h index 67de91b..c6f57df 100644 --- a/src/defs.h +++ b/src/defs.h @@ -80,7 +80,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define NUM_ATLAS_BUCKETS 64 #define NUM_GLYPH_BUCKETS 128 -#define MAX_STARS 500 +#define MAX_STARS 250 #define MAX_CHALLENGES 3 @@ -421,3 +421,4 @@ enum TROPHY_UNEARNED, TROPHY_MAX }; + diff --git a/src/game/options.c b/src/game/options.c index dddde72..8bba5d7 100644 --- a/src/game/options.c +++ b/src/game/options.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "options.h" static void changeWindowSize(char *value); +static void changeEffectsReduction(char *value); static void changeSoundVolume(char *value); static void changeMusicVolume(char *value); static void changeFullscreen(char *value); @@ -41,6 +42,7 @@ void initOptions(void (*rtn)(void)) selectWidget("windowSize", "options"); getWidget("windowSize", "options")->onChange = changeWindowSize; + getWidget("effects", "options")->onChange = changeEffectsReduction; getWidget("soundVolume", "options")->onChange = changeSoundVolume; getWidget("musicVolume", "options")->onChange = changeMusicVolume; getWidget("fullscreen", "options")->onChange = changeFullscreen; @@ -51,6 +53,9 @@ void initOptions(void (*rtn)(void)) sprintf(optionStr, "%d x %d", app.winWidth, app.winHeight); setWidgetOption("windowSize", "options", optionStr); + sprintf(optionStr, "%d", app.effects); + setWidgetOption("effects", "options", optionStr); + sprintf(optionStr, "%d", app.soundVolume); setWidgetOption("soundVolume", "options", optionStr); @@ -172,6 +177,13 @@ static void changeWindowSize(char *value) initStars(); } +static void changeEffectsReduction(char *value) +{ + app.effects = atoi(value); + + // Mix_Volume(-1, app.effects * MIX_MAX_VOLUME / 10); +} + static void changeSoundVolume(char *value) { app.soundVolume = atoi(value); @@ -204,3 +216,4 @@ static void controlsOK(void) { show = SHOW_MAIN; } + diff --git a/src/structs.h b/src/structs.h index 2c25b5f..63b4e3e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -521,6 +521,7 @@ typedef struct { int keyControls[CONTROL_MAX]; int mouseControls[CONTROL_MAX]; int textWidth; + int effects; } App; typedef struct { @@ -576,3 +577,4 @@ typedef struct { typedef struct { int32_t length, offset; } MOEntry; + diff --git a/src/system/init.c b/src/system/init.c index 19d62f5..4cee340 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -229,6 +229,7 @@ static void loadConfigFile(char *filename) app.winWidth = cJSON_GetObjectItem(root, "winWidth")->valueint; app.winHeight = cJSON_GetObjectItem(root, "winHeight")->valueint; + app.effects = cJSON_GetObjectItem(root, "effects")->valueint; app.fullscreen = cJSON_GetObjectItem(root, "fullscreen")->valueint; app.musicVolume = cJSON_GetObjectItem(root, "musicVolume")->valueint; app.soundVolume = cJSON_GetObjectItem(root, "soundVolume")->valueint; @@ -284,6 +285,7 @@ void saveConfig(void) root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "winWidth", app.winWidth); cJSON_AddNumberToObject(root, "winHeight", app.winHeight); + cJSON_AddNumberToObject(root, "effects", app.effects); cJSON_AddNumberToObject(root, "fullscreen", app.fullscreen); cJSON_AddNumberToObject(root, "musicVolume", app.musicVolume); cJSON_AddNumberToObject(root, "soundVolume", app.soundVolume); @@ -383,3 +385,4 @@ void cleanup(void) SDL_Quit(); } +