diff --git a/data/fighters/ray.json b/data/fighters/ray.json index 599dd70..c5ae6ba 100644 --- a/data/fighters/ray.json +++ b/data/fighters/ray.json @@ -8,14 +8,24 @@ "textureName" : "gfx/fighters/ray.png", "guns" : [ { - "type" : "BT_MAG", + "type" : "BT_PLASMA", "x" : -12, "y" : -12 }, { - "type" : "BT_MAG", + "type" : "BT_PLASMA", "x" : 12, "y" : -12 + }, + { + "type" : "BT_MAG", + "x" : -8, + "y" : -12 + }, + { + "type" : "BT_MAG", + "x" : 8, + "y" : -12 } ], "missiles" : { diff --git a/src/battle/battle.h b/src/battle/battle.h index 200f220..808d065 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -61,6 +61,7 @@ extern void scrollBackground(float x, float y); extern void initOptions(void (*returnFromOptions)(void)); extern void drawOptions(void); extern void playSound(int id); +extern void initPlayer(void); extern App app; extern Battle battle; diff --git a/src/battle/bullets.c b/src/battle/bullets.c index ede1435..3b2b469 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -230,7 +230,7 @@ void fireGuns(Fighter *owner) 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)); c = cos(TO_RAIDANS(owner->angle)); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 87b1682..b166cf8 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -73,6 +73,8 @@ Fighter *spawnFighter(char *name, int x, int y, int side) randomizeDart(f); } + f->selectedGunType = f->guns[0].type; + f->defaultAction = doAI; f->die = die; diff --git a/src/battle/hud.c b/src/battle/hud.c index 2abfd25..b8b092f 100644 --- a/src/battle/hud.c +++ b/src/battle/hud.c @@ -25,7 +25,7 @@ static void drawPlayerTargeter(void); static void drawNumAllies(void); static void drawNumEnemies(void); static void drawHealthBars(void); -static void drawMissileAmmoBar(void); +static void drawWeaponInfo(void); static void drawObjectives(void); static void drawTargetDistance(void); static void drawHudMessages(void); @@ -34,6 +34,7 @@ static HudMessage hudMessageHead; static HudMessage *hudMessageTail; static int healthWarning; +static char *gunName[] = {"", "Particle Cannon", "Plasma Cannon", "Laser Cannon", "Mag Cannon"}; void initHud(void) { @@ -95,7 +96,7 @@ void drawHud(void) { drawHealthBars(); - drawMissileAmmoBar(); + drawWeaponInfo(); 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; - float i, percent, step; - 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); - } + drawText(10, 50, 14, TA_LEFT, colors.white, gunName[player->selectedGunType]); + drawText(260, 50, 14, TA_RIGHT, colors.white, "Missiles (%d)", player->missiles.ammo); } static void drawPlayerTargeter(void) diff --git a/src/battle/player.c b/src/battle/player.c index 95dc1a4..d25519c 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -21,6 +21,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "player.h" 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) { @@ -55,6 +82,13 @@ void doPlayer(void) 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) { 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) { unsigned int closest = 65535; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index bef7182..cb92e6d 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -68,6 +68,9 @@ void loadMission(char *filename) battle.status = MS_IN_PROGRESS; } + + initPlayer(); + playMusic(music); } diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 802cbfc..3c9f504 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -33,6 +33,7 @@ extern void startSectionTransition(void); extern void endSectionTransition(void); extern void playMusic(char *filename); extern void stopMusic(void); +extern void initPlayer(void); extern Battle battle; extern Fighter *player; diff --git a/src/structs.h b/src/structs.h index 837ff54..542961c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -85,6 +85,7 @@ struct Fighter { int maxShield; int reload; int reloadTime; + int selectedGunType; int shieldRecharge; int shieldRechargeRate; int systemPower;