Added ECM and boost abilities to player.

This commit is contained in:
Steve 2015-11-15 16:18:17 +00:00
parent 0b459a9927
commit d8ef183b5e
6 changed files with 89 additions and 5 deletions

View File

@ -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
{

View File

@ -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);

View File

@ -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)

View File

@ -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;

View File

@ -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,

View File

@ -241,6 +241,8 @@ typedef struct {
int epicFighterLimit;
int playerSelect;
int missionFinishedTimer;
int boostTimer;
int ecmTimer;
int numObjectivesComplete, numObjectivesTotal;
Entity *missionTarget;
Entity *extractionPoint;