Allow for switching of weapons. Show weapon info on hud.

This commit is contained in:
Steve 2015-10-23 07:08:18 +01:00
parent 204055ea72
commit f206f2052b
9 changed files with 76 additions and 44 deletions

View File

@ -8,14 +8,24 @@
"textureName" : "gfx/fighters/ray.png", "textureName" : "gfx/fighters/ray.png",
"guns" : [ "guns" : [
{ {
"type" : "BT_MAG", "type" : "BT_PLASMA",
"x" : -12, "x" : -12,
"y" : -12 "y" : -12
}, },
{ {
"type" : "BT_MAG", "type" : "BT_PLASMA",
"x" : 12, "x" : 12,
"y" : -12 "y" : -12
},
{
"type" : "BT_MAG",
"x" : -8,
"y" : -12
},
{
"type" : "BT_MAG",
"x" : 8,
"y" : -12
} }
], ],
"missiles" : { "missiles" : {

View File

@ -61,6 +61,7 @@ extern void scrollBackground(float x, float y);
extern void initOptions(void (*returnFromOptions)(void)); extern void initOptions(void (*returnFromOptions)(void));
extern void drawOptions(void); extern void drawOptions(void);
extern void playSound(int id); extern void playSound(int id);
extern void initPlayer(void);
extern App app; extern App app;
extern Battle battle; extern Battle battle;

View File

@ -230,7 +230,7 @@ void fireGuns(Fighter *owner)
for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++) for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++)
{ {
if (owner->guns[i].type) if (owner->guns[i].type == owner->selectedGunType)
{ {
s = sin(TO_RAIDANS(owner->angle)); s = sin(TO_RAIDANS(owner->angle));
c = cos(TO_RAIDANS(owner->angle)); c = cos(TO_RAIDANS(owner->angle));

View File

@ -73,6 +73,8 @@ Fighter *spawnFighter(char *name, int x, int y, int side)
randomizeDart(f); randomizeDart(f);
} }
f->selectedGunType = f->guns[0].type;
f->defaultAction = doAI; f->defaultAction = doAI;
f->die = die; f->die = die;

View File

@ -25,7 +25,7 @@ static void drawPlayerTargeter(void);
static void drawNumAllies(void); static void drawNumAllies(void);
static void drawNumEnemies(void); static void drawNumEnemies(void);
static void drawHealthBars(void); static void drawHealthBars(void);
static void drawMissileAmmoBar(void); static void drawWeaponInfo(void);
static void drawObjectives(void); static void drawObjectives(void);
static void drawTargetDistance(void); static void drawTargetDistance(void);
static void drawHudMessages(void); static void drawHudMessages(void);
@ -34,6 +34,7 @@ static HudMessage hudMessageHead;
static HudMessage *hudMessageTail; static HudMessage *hudMessageTail;
static int healthWarning; static int healthWarning;
static char *gunName[] = {"", "Particle Cannon", "Plasma Cannon", "Laser Cannon", "Mag Cannon"};
void initHud(void) void initHud(void)
{ {
@ -95,7 +96,7 @@ void drawHud(void)
{ {
drawHealthBars(); drawHealthBars();
drawMissileAmmoBar(); drawWeaponInfo();
drawNumAllies(); drawNumAllies();
@ -181,46 +182,10 @@ static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g
} }
} }
static void drawMissileAmmoBar(void) static void drawWeaponInfo(void)
{ {
int w; drawText(10, 50, 14, TA_LEFT, colors.white, gunName[player->selectedGunType]);
float i, percent, step; drawText(260, 50, 14, TA_RIGHT, colors.white, "Missiles (%d)", player->missiles.ammo);
SDL_Rect rect;
rect.x = 10;
rect.y = 50;
rect.w = 250;
rect.h = 12;
SDL_SetRenderDrawColor(app.renderer, 128, 64, 32, 255);
SDL_RenderFillRect(app.renderer, &rect);
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
SDL_RenderDrawRect(app.renderer, &rect);
rect.x += 2;
rect.y += 2;
rect.w -= 4;
rect.h -= 4;
percent = player->missiles.ammo;
percent /= player->missiles.maxAmmo;
step = rect.w;
step /= player->missiles.maxAmmo;
w = rect.w;
rect.w *= percent;
SDL_SetRenderDrawColor(app.renderer, 255, 128, 0, 255);
SDL_RenderFillRect(app.renderer, &rect);
for (i = step ; i < w ; i += step)
{
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
SDL_RenderDrawLine(app.renderer, rect.x + i, rect.y, rect.x + i, rect.y + rect.h);
}
} }
static void drawPlayerTargeter(void) static void drawPlayerTargeter(void)

View File

@ -21,6 +21,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "player.h" #include "player.h"
static void selectTarget(void); static void selectTarget(void);
static void switchGuns(void);
static int availableGuns[BT_MAX];
void initPlayer(void)
{
int i, n;
memset(&availableGuns, 0, sizeof(int) * BT_MAX);
player->selectedGunType = -1;
for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++)
{
n = player->guns[i].type;
if (n)
{
availableGuns[n] = 1;
if (player->selectedGunType == -1)
{
player->selectedGunType = n;
}
}
}
}
void doPlayer(void) void doPlayer(void)
{ {
@ -55,6 +82,13 @@ void doPlayer(void)
fireGuns(player); fireGuns(player);
} }
if (app.keyboard[SDL_SCANCODE_LSHIFT])
{
switchGuns();
app.keyboard[SDL_SCANCODE_LSHIFT] = 0;
}
if (app.keyboard[SDL_SCANCODE_RETURN] && player->missiles.ammo && player->target) if (app.keyboard[SDL_SCANCODE_RETURN] && player->missiles.ammo && player->target)
{ {
fireMissile(player); fireMissile(player);
@ -83,6 +117,21 @@ void doPlayer(void)
} }
} }
static void switchGuns(void)
{
int i;
i = player->selectedGunType;
do
{
i = (i + 1) % BT_MAX;
}
while (!availableGuns[i]);
player->selectedGunType = i;
}
static void selectTarget(void) static void selectTarget(void)
{ {
unsigned int closest = 65535; unsigned int closest = 65535;

View File

@ -68,6 +68,9 @@ void loadMission(char *filename)
battle.status = MS_IN_PROGRESS; battle.status = MS_IN_PROGRESS;
} }
initPlayer();
playMusic(music); playMusic(music);
} }

View File

@ -33,6 +33,7 @@ extern void startSectionTransition(void);
extern void endSectionTransition(void); extern void endSectionTransition(void);
extern void playMusic(char *filename); extern void playMusic(char *filename);
extern void stopMusic(void); extern void stopMusic(void);
extern void initPlayer(void);
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Fighter *player;

View File

@ -85,6 +85,7 @@ struct Fighter {
int maxShield; int maxShield;
int reload; int reload;
int reloadTime; int reloadTime;
int selectedGunType;
int shieldRecharge; int shieldRecharge;
int shieldRechargeRate; int shieldRechargeRate;
int systemPower; int systemPower;