Implemented camera, to aid fighter switching. Added prompts for switching fighters, when current one is destroyed.

This commit is contained in:
Steve 2015-10-31 23:09:43 +00:00
parent 4f47cd0bc6
commit 443723f6b7
11 changed files with 125 additions and 95 deletions

View File

@ -36,6 +36,7 @@ static void options(void);
static void returnFromOptions(void); static void returnFromOptions(void);
static int show; static int show;
static float ssx, ssy;
void initBattle(void) void initBattle(void)
{ {
@ -86,11 +87,11 @@ static void logic(void)
if (show == SHOW_BATTLE) if (show == SHOW_BATTLE)
{ {
if (!battle.epic || (battle.epic && player != NULL)) if (!battle.epic || (battle.epic && !battle.playerSelect))
{ {
doBattle(); doBattle();
} }
else if (battle.epic && player == NULL) else if (battle.epic && battle.playerSelect)
{ {
doPlayerSelect(); doPlayerSelect();
} }
@ -102,27 +103,26 @@ static void logic(void)
static void doBattle(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(); doHud();
doObjectives(); doObjectives();
if (player != NULL) doStars(ssx, ssy);
{
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);
doBullets(); doBullets();
@ -164,7 +164,7 @@ static void draw(void)
drawStars(); 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(); drawBullets();

View File

@ -64,9 +64,6 @@ void doBullets(void)
b->x += b->dx; b->x += b->dx;
b->y += b->dy; b->y += b->dy;
b->x -= battle.ssx;
b->y -= battle.ssy;
if (b->type == BT_MISSILE) if (b->type == BT_MISSILE)
{ {
addMissileEngineEffect(b); addMissileEngineEffect(b);
@ -148,7 +145,7 @@ void drawBullets(void)
for (b = battle.bulletHead.next ; b != NULL ; b = b->next) 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);
} }
} }

View File

@ -32,9 +32,6 @@ void doEffects(void)
e->x += e->dx; e->x += e->dx;
e->y += e->dy; e->y += e->dy;
e->x -= battle.ssx;
e->y -= battle.ssy;
e->health--; e->health--;
if (e->health <= 0) if (e->health <= 0)
@ -72,12 +69,12 @@ void drawEffects(void)
switch (e->type) switch (e->type)
{ {
case EFFECT_LINE: 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; break;
case EFFECT_TEXTURE: case EFFECT_TEXTURE:
SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b); 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; break;
case EFFECT_HALO: case EFFECT_HALO:

View File

@ -47,13 +47,6 @@ void doEntities(void)
for (e = battle.entityHead.next ; e != NULL ; e = e->next) 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) if (e->active)
{ {
self = e; self = e;
@ -112,6 +105,8 @@ void doEntities(void)
if (e == player) if (e == player)
{ {
player = NULL; player = NULL;
battle.playerSelect = battle.epic;
} }
prev->next = e->next; prev->next = e->next;
@ -159,7 +154,7 @@ void drawEntities(void)
static void drawEntity(Entity *e) 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) void activateEntities(char *name)

View File

@ -113,6 +113,8 @@ static void loadFighterDef(char *filename)
} }
} }
f->selectedGunType = f->guns[0].type;
if (cJSON_GetObjectItem(root, "missiles")) if (cJSON_GetObjectItem(root, "missiles"))
{ {
node = cJSON_GetObjectItem(root, "missiles"); node = cJSON_GetObjectItem(root, "missiles");

View File

@ -298,7 +298,6 @@ static void separate(void)
void drawFighter(Entity *e) void drawFighter(Entity *e)
{ {
SDL_Rect r;
SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png"); SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png");
SDL_SetTextureColorMod(e->texture, 255, 255, 255); SDL_SetTextureColorMod(e->texture, 255, 255, 255);
@ -313,38 +312,13 @@ void drawFighter(Entity *e)
SDL_SetTextureColorMod(e->texture, 255 - e->systemHit, 255, 255); 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) if (e->shieldHit > 0)
{ {
SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit); SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit);
blit(shieldHitTexture, e->x, e->y, 1); blit(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.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);
}
} }
} }
@ -451,7 +425,7 @@ static void spinDie(void)
addSmallFighterExplosion(); addSmallFighterExplosion();
} }
if (self->health <= -FPS) if (self->health <= -(FPS * 1.5))
{ {
self->alive = ALIVE_DEAD; self->alive = ALIVE_DEAD;
addFighterExplosion(); addFighterExplosion();
@ -472,7 +446,7 @@ static void straightDie(void)
addSmallFighterExplosion(); addSmallFighterExplosion();
} }
if (self->health <= -FPS) if (self->health <= -(FPS * 1.5))
{ {
self->alive = ALIVE_DEAD; self->alive = ALIVE_DEAD;
addFighterExplosion(); addFighterExplosion();

View File

@ -29,6 +29,8 @@ static void drawObjectives(void);
static void drawTargetDistance(void); static void drawTargetDistance(void);
static void drawMissionTargetDistance(void); static void drawMissionTargetDistance(void);
static void drawHudMessages(void); static void drawHudMessages(void);
static void drawPlayerSelect(void);
static void drawTargetsRects(void);
static HudMessage hudMessageHead; static HudMessage hudMessageHead;
static HudMessage *hudMessageTail; static HudMessage *hudMessageTail;
@ -120,16 +122,30 @@ void drawHud(void)
{ {
drawHealthBars(); drawHealthBars();
drawPlayerTargeter();
drawTargetsRects();
drawWeaponInfo(); drawWeaponInfo();
drawNumFighters(); drawNumFighters();
drawObjectives(); drawObjectives();
if (battle.missionTarget)
{
drawMissionTargetDistance();
}
drawRadar(); drawRadar();
} }
drawHudMessages(); drawHudMessages();
if (battle.playerSelect)
{
drawPlayerSelect();
}
} }
static void drawHealthBars(void) static void drawHealthBars(void)
@ -137,8 +153,6 @@ static void drawHealthBars(void)
float p; float p;
int r, g, b; int r, g, b;
drawPlayerTargeter();
r = g = b = 0; r = g = b = 0;
p = player->health; p = player->health;
p /= player->maxHealth; 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); drawHealthShieldBar(player->target->shield, player->target->maxShield, SCREEN_WIDTH - 260, 30, 0, 200, 255);
drawTargetDistance(); drawTargetDistance();
} }
if (battle.missionTarget)
{
drawMissionTargetDistance();
}
} }
static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g, int b) 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); 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) if (player->target)
@ -245,7 +254,7 @@ static void drawPlayerTargeter(void)
SDL_SetTextureColorMod(targetPointer, 255, 0, 0); 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) 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) static void drawNumFighters(void)
{ {
/* Allies */ /* 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) void resetHud(void)
{ {
HudMessage *hudMessage; HudMessage *hudMessage;

View File

@ -54,6 +54,9 @@ void initPlayer(void)
} }
STRNCPY(player->name, "Player", MAX_NAME_LENGTH); STRNCPY(player->name, "Player", MAX_NAME_LENGTH);
player->action = NULL;
player->defaultAction = NULL;
} }
void doPlayer(void) void doPlayer(void)
@ -125,25 +128,22 @@ void doPlayer(void)
player->angle = ((int)player->angle) % 360; 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 (player->health <= 0 && battle.status == MS_IN_PROGRESS)
{ {
if (!battle.epic || (battle.epic && battle.numAllies <= 1)) if (!battle.epic)
{ {
failIncompleteObjectives(); failIncompleteObjectives();
battle.status = MS_FAILED; battle.status = MS_FAILED;
battle.missionFinishedTimer = FPS; battle.missionFinishedTimer = FPS;
} }
} else if (player->health == -FPS)
}
else
{ {
initPlayerSelect(); initPlayerSelect();
} }
} }
}
}
void initPlayerSelect(void) void initPlayerSelect(void)
{ {
@ -161,10 +161,22 @@ void initPlayerSelect(void)
} }
} }
if (selectedPlayerIndex > 0)
{
battle.playerSelect = 1;
selectedPlayerIndex = 0; selectedPlayerIndex = 0;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
} }
else
{
battle.epic = 0;
failIncompleteObjectives();
battle.status = MS_FAILED;
battle.missionFinishedTimer = FPS;
}
}
void doPlayerSelect(void) void doPlayerSelect(void)
{ {
@ -184,10 +196,11 @@ void doPlayerSelect(void)
if (app.keyboard[SDL_SCANCODE_RETURN]) if (app.keyboard[SDL_SCANCODE_RETURN])
{ {
player = availablePlayerUnits[selectedPlayerIndex]; battle.playerSelect = 0;
player->action = NULL; initPlayer();
player->defaultAction = NULL;
app.keyboard[SDL_SCANCODE_RETURN] = 0;
} }
} }
@ -198,8 +211,13 @@ static void selectNewPlayer(int dir)
selectedPlayerIndex += dir; selectedPlayerIndex += dir;
selectedPlayerIndex = mod(selectedPlayerIndex, MAX_SELECTABLE_PLAYERS); 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) static void switchGuns(void)

View File

@ -189,7 +189,6 @@ static void loadPlayer(cJSON *node)
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring); side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
player = spawnFighter(type, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, side); player = spawnFighter(type, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, side);
player->defaultAction = NULL;
} }
static void loadFighters(cJSON *node) static void loadFighters(cJSON *node)

View File

@ -51,8 +51,6 @@ void initTitle(void)
app.delegate.draw = &draw; app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
battle.ssx = battle.ssy = 0;
destroyBattle(); destroyBattle();
logo = getTexture("gfx/title/logo.png"); logo = getTexture("gfx/title/logo.png");

View File

@ -218,12 +218,12 @@ struct StarSystem {
typedef struct { typedef struct {
int entId; int entId;
float ssx; SDL_Point camera;
float ssy;
int numAllies; int numAllies;
int numEnemies; int numEnemies;
int status; int status;
int epic; int epic;
int playerSelect;
int missionFinishedTimer; int missionFinishedTimer;
int numObjectivesComplete, numObjectivesTotal; int numObjectivesComplete, numObjectivesTotal;
Entity *missionTarget; Entity *missionTarget;