From d8ef183b5e6bd22cab2bf523588d8a9cf2014b8a Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 15 Nov 2015 16:18:17 +0000 Subject: [PATCH] Added ECM and boost abilities to player. --- src/battle/bullets.c | 6 ++++++ src/battle/fighters.h | 1 - src/battle/hud.c | 42 ++++++++++++++++++++++++++++++++++++++++-- src/battle/player.c | 38 ++++++++++++++++++++++++++++++++++++-- src/defs.h | 5 +++++ src/structs.h | 2 ++ 6 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/battle/bullets.c b/src/battle/bullets.c index ac39846..13f83bd 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -223,6 +223,12 @@ static void huntTarget(Bullet *b) faceTarget(b); applyMissileThrust(b); + + if (b->target == player && battle.ecmTimer == ECM_RECHARGE_TIME) + { + b->life = 0; + addMissileExplosion(b); + } } else { diff --git a/src/battle/fighters.h b/src/battle/fighters.h index 0c629c9..9344423 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern SDL_Texture *getTexture(char *filename); extern void doAI(void); -extern void doCivilianAI(void); extern void blitRotated(SDL_Texture *t, int x, int y, int angle); extern void blit(SDL_Texture *t, int x, int y, int center); extern float getAngle(int x1, int y1, int x2, int y2); diff --git a/src/battle/hud.c b/src/battle/hud.c index f5c253a..7e448d6 100644 --- a/src/battle/hud.c +++ b/src/battle/hud.c @@ -29,6 +29,8 @@ static void drawObjectives(void); static void drawDistancesInfo(void); static void drawHudMessages(void); static void drawPlayerSelect(void); +static void drawAbilityBars(void); +static void drawBoostECMBar(int x, int y, int r, int g, int b, int available); static HudMessage hudMessageHead; static HudMessage *hudMessageTail; @@ -124,6 +126,8 @@ void drawHud(void) { drawHealthBars(); + drawAbilityBars(); + drawPlayerTargeter(); drawWeaponInfo(); @@ -210,10 +214,44 @@ static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g } } +static void drawAbilityBars(void) +{ + drawBoostECMBar(10, 50, 128, 128, 255, battle.boostTimer == 0); + + drawBoostECMBar(160, 50, 255, 128, 0, battle.ecmTimer == 0); +} + +static void drawBoostECMBar(int x, int y, int r, int g, int b, int available) +{ + SDL_Rect rect; + + rect.x = x; + rect.y = y; + rect.w = 100; + rect.h = 12; + + SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); + SDL_RenderFillRect(app.renderer, &rect); + + SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); + SDL_RenderDrawRect(app.renderer, &rect); + + if (available) + { + rect.x += 2; + rect.y += 2; + rect.w -= 4; + rect.h -= 4; + + SDL_SetRenderDrawColor(app.renderer, r, g, b, 255); + SDL_RenderFillRect(app.renderer, &rect); + } +} + static void drawWeaponInfo(void) { - drawText(10, 50, 14, TA_LEFT, colors.white, gunName[player->selectedGunType]); - drawText(260, 50, 14, TA_RIGHT, colors.white, "Missiles (%d)", player->missiles.ammo); + drawText(10, 70, 14, TA_LEFT, colors.white, gunName[player->selectedGunType]); + drawText(260, 70, 14, TA_RIGHT, colors.white, "Missiles (%d)", player->missiles.ammo); } static void drawPlayerTargeter(void) diff --git a/src/battle/player.c b/src/battle/player.c index a736c8c..d71a991 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -25,6 +25,8 @@ static void switchGuns(void); static void selectMissionTarget(void); static void selectNewPlayer(int dir); static void initPlayerSelect(void); +static void activateBoost(void); +static void activateECM(void); static int selectedPlayerIndex; static int availableGuns[BT_MAX]; @@ -60,6 +62,14 @@ void initPlayer(void) void doPlayer(void) { + battle.boostTimer = MAX(battle.boostTimer - 1, 0); + battle.ecmTimer = MAX(battle.ecmTimer - 1, 0); + + if (battle.boostTimer == BOOST_FINISHED_TIME) + { + applyFighterThrust(); + } + if (player != NULL) { self = player; @@ -76,7 +86,7 @@ void doPlayer(void) player->angle += 4; } - if (app.keyboard[SDL_SCANCODE_UP]) + if (app.keyboard[SDL_SCANCODE_UP] && battle.boostTimer < BOOST_FINISHED_TIME) { applyFighterThrust(); } @@ -112,13 +122,23 @@ void doPlayer(void) app.keyboard[SDL_SCANCODE_RETURN] = 0; } - if (!player->target || player->target->health <= 0 || player->target->systemPower <= 0 || app.keyboard[SDLK_t]) + if (!player->target || player->target->health <= 0 || player->target->systemPower <= 0 || app.keyboard[SDL_SCANCODE_T]) { selectTarget(); app.keyboard[SDLK_t] = 0; } + if (app.keyboard[SDL_SCANCODE_SPACE] && !battle.boostTimer) + { + activateBoost(); + } + + if (app.keyboard[SDL_SCANCODE_E] && !battle.ecmTimer) + { + activateECM(); + } + if (!battle.missionTarget) { selectMissionTarget(); @@ -213,6 +233,20 @@ static void selectNewPlayer(int dir) battle.camera.y = player->y - (SCREEN_HEIGHT / 2); } +static void activateBoost(void) +{ + self->dx += sin(TO_RAIDANS(self->angle)) * 10; + self->dy += -cos(TO_RAIDANS(self->angle)) * 10; + self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); + + battle.boostTimer = BOOST_RECHARGE_TIME; +} + +static void activateECM(void) +{ + battle.ecmTimer = ECM_RECHARGE_TIME; +} + static void switchGuns(void) { int i; diff --git a/src/defs.h b/src/defs.h index e1fa3dd..3144e3b 100644 --- a/src/defs.h +++ b/src/defs.h @@ -74,6 +74,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define EF_HAS_ROPE (2 << 8) #define EF_ALWAYS_FLEES (2 << 9) +/* player abilities */ +#define BOOST_RECHARGE_TIME (FPS * 5) +#define BOOST_FINISHED_TIME (BOOST_RECHARGE_TIME - FPS * 0.5) +#define ECM_RECHARGE_TIME (FPS * 5) + enum { ET_FIGHTER, diff --git a/src/structs.h b/src/structs.h index f73cff2..05e54b7 100644 --- a/src/structs.h +++ b/src/structs.h @@ -241,6 +241,8 @@ typedef struct { int epicFighterLimit; int playerSelect; int missionFinishedTimer; + int boostTimer; + int ecmTimer; int numObjectivesComplete, numObjectivesTotal; Entity *missionTarget; Entity *extractionPoint;