From 048d3b17e0d5db80bf3abfa6edee3495684da4d3 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 22 Nov 2015 16:51:11 +0000 Subject: [PATCH] Shield hit effect optimisation. --- src/battle/effects.c | 7 +++++++ src/battle/effects.h | 1 + src/battle/fighters.c | 10 +++------- src/battle/fighters.h | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/battle/effects.c b/src/battle/effects.c index 5fd5c8c..464a83a 100644 --- a/src/battle/effects.c +++ b/src/battle/effects.c @@ -95,6 +95,13 @@ void drawEffects(void) SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); } +void drawShieldHitEffect(Entity *e) +{ + SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND); + SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit); + blit(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.y, 1); +} + void addSmallFighterExplosion(void) { Effect *e; diff --git a/src/battle/effects.h b/src/battle/effects.h index 1e908d7..3f22f17 100644 --- a/src/battle/effects.h +++ b/src/battle/effects.h @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h); extern SDL_Texture *getTexture(char *name); +extern void blit(SDL_Texture *t, int x, int y, int center); extern App app; extern Battle battle; diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 1a1b9bc..17963e1 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -359,8 +359,6 @@ static void separate(void) void drawFighter(Entity *e) { - SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png"); - SDL_SetTextureColorMod(e->texture, 255, 255, 255); if (e->armourHit > 0) @@ -377,9 +375,7 @@ void drawFighter(Entity *e) if (e->shieldHit > 0) { - SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND); - SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit); - blit(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.y, 1); + drawShieldHitEffect(e); } } @@ -628,8 +624,8 @@ static void loadFighterDef(char *filename) STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); STRNCPY(f->defName, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); - f->health = f->maxHealth = cJSON_GetObjectItem(root, "health")->valueint; - f->shield = f->maxShield = cJSON_GetObjectItem(root, "shield")->valueint; + f->health = f->maxHealth = cJSON_GetObjectItem(root, "health")->valueint * 2; + f->shield = f->maxShield = cJSON_GetObjectItem(root, "shield")->valueint * 2; f->speed = cJSON_GetObjectItem(root, "speed")->valuedouble; f->reloadTime = cJSON_GetObjectItem(root, "reloadTime")->valueint; f->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint; diff --git a/src/battle/fighters.h b/src/battle/fighters.h index c53fd65..58cc1a7 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -48,6 +48,7 @@ extern long lookup(char *name); extern long flagsToLong(char *flags); extern void addShieldSplinterEffect(Entity *ent); extern void completeMission(void); +extern void drawShieldHitEffect(Entity *e); extern App app; extern Battle battle;