Implemented camera, to aid fighter switching. Added prompts for switching fighters, when current one is destroyed.
This commit is contained in:
parent
4f47cd0bc6
commit
443723f6b7
|
@ -36,6 +36,7 @@ static void options(void);
|
|||
static void returnFromOptions(void);
|
||||
|
||||
static int show;
|
||||
static float ssx, ssy;
|
||||
|
||||
void initBattle(void)
|
||||
{
|
||||
|
@ -86,11 +87,11 @@ static void logic(void)
|
|||
|
||||
if (show == SHOW_BATTLE)
|
||||
{
|
||||
if (!battle.epic || (battle.epic && player != NULL))
|
||||
if (!battle.epic || (battle.epic && !battle.playerSelect))
|
||||
{
|
||||
doBattle();
|
||||
}
|
||||
else if (battle.epic && player == NULL)
|
||||
else if (battle.epic && battle.playerSelect)
|
||||
{
|
||||
doPlayerSelect();
|
||||
}
|
||||
|
@ -102,27 +103,26 @@ static void logic(void)
|
|||
|
||||
static void doBattle(void)
|
||||
{
|
||||
scrollBackground(-battle.ssx * 0.1, -battle.ssy * 0.1);
|
||||
if (player != NULL)
|
||||
{
|
||||
battle.camera.x = player->x - (SCREEN_WIDTH / 2);
|
||||
battle.camera.y = player->y - (SCREEN_HEIGHT / 2);
|
||||
|
||||
ssx = player->dx;
|
||||
ssy = player->dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
ssx = ssy = 0;
|
||||
}
|
||||
|
||||
scrollBackground(-ssx * 0.1, -ssy * 0.1);
|
||||
|
||||
doHud();
|
||||
|
||||
doObjectives();
|
||||
|
||||
if (player != NULL)
|
||||
{
|
||||
battle.ssx = player->dx;
|
||||
battle.ssy = player->dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
battle.ssx *= 0.99;
|
||||
battle.ssy *= 0.99;
|
||||
}
|
||||
|
||||
battle.planet.x -= (battle.ssx * 0.25);
|
||||
battle.planet.y -= (battle.ssy * 0.25);
|
||||
|
||||
doStars(battle.ssx, battle.ssy);
|
||||
doStars(ssx, ssy);
|
||||
|
||||
doBullets();
|
||||
|
||||
|
@ -164,7 +164,7 @@ static void draw(void)
|
|||
|
||||
drawStars();
|
||||
|
||||
blit(battle.planetTexture, battle.planet.x, battle.planet.y, 1);
|
||||
blit(battle.planetTexture, battle.planet.x - battle.camera.x, battle.planet.y - battle.camera.y, 1);
|
||||
|
||||
drawBullets();
|
||||
|
||||
|
|
|
@ -64,9 +64,6 @@ void doBullets(void)
|
|||
b->x += b->dx;
|
||||
b->y += b->dy;
|
||||
|
||||
b->x -= battle.ssx;
|
||||
b->y -= battle.ssy;
|
||||
|
||||
if (b->type == BT_MISSILE)
|
||||
{
|
||||
addMissileEngineEffect(b);
|
||||
|
@ -148,7 +145,7 @@ void drawBullets(void)
|
|||
|
||||
for (b = battle.bulletHead.next ; b != NULL ; b = b->next)
|
||||
{
|
||||
blitRotated(b->texture, b->x, b->y, b->angle);
|
||||
blitRotated(b->texture, b->x - battle.camera.x, b->y - battle.camera.y, b->angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,6 @@ void doEffects(void)
|
|||
e->x += e->dx;
|
||||
e->y += e->dy;
|
||||
|
||||
e->x -= battle.ssx;
|
||||
e->y -= battle.ssy;
|
||||
|
||||
e->health--;
|
||||
|
||||
if (e->health <= 0)
|
||||
|
@ -72,12 +69,12 @@ void drawEffects(void)
|
|||
switch (e->type)
|
||||
{
|
||||
case EFFECT_LINE:
|
||||
SDL_RenderDrawLine(app.renderer, e->x, e->y, e->x + (e->dx * 3), e->y + (e->dy * 3));
|
||||
SDL_RenderDrawLine(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y, e->x + (e->dx * 3) - battle.camera.x, e->y + (e->dy * 3) - battle.camera.y);
|
||||
break;
|
||||
|
||||
case EFFECT_TEXTURE:
|
||||
SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
|
||||
blitScaled(e->texture, e->x, e->y, e->size, e->size);
|
||||
blitScaled(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->size, e->size);
|
||||
break;
|
||||
|
||||
case EFFECT_HALO:
|
||||
|
|
|
@ -47,13 +47,6 @@ void doEntities(void)
|
|||
|
||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
/* must always be shifted, even if not active */
|
||||
if (e != player)
|
||||
{
|
||||
e->x -= battle.ssx;
|
||||
e->y -= battle.ssy;
|
||||
}
|
||||
|
||||
if (e->active)
|
||||
{
|
||||
self = e;
|
||||
|
@ -112,6 +105,8 @@ void doEntities(void)
|
|||
if (e == player)
|
||||
{
|
||||
player = NULL;
|
||||
|
||||
battle.playerSelect = battle.epic;
|
||||
}
|
||||
|
||||
prev->next = e->next;
|
||||
|
@ -159,7 +154,7 @@ void drawEntities(void)
|
|||
|
||||
static void drawEntity(Entity *e)
|
||||
{
|
||||
blitRotated(e->texture, e->x, e->y, e->angle);
|
||||
blitRotated(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->angle);
|
||||
}
|
||||
|
||||
void activateEntities(char *name)
|
||||
|
|
|
@ -113,6 +113,8 @@ static void loadFighterDef(char *filename)
|
|||
}
|
||||
}
|
||||
|
||||
f->selectedGunType = f->guns[0].type;
|
||||
|
||||
if (cJSON_GetObjectItem(root, "missiles"))
|
||||
{
|
||||
node = cJSON_GetObjectItem(root, "missiles");
|
||||
|
|
|
@ -298,7 +298,6 @@ static void separate(void)
|
|||
|
||||
void drawFighter(Entity *e)
|
||||
{
|
||||
SDL_Rect r;
|
||||
SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png");
|
||||
|
||||
SDL_SetTextureColorMod(e->texture, 255, 255, 255);
|
||||
|
@ -313,38 +312,13 @@ void drawFighter(Entity *e)
|
|||
SDL_SetTextureColorMod(e->texture, 255 - e->systemHit, 255, 255);
|
||||
}
|
||||
|
||||
blitRotated(e->texture, e->x, e->y, e->angle);
|
||||
blitRotated(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->angle);
|
||||
|
||||
if (e->shieldHit > 0)
|
||||
{
|
||||
SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit);
|
||||
blit(shieldHitTexture, e->x, e->y, 1);
|
||||
}
|
||||
|
||||
if (player != NULL)
|
||||
{
|
||||
if (e == player->target)
|
||||
{
|
||||
r.x = e->x - 32;
|
||||
r.y = e->y - 32;
|
||||
r.w = 64;
|
||||
r.h = 64;
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 255, 64, 0, 255);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
}
|
||||
|
||||
if (e == battle.missionTarget)
|
||||
{
|
||||
r.x = e->x - 28;
|
||||
r.y = e->y - 28;
|
||||
r.w = 56;
|
||||
r.h = 56;
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 64, 255, 0, 255);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
}
|
||||
blit(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.y, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,7 +425,7 @@ static void spinDie(void)
|
|||
addSmallFighterExplosion();
|
||||
}
|
||||
|
||||
if (self->health <= -FPS)
|
||||
if (self->health <= -(FPS * 1.5))
|
||||
{
|
||||
self->alive = ALIVE_DEAD;
|
||||
addFighterExplosion();
|
||||
|
@ -472,7 +446,7 @@ static void straightDie(void)
|
|||
addSmallFighterExplosion();
|
||||
}
|
||||
|
||||
if (self->health <= -FPS)
|
||||
if (self->health <= -(FPS * 1.5))
|
||||
{
|
||||
self->alive = ALIVE_DEAD;
|
||||
addFighterExplosion();
|
||||
|
|
|
@ -29,6 +29,8 @@ static void drawObjectives(void);
|
|||
static void drawTargetDistance(void);
|
||||
static void drawMissionTargetDistance(void);
|
||||
static void drawHudMessages(void);
|
||||
static void drawPlayerSelect(void);
|
||||
static void drawTargetsRects(void);
|
||||
|
||||
static HudMessage hudMessageHead;
|
||||
static HudMessage *hudMessageTail;
|
||||
|
@ -120,16 +122,30 @@ void drawHud(void)
|
|||
{
|
||||
drawHealthBars();
|
||||
|
||||
drawPlayerTargeter();
|
||||
|
||||
drawTargetsRects();
|
||||
|
||||
drawWeaponInfo();
|
||||
|
||||
drawNumFighters();
|
||||
|
||||
drawObjectives();
|
||||
|
||||
if (battle.missionTarget)
|
||||
{
|
||||
drawMissionTargetDistance();
|
||||
}
|
||||
|
||||
drawRadar();
|
||||
}
|
||||
|
||||
drawHudMessages();
|
||||
|
||||
if (battle.playerSelect)
|
||||
{
|
||||
drawPlayerSelect();
|
||||
}
|
||||
}
|
||||
|
||||
static void drawHealthBars(void)
|
||||
|
@ -137,8 +153,6 @@ static void drawHealthBars(void)
|
|||
float p;
|
||||
int r, g, b;
|
||||
|
||||
drawPlayerTargeter();
|
||||
|
||||
r = g = b = 0;
|
||||
p = player->health;
|
||||
p /= player->maxHealth;
|
||||
|
@ -166,11 +180,6 @@ static void drawHealthBars(void)
|
|||
drawHealthShieldBar(player->target->shield, player->target->maxShield, SCREEN_WIDTH - 260, 30, 0, 200, 255);
|
||||
drawTargetDistance();
|
||||
}
|
||||
|
||||
if (battle.missionTarget)
|
||||
{
|
||||
drawMissionTargetDistance();
|
||||
}
|
||||
}
|
||||
|
||||
static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g, int b)
|
||||
|
@ -231,7 +240,7 @@ static void drawPlayerTargeter(void)
|
|||
SDL_SetTextureColorMod(targetCircle, 0, 255, 0);
|
||||
}
|
||||
|
||||
blit(targetCircle, player->x, player->y, 1);
|
||||
blit(targetCircle, player->x - battle.camera.x, player->y - battle.camera.y, 1);
|
||||
}
|
||||
|
||||
if (player->target)
|
||||
|
@ -245,7 +254,7 @@ static void drawPlayerTargeter(void)
|
|||
|
||||
SDL_SetTextureColorMod(targetPointer, 255, 0, 0);
|
||||
|
||||
blitRotated(targetPointer, x, y, angle);
|
||||
blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle);
|
||||
}
|
||||
|
||||
if (battle.missionTarget)
|
||||
|
@ -263,6 +272,33 @@ static void drawPlayerTargeter(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void drawTargetsRects(void)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
if (player->target)
|
||||
{
|
||||
r.x = player->target->x - 32 - battle.camera.x;
|
||||
r.y = player->target->y - 32 - battle.camera.y;
|
||||
r.w = 64;
|
||||
r.h = 64;
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 255, 64, 0, 255);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
}
|
||||
|
||||
if (battle.missionTarget)
|
||||
{
|
||||
r.x = battle.missionTarget->x - 28 - battle.camera.x;
|
||||
r.y = battle.missionTarget->y - 28 - battle.camera.y;
|
||||
r.w = 56;
|
||||
r.h = 56;
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 64, 255, 0, 255);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
}
|
||||
}
|
||||
|
||||
static void drawNumFighters(void)
|
||||
{
|
||||
/* Allies */
|
||||
|
@ -326,6 +362,20 @@ static void drawHudMessages(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void drawPlayerSelect(void)
|
||||
{
|
||||
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
|
||||
SDL_RenderFillRect(app.renderer, NULL);
|
||||
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
|
||||
|
||||
SDL_SetTextureColorMod(targetCircle, 0, 200, 255);
|
||||
|
||||
blit(targetCircle, player->x - battle.camera.x, player->y - battle.camera.y, 1);
|
||||
|
||||
drawText(SCREEN_WIDTH / 2, 500, 28, TA_CENTER, colors.white, "SELECT NEW FIGHTER");
|
||||
}
|
||||
|
||||
void resetHud(void)
|
||||
{
|
||||
HudMessage *hudMessage;
|
||||
|
|
|
@ -54,6 +54,9 @@ void initPlayer(void)
|
|||
}
|
||||
|
||||
STRNCPY(player->name, "Player", MAX_NAME_LENGTH);
|
||||
|
||||
player->action = NULL;
|
||||
player->defaultAction = NULL;
|
||||
}
|
||||
|
||||
void doPlayer(void)
|
||||
|
@ -125,25 +128,22 @@ void doPlayer(void)
|
|||
|
||||
player->angle = ((int)player->angle) % 360;
|
||||
|
||||
player->x = SCREEN_WIDTH / 2;
|
||||
player->y = SCREEN_HEIGHT / 2;
|
||||
|
||||
if (player->health <= 0 && battle.status == MS_IN_PROGRESS)
|
||||
{
|
||||
if (!battle.epic || (battle.epic && battle.numAllies <= 1))
|
||||
if (!battle.epic)
|
||||
{
|
||||
failIncompleteObjectives();
|
||||
|
||||
battle.status = MS_FAILED;
|
||||
battle.missionFinishedTimer = FPS;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (player->health == -FPS)
|
||||
{
|
||||
initPlayerSelect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initPlayerSelect(void)
|
||||
{
|
||||
|
@ -161,10 +161,22 @@ void initPlayerSelect(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (selectedPlayerIndex > 0)
|
||||
{
|
||||
battle.playerSelect = 1;
|
||||
selectedPlayerIndex = 0;
|
||||
|
||||
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
|
||||
}
|
||||
else
|
||||
{
|
||||
battle.epic = 0;
|
||||
|
||||
failIncompleteObjectives();
|
||||
|
||||
battle.status = MS_FAILED;
|
||||
battle.missionFinishedTimer = FPS;
|
||||
}
|
||||
}
|
||||
|
||||
void doPlayerSelect(void)
|
||||
{
|
||||
|
@ -184,10 +196,11 @@ void doPlayerSelect(void)
|
|||
|
||||
if (app.keyboard[SDL_SCANCODE_RETURN])
|
||||
{
|
||||
player = availablePlayerUnits[selectedPlayerIndex];
|
||||
battle.playerSelect = 0;
|
||||
|
||||
player->action = NULL;
|
||||
player->defaultAction = NULL;
|
||||
initPlayer();
|
||||
|
||||
app.keyboard[SDL_SCANCODE_RETURN] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,8 +211,13 @@ static void selectNewPlayer(int dir)
|
|||
selectedPlayerIndex += dir;
|
||||
|
||||
selectedPlayerIndex = mod(selectedPlayerIndex, MAX_SELECTABLE_PLAYERS);
|
||||
|
||||
player = availablePlayerUnits[selectedPlayerIndex];
|
||||
}
|
||||
while (availablePlayerUnits[selectedPlayerIndex] == NULL);
|
||||
while (player == NULL);
|
||||
|
||||
battle.camera.x = player->x - (SCREEN_WIDTH / 2);
|
||||
battle.camera.y = player->y - (SCREEN_HEIGHT / 2);
|
||||
}
|
||||
|
||||
static void switchGuns(void)
|
||||
|
|
|
@ -189,7 +189,6 @@ static void loadPlayer(cJSON *node)
|
|||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
|
||||
player = spawnFighter(type, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, side);
|
||||
player->defaultAction = NULL;
|
||||
}
|
||||
|
||||
static void loadFighters(cJSON *node)
|
||||
|
|
|
@ -51,8 +51,6 @@ void initTitle(void)
|
|||
app.delegate.draw = &draw;
|
||||
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
|
||||
|
||||
battle.ssx = battle.ssy = 0;
|
||||
|
||||
destroyBattle();
|
||||
|
||||
logo = getTexture("gfx/title/logo.png");
|
||||
|
|
|
@ -218,12 +218,12 @@ struct StarSystem {
|
|||
|
||||
typedef struct {
|
||||
int entId;
|
||||
float ssx;
|
||||
float ssy;
|
||||
SDL_Point camera;
|
||||
int numAllies;
|
||||
int numEnemies;
|
||||
int status;
|
||||
int epic;
|
||||
int playerSelect;
|
||||
int missionFinishedTimer;
|
||||
int numObjectivesComplete, numObjectivesTotal;
|
||||
Entity *missionTarget;
|
||||
|
|
Loading…
Reference in New Issue