Various boost tweaks.

This commit is contained in:
Steve 2015-11-15 17:12:04 +00:00
parent f62861cfba
commit 6dfe2b7f22
5 changed files with 38 additions and 24 deletions

View File

@ -355,11 +355,12 @@ void applyFighterThrust(void)
self->dy += -cos(TO_RAIDANS(self->angle)) * 0.1; self->dy += -cos(TO_RAIDANS(self->angle)) * 0.1;
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
if (self->thrust > self->speed * self->speed) while (self->thrust > self->speed * self->speed)
{ {
v = (self->speed / sqrt(self->thrust)); v = (self->speed / sqrt(self->thrust));
self->dx = v * self->dx; self->dx = v * self->dx;
self->dy = v * self->dy; self->dy = v * self->dy;
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
} }
} }

View File

@ -30,7 +30,7 @@ static void drawDistancesInfo(void);
static void drawHudMessages(void); static void drawHudMessages(void);
static void drawPlayerSelect(void); static void drawPlayerSelect(void);
static void drawAbilityBars(void); static void drawAbilityBars(void);
static void drawBoostECMBar(int x, int y, int r, int g, int b, int available); static void drawBoostECMBar(int current, int max, int x, int y, int r, int g, int b);
static HudMessage hudMessageHead; static HudMessage hudMessageHead;
static HudMessage *hudMessageTail; static HudMessage *hudMessageTail;
@ -216,15 +216,18 @@ static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g
static void drawAbilityBars(void) static void drawAbilityBars(void)
{ {
drawBoostECMBar(10, 50, 128, 128, 255, battle.boostTimer == 0); drawBoostECMBar(battle.boostTimer, BOOST_RECHARGE_TIME, 10, 50, 128, 128, 255);
drawBoostECMBar(160, 50, 255, 128, 0, battle.ecmTimer == 0); drawBoostECMBar(battle.ecmTimer, ECM_RECHARGE_TIME, 160, 50, 255, 128, 0);
} }
static void drawBoostECMBar(int x, int y, int r, int g, int b, int available) static void drawBoostECMBar(int current, int max, int x, int y, int r, int g, int b)
{ {
SDL_Rect rect; SDL_Rect rect;
float percent = current;
percent /= max;
rect.x = x; rect.x = x;
rect.y = y; rect.y = y;
rect.w = 100; rect.w = 100;
@ -236,16 +239,22 @@ static void drawBoostECMBar(int x, int y, int r, int g, int b, int available)
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
SDL_RenderDrawRect(app.renderer, &rect); SDL_RenderDrawRect(app.renderer, &rect);
if (available)
{
rect.x += 2; rect.x += 2;
rect.y += 2; rect.y += 2;
rect.w -= 4; rect.w -= 4;
rect.h -= 4; rect.h -= 4;
rect.w *= percent;
if (current < max)
{
r /= 2;
g /= 2;
b /= 2;
}
SDL_SetRenderDrawColor(app.renderer, r, g, b, 255); SDL_SetRenderDrawColor(app.renderer, r, g, b, 255);
SDL_RenderFillRect(app.renderer, &rect); SDL_RenderFillRect(app.renderer, &rect);
}
} }
static void drawWeaponInfo(void) static void drawWeaponInfo(void)

View File

@ -59,16 +59,16 @@ void initPlayer(void)
player->action = NULL; player->action = NULL;
battle.boostTimer = 0; battle.boostTimer = BOOST_RECHARGE_TIME;
battle.ecmTimer = 0; battle.ecmTimer = ECM_RECHARGE_TIME;
} }
void doPlayer(void) void doPlayer(void)
{ {
battle.boostTimer = MAX(battle.boostTimer - 1, 0); battle.boostTimer = MIN(battle.boostTimer + 1, BOOST_RECHARGE_TIME);
battle.ecmTimer = MAX(battle.ecmTimer - 1, 0); battle.ecmTimer = MIN(battle.ecmTimer + 1, ECM_RECHARGE_TIME);
if (battle.boostTimer == BOOST_FINISHED_TIME) if (battle.boostTimer == (int)BOOST_FINISHED_TIME)
{ {
applyFighterThrust(); applyFighterThrust();
} }
@ -89,7 +89,7 @@ void doPlayer(void)
player->angle += 4; player->angle += 4;
} }
if (app.keyboard[SDL_SCANCODE_UP] && battle.boostTimer < BOOST_FINISHED_TIME) if (app.keyboard[SDL_SCANCODE_UP] && battle.boostTimer > BOOST_FINISHED_TIME)
{ {
applyFighterThrust(); applyFighterThrust();
} }
@ -132,12 +132,14 @@ void doPlayer(void)
app.keyboard[SDLK_t] = 0; app.keyboard[SDLK_t] = 0;
} }
if (app.keyboard[SDL_SCANCODE_SPACE] && !battle.boostTimer) if (app.keyboard[SDL_SCANCODE_SPACE] && battle.boostTimer == BOOST_RECHARGE_TIME)
{ {
playSound(SND_BOOST);
activateBoost(); activateBoost();
} }
if (app.keyboard[SDL_SCANCODE_E] && !battle.ecmTimer) if (app.keyboard[SDL_SCANCODE_E] && battle.ecmTimer == ECM_RECHARGE_TIME)
{ {
activateECM(); activateECM();
} }
@ -242,12 +244,12 @@ static void activateBoost(void)
self->dy += -cos(TO_RAIDANS(self->angle)) * 10; self->dy += -cos(TO_RAIDANS(self->angle)) * 10;
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
battle.boostTimer = BOOST_RECHARGE_TIME; battle.boostTimer = 0;
} }
static void activateECM(void) static void activateECM(void)
{ {
battle.ecmTimer = ECM_RECHARGE_TIME; battle.ecmTimer = 0;
} }
static void switchGuns(void) static void switchGuns(void)

View File

@ -32,6 +32,7 @@ extern void applyFighterBrakes(void);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void addHudMessage(SDL_Color c, char *format, ...); extern void addHudMessage(SDL_Color c, char *format, ...);
extern int mod(int n, int x); extern int mod(int n, int x);
extern void playSound(int id);
extern void failMission(void); extern void failMission(void);
extern App app; extern App app;

View File

@ -76,7 +76,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* player abilities */ /* player abilities */
#define BOOST_RECHARGE_TIME (FPS * 5) #define BOOST_RECHARGE_TIME (FPS * 5)
#define BOOST_FINISHED_TIME (BOOST_RECHARGE_TIME - FPS * 0.5) #define BOOST_FINISHED_TIME (FPS * 0.75)
#define ECM_RECHARGE_TIME (FPS * 5) #define ECM_RECHARGE_TIME (FPS * 5)
enum enum
@ -153,6 +153,7 @@ enum
SND_EXPLOSION_3, SND_EXPLOSION_3,
SND_EXPLOSION_4, SND_EXPLOSION_4,
SND_MISSILE, SND_MISSILE,
SND_BOOST,
SND_GUI_CLICK, SND_GUI_CLICK,
SND_GUI_SELECT, SND_GUI_SELECT,
SND_GUI_CLOSE, SND_GUI_CLOSE,