Fixed more magic numbers.

God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.

The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.

The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.

There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
This commit is contained in:
onpon4 2016-01-05 22:12:29 -05:00
parent 4a921947c1
commit 4be080225b
14 changed files with 219 additions and 124 deletions

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void bullet_add(object *theWeapon, object *attacker, int y, int dy) void bullet_add(object *theWeapon, object *attacker, int y, int dy)
{ {
object *bullet; object *bullet;
signed char imageIndex; int imageIndex;
int tempX, tempY, steps; int tempX, tempY, steps;
bullet = new object; bullet = new object;
@ -131,7 +131,7 @@ void bullet_add(object *theWeapon, object *attacker, int y, int dy)
{ {
bullet->dx = RANDRANGE(-20, 20); bullet->dx = RANDRANGE(-20, 20);
bullet->dy = RANDRANGE(-20, 20); bullet->dy = RANDRANGE(-20, 20);
bullet->image[0] = gfx_sprites[4]; bullet->image[0] = gfx_sprites[SP_SMALL_EXPLOSION];
} }
engine.bulletTail->next = bullet; engine.bulletTail->next = bullet;

View File

@ -58,7 +58,7 @@ object *cargo_add(object *owner, int cargoType)
cargo[index].dx = 0; cargo[index].dx = 0;
cargo[index].dy = 0; cargo[index].dy = 0;
cargo[index].collectType = cargoType; cargo[index].collectType = cargoType;
cargo[index].image[0] = gfx_sprites[32]; cargo[index].image[0] = gfx_sprites[SP_CARGO];
if (cargoType == P_PHOEBE) if (cargoType == P_PHOEBE)
cargo[index].image[0] = gfx_shipSprites[SS_FRIEND]; cargo[index].image[0] = gfx_shipSprites[SS_FRIEND];

View File

@ -153,52 +153,52 @@ void collectable_add(float x, float y, int type, int value, int life)
switch(type) switch(type)
{ {
case P_CASH: case P_CASH:
collectable->image = gfx_sprites[24]; collectable->image = gfx_sprites[SP_PICKUP_MONEY];
break; break;
case P_ROCKET: case P_ROCKET:
collectable->image = gfx_sprites[49]; collectable->image = gfx_sprites[SP_PICKUP_ROCKETS];
break; break;
case P_PLASMA_AMMO: case P_PLASMA_AMMO:
collectable->image = gfx_sprites[25]; collectable->image = gfx_sprites[SP_PICKUP_PLASMA];
break; break;
case P_SHIELD: case P_SHIELD:
collectable->image = gfx_sprites[26]; collectable->image = gfx_sprites[SP_PICKUP_SHIELD];
break; break;
case P_PLASMA_SHOT: case P_PLASMA_SHOT:
collectable->image = gfx_sprites[27]; collectable->image = gfx_sprites[SP_PICKUP_PLASMA_OUTPUT];
break; break;
case P_PLASMA_RATE: case P_PLASMA_RATE:
collectable->image = gfx_sprites[28]; collectable->image = gfx_sprites[SP_PICKUP_PLASMA_RATE];
break; break;
case P_PLASMA_DAMAGE: case P_PLASMA_DAMAGE:
collectable->image = gfx_sprites[29]; collectable->image = gfx_sprites[SP_PICKUP_PLASMA_POWER];
break; break;
case P_CARGO: case P_CARGO:
collectable->image = gfx_sprites[32]; collectable->image = gfx_sprites[SP_CARGO];
break; break;
case P_SUPER: case P_SUPER:
collectable->image = gfx_sprites[50]; collectable->image = gfx_sprites[SP_SUPERCHARGE];
break; break;
case P_MINE: case P_MINE:
collectable->image = gfx_sprites[31]; collectable->image = gfx_sprites[SP_MINE];
break; break;
case P_SLAVES: case P_SLAVES:
case P_ESCAPEPOD: case P_ESCAPEPOD:
collectable->image = gfx_sprites[45]; collectable->image = gfx_sprites[SP_ESCAPE_POD];
break; break;
case P_ORE: case P_ORE:
collectable->image = gfx_sprites[46 + rand() % 3]; collectable->image = gfx_sprites[RANDRANGE(SP_ORE, SP_ORE_L)];
break; break;
} }
@ -234,8 +234,8 @@ void collectable_explode(collectables *collectable)
audio_playSound(SFX_EXPLOSION, collectable->x); audio_playSound(SFX_EXPLOSION, collectable->x);
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
explosion_add(collectable->x + rand() % 25 - rand() % 25, explosion_add(RANDRANGE(collectable->x - 25, collectable->x + 25),
collectable->y + rand() % 25 - rand() % 25, E_BIG_EXPLOSION); RANDRANGE(collectable->y - 25, collectable->x + 25), SP_BIG_EXPLOSION);
player_checkShockDamage(collectable->x, collectable->y); player_checkShockDamage(collectable->x, collectable->y);
} }

View File

@ -34,7 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
((x) + (y) < (a) ? ((b) - (a)) : 0) + \ ((x) + (y) < (a) ? ((b) - (a)) : 0) + \
((x) + (y) > (b) ? ((a) - (b)) : 0)) ((x) + (y) > (b) ? ((a) - (b)) : 0))
#define CHANCE(x) ((rand() % RAND_MAX) < ((x) * RAND_MAX)) #define CHANCE(x) ((rand() % RAND_MAX) < ((x) * RAND_MAX))
#define RANDRANGE(x, y) (((x) < (y)) ? ((x) + (rand() % (1 + (y) - (x)))) : (x)) #define RANDRANGE(x, y) (((x) < (y)) ? ((x) + (rand() % (long long)(1 + (y) - (x)))) : (x))
// Compile-time options // Compile-time options
@ -85,13 +85,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FL_HASMINIMUMSPEED 2097152L #define FL_HASMINIMUMSPEED 2097152L
#define FL_FIRELASER 4194304L #define FL_FIRELASER 4194304L
// Explosions
#define E_SMALL_EXPLOSION 4
#define E_BIG_EXPLOSION 8
#define E_SMOKE 12
#define E_TINY_EXPLOSION 16
#define E_ELECTRICAL 20
// Weapon flags // Weapon flags
#define WF_SPREAD 4 #define WF_SPREAD 4
#define WF_SCATTER 8 #define WF_SCATTER 8
@ -105,8 +98,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define WF_TIMEDEXPLOSION 2048 #define WF_TIMEDEXPLOSION 2048
#define MAX_WEAPONS 20 #define MAX_WEAPONS 20
#define MAX_SPRITES 100
#define MAX_FONTSPRITES 6
#define MAX_CARGO 20 #define MAX_CARGO 20
#define MAX_INFOLINES 3 #define MAX_INFOLINES 3
#define MAX_EVENTS 20 #define MAX_EVENTS 20
@ -318,6 +309,66 @@ enum {
SP_PLANET_BLUE, SP_PLANET_BLUE,
SP_PLANET_RED, SP_PLANET_RED,
SP_PLANET_ORANGE, SP_PLANET_ORANGE,
// Bullets
SP_PLASMA_GREEN,
SP_PLASMA_RED,
SP_DIR_PLASMA_GREEN,
SP_DIR_PLASMA_RED,
SP_ION,
SP_ROCKET,
SP_ROCKET_L,
// Explosions
SP_SMALL_EXPLOSION,
SP_SMALL_EXPLOSION_2,
SP_SMALL_EXPLOSION_3,
SP_SMALL_EXPLOSION_L,
SP_BIG_EXPLOSION,
SP_BIG_EXPLOSION_2,
SP_BIG_EXPLOSION_3,
SP_BIG_EXPLOSION_L,
SP_SMOKE,
SP_SMOKE_2,
SP_SMOKE_3,
SP_SMOKE_L,
SP_TINY_EXPLOSION,
SP_TINY_EXPLOSION_2,
SP_TINY_EXPLOSION_3,
SP_TINY_EXPLOSION_L,
SP_ELECTRICAL,
SP_ELECTRICAL_2,
SP_ELECTRICAL_3,
SP_ELECTRICAL_L,
// Pickups
SP_PICKUP_MONEY,
SP_PICKUP_PLASMA,
SP_PICKUP_ROCKETS,
SP_PICKUP_SHIELD,
SP_PICKUP_PLASMA_OUTPUT,
SP_PICKUP_PLASMA_POWER,
SP_PICKUP_PLASMA_RATE,
SP_SUPERCHARGE,
SP_CARGO,
SP_ESCAPE_POD,
SP_ORE,
SP_ORE_2,
SP_ORE_L,
SP_CHAIN_LINK,
SP_MINE,
// Targeting system
SP_ARROW_NORTH,
SP_ARROW_NORTHEAST,
SP_ARROW_EAST,
SP_ARROW_SOUTHEAST,
SP_ARROW_SOUTH,
SP_ARROW_SOUTHWEST,
SP_ARROW_WEST,
SP_ARROW_NORTHWEST,
SP_TARGET,
SP_MAX SP_MAX
}; };
@ -550,7 +601,8 @@ enum {
FONT_YELLOW, FONT_YELLOW,
FONT_GREEN, FONT_GREEN,
FONT_CYAN, FONT_CYAN,
FONT_OUTLINE // a dark blue color FONT_OUTLINE, // a dark blue color
FONT_MAX
}; };
// Sounds // Sounds

View File

@ -266,7 +266,7 @@ void engine_cleanup()
delete(engine.collectableHead); delete(engine.collectableHead);
delete(screen_bufferHead); delete(screen_bufferHead);
for (int i = 0 ; i < MAX_FONTSPRITES ; i++) for (int i = 0 ; i < FONT_MAX ; i++)
{ {
if (gfx_fontSprites[i] != NULL) if (gfx_fontSprites[i] != NULL)
SDL_FreeSurface(gfx_fontSprites[i]); SDL_FreeSurface(gfx_fontSprites[i]);

View File

@ -47,12 +47,12 @@ void explosion_add(float x, float y, int type)
*/ */
void explosion_addEngine(object *craft) void explosion_addEngine(object *craft)
{ {
if (rand() % 2 == 0) if (CHANCE(0.5))
return; return;
float x = craft->x + (craft->engineX * craft->face); float x = craft->x + (craft->engineX * craft->face);
float y = craft->y + craft->engineY; float y = craft->y + craft->engineY;
y += RANDRANGE(-3, 3); y += RANDRANGE(-3, 3);
explosion_add(x, y, E_TINY_EXPLOSION); explosion_add(x, y, SP_TINY_EXPLOSION);
} }

View File

@ -521,11 +521,11 @@ static void game_doBullets()
if (bullet->id == WT_ROCKET) if (bullet->id == WT_ROCKET)
{ {
explosion_add(bullet->x, bullet->y, E_SMALL_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_SMALL_EXPLOSION);
} }
else if (bullet->id == WT_MICROROCKET) else if (bullet->id == WT_MICROROCKET)
{ {
explosion_add(bullet->x, bullet->y, E_TINY_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_TINY_EXPLOSION);
} }
if ((bullet->flags & WF_AIMED)) if ((bullet->flags & WF_AIMED))
@ -637,7 +637,7 @@ static void game_doBullets()
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
explosion_add(bullet->x + RANDRANGE(-35, 35), explosion_add(bullet->x + RANDRANGE(-35, 35),
bullet->y + RANDRANGE(-35, 35), bullet->y + RANDRANGE(-35, 35),
E_BIG_EXPLOSION); SP_BIG_EXPLOSION);
} }
} }
else else
@ -647,9 +647,9 @@ static void game_doBullets()
} }
if (bullet->id == WT_ROCKET) if (bullet->id == WT_ROCKET)
explosion_add(bullet->x, bullet->y, E_BIG_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_BIG_EXPLOSION);
else else
explosion_add(bullet->x, bullet->y, E_SMALL_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_SMALL_EXPLOSION);
} }
} }
} }
@ -688,7 +688,7 @@ static void game_doBullets()
audio_playSound(SFX_EXPLOSION, bullet->x); audio_playSound(SFX_EXPLOSION, bullet->x);
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
explosion_add(bullet->x + RANDRANGE(-35, 35), explosion_add(bullet->x + RANDRANGE(-35, 35),
bullet->y + RANDRANGE(-35, 35), E_BIG_EXPLOSION); bullet->y + RANDRANGE(-35, 35), SP_BIG_EXPLOSION);
} }
} }
else else
@ -700,9 +700,9 @@ static void game_doBullets()
audio_playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
if (bullet->id == WT_ROCKET) if (bullet->id == WT_ROCKET)
explosion_add(bullet->x, bullet->y, E_BIG_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_BIG_EXPLOSION);
else else
explosion_add(bullet->x, bullet->y, E_SMALL_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_SMALL_EXPLOSION);
} }
} }
} }
@ -717,7 +717,7 @@ static void game_doBullets()
if (bullet_collision(bullet, &cargo[j])) if (bullet_collision(bullet, &cargo[j]))
{ {
bullet->active = false; bullet->active = false;
explosion_add(bullet->x, bullet->y, E_SMALL_EXPLOSION); explosion_add(bullet->x, bullet->y, SP_SMALL_EXPLOSION);
audio_playSound(SFX_HIT, cargo[j].x); audio_playSound(SFX_HIT, cargo[j].x);
if (cargo[j].collectType != P_PHOEBE) if (cargo[j].collectType != P_PHOEBE)
{ {
@ -726,7 +726,7 @@ static void game_doBullets()
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
explosion_add(cargo[j].x + RANDRANGE(-15, 15), explosion_add(cargo[j].x + RANDRANGE(-15, 15),
cargo[j].y + RANDRANGE(-15, 15), cargo[j].y + RANDRANGE(-15, 15),
E_BIG_EXPLOSION); SP_BIG_EXPLOSION);
updateMissionRequirements(M_PROTECT_PICKUP, updateMissionRequirements(M_PROTECT_PICKUP,
P_CARGO, 1); P_CARGO, 1);
} }
@ -791,7 +791,7 @@ static void game_doBullets()
audio_playSound(SFX_EXPLOSION, bullet->x); audio_playSound(SFX_EXPLOSION, bullet->x);
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
explosion_add(bullet->x + RANDRANGE(-35, 35), explosion_add(bullet->x + RANDRANGE(-35, 35),
bullet->y + RANDRANGE(-35, 35), E_BIG_EXPLOSION); bullet->y + RANDRANGE(-35, 35), SP_BIG_EXPLOSION);
player_checkShockDamage(bullet->x, bullet->y); player_checkShockDamage(bullet->x, bullet->y);
} }
@ -1092,7 +1092,7 @@ static void game_doAliens()
if ((rand() % 10) == 0) if ((rand() % 10) == 0)
explosion_add(aliens[i].x + (rand() % aliens[i].image[0]->w), explosion_add(aliens[i].x + (rand() % aliens[i].image[0]->w),
aliens[i].y + (rand() % aliens[i].image[0]->h), aliens[i].y + (rand() % aliens[i].image[0]->h),
E_ELECTRICAL); SP_ELECTRICAL);
} }
} }
@ -1109,7 +1109,7 @@ static void game_doAliens()
(int)aliens[i].y); (int)aliens[i].y);
explosion_add(aliens[i].x + (rand() % aliens[i].image[0]->w), explosion_add(aliens[i].x + (rand() % aliens[i].image[0]->w),
aliens[i].y + (rand() % aliens[i].image[0]->h), aliens[i].y + (rand() % aliens[i].image[0]->h),
E_BIG_EXPLOSION); SP_BIG_EXPLOSION);
} }
if (aliens[i].shield < aliens[i].deathCounter) if (aliens[i].shield < aliens[i].deathCounter)
{ {
@ -1399,7 +1399,7 @@ static void game_doPlayer()
if ((player.maxShield > 1) && (player.shield <= engine.lowShield) && if ((player.maxShield > 1) && (player.shield <= engine.lowShield) &&
(rand() % 5 < 1)) (rand() % 5 < 1))
explosion_add(player.x + RANDRANGE(-10, 10), explosion_add(player.x + RANDRANGE(-10, 10),
player.y + RANDRANGE(-10, 20), E_SMOKE); player.y + RANDRANGE(-10, 20), SP_SMOKE);
} }
else else
{ {
@ -1424,7 +1424,7 @@ static void game_doPlayer()
engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0; engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0;
if ((rand() % 3) == 0) if ((rand() % 3) == 0)
explosion_add(player.x + RANDRANGE(-10, 10), explosion_add(player.x + RANDRANGE(-10, 10),
player.y + RANDRANGE(-10, 10), E_BIG_EXPLOSION); player.y + RANDRANGE(-10, 10), SP_BIG_EXPLOSION);
if (player.shield == -99) if (player.shield == -99)
game_addDebris((int)player.x, (int)player.y, player.maxShield); game_addDebris((int)player.x, (int)player.y, player.maxShield);
} }
@ -1481,7 +1481,7 @@ static void game_doCargo()
// draw the chain link line // draw the chain link line
for (int j = 0 ; j < 10 ; j++) for (int j = 0 ; j < 10 ; j++)
{ {
screen_blit(gfx_sprites[30], (int)chainX, (int)chainY); screen_blit(gfx_sprites[SP_CHAIN_LINK], (int)chainX, (int)chainY);
chainX -= dx; chainX -= dx;
chainY -= dy; chainY -= dy;
} }
@ -1508,7 +1508,7 @@ static void game_doDebris()
debris->x += debris->dx; debris->x += debris->dx;
debris->y += debris->dy; debris->y += debris->dy;
explosion_add(debris->x + RANDRANGE(-10, 10), debris->y + RANDRANGE(-10, 10), E_BIG_EXPLOSION); explosion_add(debris->x + RANDRANGE(-10, 10), debris->y + RANDRANGE(-10, 10), SP_BIG_EXPLOSION);
} }
if (debris->thinktime < 1) if (debris->thinktime < 1)
@ -1549,7 +1549,7 @@ void game_doExplosions()
screen_blit(explosion->image[0], (int)explosion->x, (int)explosion->y); screen_blit(explosion->image[0], (int)explosion->x, (int)explosion->y);
if(rand() % 7 == 0) if(CHANCE(1. / 7.))
{ {
explosion->thinktime -= 7; explosion->thinktime -= 7;
@ -1602,12 +1602,15 @@ static void game_doArrow(int i)
int arrow; int arrow;
if (sxy == sx) { if (sxy == sx)
arrow = x < screen->w / 2 ? 42 : 38; {
arrow = x < screen->w / 2 ? SP_ARROW_WEST : SP_ARROW_EAST;
x -= x > screen->w / 2 ? gfx_sprites[arrow]->w : 0; x -= x > screen->w / 2 ? gfx_sprites[arrow]->w : 0;
y -= gfx_sprites[arrow]->h / 2; y -= gfx_sprites[arrow]->h / 2;
} else { }
arrow = y < screen->h / 2 ? 36 : 40; else
{
arrow = y < screen->h / 2 ? SP_ARROW_NORTH : SP_ARROW_SOUTH;
x -= gfx_sprites[arrow]->w / 2; x -= gfx_sprites[arrow]->w / 2;
y -= y > screen->h / 2 ? gfx_sprites[arrow]->h : 0; y -= y > screen->h / 2 ? gfx_sprites[arrow]->h : 0;
} }
@ -1620,15 +1623,18 @@ static void game_doArrow(int i)
if (gfx_textSprites[TS_RADIO].life > 0) if (gfx_textSprites[TS_RADIO].life > 0)
return; return;
if (sxy == sx) { if (sxy == sx)
x -= x > screen->w / 2 ? 5 + gfx_sprites[44]->w : -5 - gfx_sprites[arrow]->w; {
y -= (gfx_sprites[44]->h - gfx_sprites[arrow]->h) / 2; x -= x > screen->w / 2 ? 5 + gfx_sprites[SP_TARGET]->w : -5 - gfx_sprites[arrow]->w;
} else { y -= (gfx_sprites[SP_TARGET]->h - gfx_sprites[arrow]->h) / 2;
x -= (gfx_sprites[44]->w - gfx_sprites[arrow]->w) / 2; }
y -= y > screen->h / 2 ? 5 + gfx_sprites[44]->h : -5 - gfx_sprites[arrow]->h; else
{
x -= (gfx_sprites[SP_TARGET]->w - gfx_sprites[arrow]->w) / 2;
y -= y > screen->h / 2 ? 5 + gfx_sprites[SP_TARGET]->h : -5 - gfx_sprites[arrow]->h;
} }
screen_blit(gfx_sprites[44], x, y); screen_blit(gfx_sprites[SP_TARGET], x, y);
} }
static void game_doHud() static void game_doHud()

View File

@ -22,10 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Starfighter.h" #include "Starfighter.h"
SDL_Surface *gfx_background; SDL_Surface *gfx_background;
SDL_Surface *gfx_sprites[MAX_SPRITES]; SDL_Surface *gfx_sprites[SP_MAX];
SDL_Surface *gfx_faceSprites[FS_MAX]; SDL_Surface *gfx_faceSprites[FS_MAX];
SDL_Surface *gfx_shipSprites[SS_MAX]; SDL_Surface *gfx_shipSprites[SS_MAX];
SDL_Surface *gfx_fontSprites[MAX_FONTSPRITES]; SDL_Surface *gfx_fontSprites[FONT_MAX];
SDL_Surface *gfx_shopSprites[SHOP_S_MAX]; SDL_Surface *gfx_shopSprites[SHOP_S_MAX];
textObject gfx_textSprites[TS_MAX]; textObject gfx_textSprites[TS_MAX];
SDL_Surface *gfx_messageBox; SDL_Surface *gfx_messageBox;
@ -36,7 +36,7 @@ void gfx_init()
screen_bufferHead->next = NULL; screen_bufferHead->next = NULL;
screen_bufferTail = screen_bufferHead; screen_bufferTail = screen_bufferHead;
for (int i = 0 ; i < MAX_SPRITES ; i++) for (int i = 0 ; i < SP_MAX ; i++)
gfx_sprites[i] = NULL; gfx_sprites[i] = NULL;
for (int i = 0 ; i < SS_MAX ; i++) for (int i = 0 ; i < SS_MAX ; i++)
@ -48,7 +48,7 @@ void gfx_init()
for (int i = 0 ; i < SHOP_S_MAX ; i++) for (int i = 0 ; i < SHOP_S_MAX ; i++)
gfx_shopSprites[i] = NULL; gfx_shopSprites[i] = NULL;
for (int i = 0 ; i < MAX_FONTSPRITES ; i++) for (int i = 0 ; i < FONT_MAX ; i++)
gfx_fontSprites[i] = NULL; gfx_fontSprites[i] = NULL;
gfx_background = NULL; gfx_background = NULL;
@ -444,7 +444,7 @@ SDL_Surface *gfx_loadImage(const char *filename)
void gfx_free() void gfx_free()
{ {
for (int i = 0 ; i < MAX_SPRITES ; i++) for (int i = 0 ; i < SP_MAX ; i++)
{ {
if (gfx_sprites[i] != NULL) if (gfx_sprites[i] != NULL)
{ {

View File

@ -23,10 +23,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Starfighter.h" #include "Starfighter.h"
extern SDL_Surface *gfx_background; extern SDL_Surface *gfx_background;
extern SDL_Surface *gfx_sprites[MAX_SPRITES]; extern SDL_Surface *gfx_sprites[SP_MAX];
extern SDL_Surface *gfx_faceSprites[FS_MAX]; extern SDL_Surface *gfx_faceSprites[FS_MAX];
extern SDL_Surface *gfx_shipSprites[SS_MAX]; extern SDL_Surface *gfx_shipSprites[SS_MAX];
extern SDL_Surface *gfx_fontSprites[MAX_FONTSPRITES]; extern SDL_Surface *gfx_fontSprites[FONT_MAX];
extern SDL_Surface *gfx_shopSprites[SHOP_S_MAX]; extern SDL_Surface *gfx_shopSprites[SHOP_S_MAX];
extern textObject gfx_textSprites[TS_MAX]; extern textObject gfx_textSprites[TS_MAX];
extern SDL_Surface *gfx_messageBox; extern SDL_Surface *gfx_messageBox;

View File

@ -116,6 +116,8 @@ bool loadGame(int slot)
game.difficulty = DIFFICULTY_NORMAL; game.difficulty = DIFFICULTY_NORMAL;
weapon[W_PLAYER_WEAPON] = game.playerWeapon; weapon[W_PLAYER_WEAPON] = game.playerWeapon;
weapon[W_PLAYER_WEAPON].imageIndex[0] = SP_PLASMA_GREEN;
weapon[W_PLAYER_WEAPON].imageIndex[1] = SP_PLASMA_GREEN;
player = game.thePlayer; player = game.thePlayer;
// Re-init all the planets in this system... // Re-init all the planets in this system...

View File

@ -32,9 +32,6 @@ void loadBackground(const char *filename)
void loadGameGraphics() void loadGameGraphics()
{ {
int index;
char string[75] = "";
FILE *fp;
Uint32 *p32; Uint32 *p32;
Uint16 *p16; Uint16 *p16;
Uint8 *p8; Uint8 *p8;
@ -177,16 +174,58 @@ void loadGameGraphics()
SDL_MapRGB(gfx_shipSprites[i]->format, 0, 0, 0)); SDL_MapRGB(gfx_shipSprites[i]->format, 0, 0, 0));
} }
strcpy(string, "data/resources_all.dat"); // Other sprites
gfx_sprites[SP_PLASMA_GREEN] = gfx_loadImage("gfx/plasmaGreen.png");
fp = fopen(string, "rb"); gfx_sprites[SP_PLASMA_RED] = gfx_loadImage("gfx/plasmaRed.png");
gfx_sprites[SP_DIR_PLASMA_GREEN] = gfx_loadImage("gfx/greenDir.png");
while (fscanf(fp, "%d %s", &index, string) == 2) gfx_sprites[SP_DIR_PLASMA_RED] = gfx_loadImage("gfx/redDir.png");
{ gfx_sprites[SP_ROCKET] = gfx_loadImage("gfx/rocket1.png");
gfx_sprites[index] = gfx_loadImage(string); gfx_sprites[SP_ROCKET_L] = gfx_loadImage("gfx/rocket2.png");
} gfx_sprites[SP_SMALL_EXPLOSION] = gfx_loadImage("gfx/explode1.png");
gfx_sprites[SP_SMALL_EXPLOSION_2] = gfx_loadImage("gfx/explode2.png");
fclose(fp); gfx_sprites[SP_SMALL_EXPLOSION_3] = gfx_loadImage("gfx/explode3.png");
gfx_sprites[SP_SMALL_EXPLOSION_L] = gfx_loadImage("gfx/explode4.png");
gfx_sprites[SP_BIG_EXPLOSION] = gfx_loadImage("gfx/explode05.png");
gfx_sprites[SP_BIG_EXPLOSION_2] = gfx_loadImage("gfx/explode06.png");
gfx_sprites[SP_BIG_EXPLOSION_3] = gfx_loadImage("gfx/explode07.png");
gfx_sprites[SP_BIG_EXPLOSION_L] = gfx_loadImage("gfx/explode08.png");
gfx_sprites[SP_SMOKE] = gfx_loadImage("gfx/explode9.png");
gfx_sprites[SP_SMOKE_2] = gfx_loadImage("gfx/explode10.png");
gfx_sprites[SP_SMOKE_3] = gfx_loadImage("gfx/explode11.png");
gfx_sprites[SP_SMOKE_L] = gfx_loadImage("gfx/explode12.png");
gfx_sprites[SP_TINY_EXPLOSION] = gfx_loadImage("gfx/explode13.png");
gfx_sprites[SP_TINY_EXPLOSION_2] = gfx_loadImage("gfx/explode14.png");
gfx_sprites[SP_TINY_EXPLOSION_3] = gfx_loadImage("gfx/explode15.png");
gfx_sprites[SP_TINY_EXPLOSION_L] = gfx_loadImage("gfx/explode16.png");
gfx_sprites[SP_ELECTRICAL] = gfx_loadImage("gfx/elec1.png");
gfx_sprites[SP_ELECTRICAL_2] = gfx_loadImage("gfx/elec2.png");
gfx_sprites[SP_ELECTRICAL_3] = gfx_loadImage("gfx/elec3.png");
gfx_sprites[SP_ELECTRICAL_L] = gfx_loadImage("gfx/elec4.png");
gfx_sprites[SP_PICKUP_MONEY] = gfx_loadImage("gfx/dollar.png");
gfx_sprites[SP_PICKUP_PLASMA] = gfx_loadImage("gfx/rocket.png");
gfx_sprites[SP_PICKUP_SHIELD] = gfx_loadImage("gfx/heart.png");
gfx_sprites[SP_PICKUP_PLASMA_OUTPUT] = gfx_loadImage("gfx/plasmaAmmo.png");
gfx_sprites[SP_PICKUP_PLASMA_RATE] = gfx_loadImage("gfx/plasmaRate.png");
gfx_sprites[SP_PICKUP_PLASMA_POWER] = gfx_loadImage("gfx/plasmaDamage.png");
gfx_sprites[SP_CHAIN_LINK] = gfx_loadImage("gfx/chainLink.png");
gfx_sprites[SP_MINE] = gfx_loadImage("gfx/mine.png");
gfx_sprites[SP_CARGO] = gfx_loadImage("gfx/cargo1.png");
gfx_sprites[SP_ION] = gfx_loadImage("gfx/stunBolt.png");
gfx_sprites[SP_ARROW_NORTH] = gfx_loadImage("gfx/arrowNorth.png");
gfx_sprites[SP_ARROW_NORTHEAST] = gfx_loadImage("gfx/arrowNorthEast.png");
gfx_sprites[SP_ARROW_EAST] = gfx_loadImage("gfx/arrowEast.png");
gfx_sprites[SP_ARROW_SOUTHEAST] = gfx_loadImage("gfx/arrowSouthEast.png");
gfx_sprites[SP_ARROW_SOUTH] = gfx_loadImage("gfx/arrowSouth.png");
gfx_sprites[SP_ARROW_SOUTHWEST] = gfx_loadImage("gfx/arrowSouthWest.png");
gfx_sprites[SP_ARROW_WEST] = gfx_loadImage("gfx/arrowWest.png");
gfx_sprites[SP_ARROW_NORTHWEST] = gfx_loadImage("gfx/arrowNorthWest.png");
gfx_sprites[SP_TARGET] = gfx_loadImage("gfx/targetText.png");
gfx_sprites[SP_ESCAPE_POD] = gfx_loadImage("gfx/pod.png");
gfx_sprites[SP_ORE] = gfx_loadImage("gfx/ore1.png");
gfx_sprites[SP_ORE_2] = gfx_loadImage("gfx/ore2.png");
gfx_sprites[SP_ORE_L] = gfx_loadImage("gfx/ore3.png");
gfx_sprites[SP_PICKUP_ROCKETS] = gfx_loadImage("gfx/rocketAmmo.png");
gfx_sprites[SP_SUPERCHARGE] = gfx_loadImage("gfx/superCharge.png");
loadBackground(systemBackground[game.system]); loadBackground(systemBackground[game.system]);
@ -201,7 +240,11 @@ void loadGameGraphics()
} }
} }
setWeaponShapes(); for (int i = 0 ; i < MAX_WEAPONS ; i++)
{
weapon[i].image[0] = gfx_sprites[weapon[i].imageIndex[0]];
weapon[i].image[1] = gfx_sprites[weapon[i].imageIndex[1]];
}
} }
@ -213,7 +256,7 @@ void loadFont()
{ {
SDL_Surface *image, *newImage; SDL_Surface *image, *newImage;
for (int i = 0 ; i < MAX_FONTSPRITES ; i++) for (int i = 0 ; i < FONT_MAX ; i++)
{ {
image = IMG_Load("gfx/smallFont.png"); image = IMG_Load("gfx/smallFont.png");
@ -224,19 +267,19 @@ void loadFont()
switch(i) switch(i)
{ {
case 1: case FONT_RED:
SDL_SetSurfaceColorMod(image, 255, 0, 0); SDL_SetSurfaceColorMod(image, 255, 0, 0);
break; break;
case 2: case FONT_YELLOW:
SDL_SetSurfaceColorMod(image, 255, 255, 0); SDL_SetSurfaceColorMod(image, 255, 255, 0);
break; break;
case 3: case FONT_GREEN:
SDL_SetSurfaceColorMod(image, 0, 255, 0); SDL_SetSurfaceColorMod(image, 0, 255, 0);
break; break;
case 4: case FONT_CYAN:
SDL_SetSurfaceColorMod(image, 0, 255, 255); SDL_SetSurfaceColorMod(image, 0, 255, 255);
break; break;
case 5: case FONT_OUTLINE:
SDL_SetSurfaceColorMod(image, 0, 0, 10); SDL_SetSurfaceColorMod(image, 0, 0, 10);
break; break;
} }

View File

@ -176,7 +176,7 @@ void ship_fireRay(object *ship)
} }
player.shield--; player.shield--;
explosion_add(player.x, player.y, E_SMALL_EXPLOSION); explosion_add(player.x, player.y, SP_SMALL_EXPLOSION);
audio_playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
if (player.shield < 1) if (player.shield < 1)
{ {

View File

@ -21,15 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
object weapon[MAX_WEAPONS]; object weapon[MAX_WEAPONS];
void setWeaponShapes()
{
for (int i = 0 ; i < MAX_WEAPONS ; i++)
{
weapon[i].image[0] = gfx_sprites[weapon[i].imageIndex[0]];
weapon[i].image[1] = gfx_sprites[weapon[i].imageIndex[1]];
}
}
/* /*
A list of predefined weaponary. A list of predefined weaponary.
*/ */
@ -41,8 +32,8 @@ void initWeapons()
weapon[W_PLAYER_WEAPON].damage = 1; weapon[W_PLAYER_WEAPON].damage = 1;
weapon[W_PLAYER_WEAPON].reload[0] = 15; weapon[W_PLAYER_WEAPON].reload[0] = 15;
weapon[W_PLAYER_WEAPON].speed = 10; weapon[W_PLAYER_WEAPON].speed = 10;
weapon[W_PLAYER_WEAPON].imageIndex[0] = 0; weapon[W_PLAYER_WEAPON].imageIndex[0] = SP_PLASMA_GREEN;
weapon[W_PLAYER_WEAPON].imageIndex[1] = 0; weapon[W_PLAYER_WEAPON].imageIndex[1] = SP_PLASMA_GREEN;
weapon[W_PLAYER_WEAPON].flags = WF_SPREAD; weapon[W_PLAYER_WEAPON].flags = WF_SPREAD;
// Single Shot // Single Shot
@ -51,8 +42,8 @@ void initWeapons()
weapon[W_SINGLE_SHOT].damage = 1; weapon[W_SINGLE_SHOT].damage = 1;
weapon[W_SINGLE_SHOT].reload[0] = 15; weapon[W_SINGLE_SHOT].reload[0] = 15;
weapon[W_SINGLE_SHOT].speed = 10; weapon[W_SINGLE_SHOT].speed = 10;
weapon[W_SINGLE_SHOT].imageIndex[0] = 0; weapon[W_SINGLE_SHOT].imageIndex[0] = SP_PLASMA_GREEN;
weapon[W_SINGLE_SHOT].imageIndex[1] = 1; weapon[W_SINGLE_SHOT].imageIndex[1] = SP_PLASMA_RED;
weapon[W_SINGLE_SHOT].flags = 0; weapon[W_SINGLE_SHOT].flags = 0;
// Double Shot // Double Shot
@ -70,8 +61,8 @@ void initWeapons()
weapon[W_ROCKETS].reload[0] = 45; weapon[W_ROCKETS].reload[0] = 45;
weapon[W_ROCKETS].speed = 20; weapon[W_ROCKETS].speed = 20;
weapon[W_ROCKETS].flags = 0; weapon[W_ROCKETS].flags = 0;
weapon[W_ROCKETS].imageIndex[0] = 2; weapon[W_ROCKETS].imageIndex[0] = SP_ROCKET;
weapon[W_ROCKETS].imageIndex[1] = 3; weapon[W_ROCKETS].imageIndex[1] = SP_ROCKET_L;
// Double Rockets (uses ROCKETS as base) // Double Rockets (uses ROCKETS as base)
weapon[W_DOUBLE_ROCKETS] = weapon[W_ROCKETS]; weapon[W_DOUBLE_ROCKETS] = weapon[W_ROCKETS];
@ -85,8 +76,8 @@ void initWeapons()
weapon[W_MICRO_ROCKETS].reload[0] = 30; weapon[W_MICRO_ROCKETS].reload[0] = 30;
weapon[W_MICRO_ROCKETS].speed = 15; weapon[W_MICRO_ROCKETS].speed = 15;
weapon[W_MICRO_ROCKETS].flags = WF_VARIABLE_SPEED; weapon[W_MICRO_ROCKETS].flags = WF_VARIABLE_SPEED;
weapon[W_MICRO_ROCKETS].imageIndex[0] = 2; weapon[W_MICRO_ROCKETS].imageIndex[0] = SP_ROCKET;
weapon[W_MICRO_ROCKETS].imageIndex[1] = 3; weapon[W_MICRO_ROCKETS].imageIndex[1] = SP_ROCKET_L;
// Energy Ray // Energy Ray
weapon[W_ENERGYRAY].id = WT_ENERGYRAY; weapon[W_ENERGYRAY].id = WT_ENERGYRAY;
@ -94,6 +85,8 @@ void initWeapons()
weapon[W_ENERGYRAY].damage = 1; weapon[W_ENERGYRAY].damage = 1;
weapon[W_ENERGYRAY].reload[0] = 25; // reload for energy ray is never used weapon[W_ENERGYRAY].reload[0] = 25; // reload for energy ray is never used
weapon[W_ENERGYRAY].speed = 15; weapon[W_ENERGYRAY].speed = 15;
weapon[W_ENERGYRAY].imageIndex[0] = SP_PLASMA_RED;
weapon[W_ENERGYRAY].imageIndex[1] = SP_PLASMA_RED;
weapon[W_ENERGYRAY].flags = 0; weapon[W_ENERGYRAY].flags = 0;
// Laser // Laser
@ -102,8 +95,8 @@ void initWeapons()
weapon[W_LASER].damage = 3; weapon[W_LASER].damage = 3;
weapon[W_LASER].reload[0] = 1; weapon[W_LASER].reload[0] = 1;
weapon[W_LASER].speed = 10; weapon[W_LASER].speed = 10;
weapon[W_LASER].imageIndex[0] = 1; weapon[W_LASER].imageIndex[0] = SP_PLASMA_RED;
weapon[W_LASER].imageIndex[1] = 1; weapon[W_LASER].imageIndex[1] = SP_PLASMA_RED;
weapon[W_LASER].flags = 0; weapon[W_LASER].flags = 0;
// Beam up weapon // Beam up weapon
@ -113,8 +106,8 @@ void initWeapons()
weapon[W_CHARGER].reload[0] = 0; weapon[W_CHARGER].reload[0] = 0;
weapon[W_CHARGER].speed = 12; weapon[W_CHARGER].speed = 12;
weapon[W_CHARGER].flags = 0; weapon[W_CHARGER].flags = 0;
weapon[W_CHARGER].imageIndex[0] = 33; weapon[W_CHARGER].imageIndex[0] = SP_DIR_PLASMA_GREEN;
weapon[W_CHARGER].imageIndex[1] = 34; weapon[W_CHARGER].imageIndex[1] = SP_DIR_PLASMA_RED;
// Homing missile // Homing missile
weapon[W_HOMING_MISSILE].id = WT_ROCKET; weapon[W_HOMING_MISSILE].id = WT_ROCKET;
@ -123,15 +116,15 @@ void initWeapons()
weapon[W_HOMING_MISSILE].reload[0] = 35; weapon[W_HOMING_MISSILE].reload[0] = 35;
weapon[W_HOMING_MISSILE].speed = 10; weapon[W_HOMING_MISSILE].speed = 10;
weapon[W_HOMING_MISSILE].flags = WF_HOMING; weapon[W_HOMING_MISSILE].flags = WF_HOMING;
weapon[W_HOMING_MISSILE].imageIndex[0] = 4; weapon[W_HOMING_MISSILE].imageIndex[0] = SP_SMALL_EXPLOSION;
weapon[W_HOMING_MISSILE].imageIndex[1] = 4; weapon[W_HOMING_MISSILE].imageIndex[1] = SP_SMALL_EXPLOSION;
// Double homing missile // Double homing missile
weapon[W_DOUBLE_HOMING_MISSILES] = weapon[W_HOMING_MISSILE]; weapon[W_DOUBLE_HOMING_MISSILES] = weapon[W_HOMING_MISSILE];
weapon[W_DOUBLE_HOMING_MISSILES].ammo[0] = 2; weapon[W_DOUBLE_HOMING_MISSILES].ammo[0] = 2;
weapon[W_DOUBLE_HOMING_MISSILES].reload[0] = 65; weapon[W_DOUBLE_HOMING_MISSILES].reload[0] = 65;
weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[0] = 4; weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[0] = SP_SMALL_EXPLOSION;
weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[1] = 4; weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[1] = SP_SMALL_EXPLOSION;
// Micro homing missiles // Micro homing missiles
weapon[W_MICRO_HOMING_MISSILES].id = WT_ROCKET; weapon[W_MICRO_HOMING_MISSILES].id = WT_ROCKET;
@ -140,8 +133,8 @@ void initWeapons()
weapon[W_MICRO_HOMING_MISSILES].reload[0] = 65; weapon[W_MICRO_HOMING_MISSILES].reload[0] = 65;
weapon[W_MICRO_HOMING_MISSILES].speed = 3; weapon[W_MICRO_HOMING_MISSILES].speed = 3;
weapon[W_MICRO_HOMING_MISSILES].flags = WF_HOMING; weapon[W_MICRO_HOMING_MISSILES].flags = WF_HOMING;
weapon[W_MICRO_HOMING_MISSILES].imageIndex[0] = 4; weapon[W_MICRO_HOMING_MISSILES].imageIndex[0] = SP_SMALL_EXPLOSION;
weapon[W_MICRO_HOMING_MISSILES].imageIndex[1] = 4; weapon[W_MICRO_HOMING_MISSILES].imageIndex[1] = SP_SMALL_EXPLOSION;
// Aimed plasma bolt // Aimed plasma bolt
weapon[W_AIMED_SHOT].id = WT_DIRECTIONAL; weapon[W_AIMED_SHOT].id = WT_DIRECTIONAL;
@ -150,8 +143,8 @@ void initWeapons()
weapon[W_AIMED_SHOT].reload[0] = 15; weapon[W_AIMED_SHOT].reload[0] = 15;
weapon[W_AIMED_SHOT].speed = 0; weapon[W_AIMED_SHOT].speed = 0;
weapon[W_AIMED_SHOT].flags = WF_AIMED; weapon[W_AIMED_SHOT].flags = WF_AIMED;
weapon[W_AIMED_SHOT].imageIndex[0] = 33; weapon[W_AIMED_SHOT].imageIndex[0] = SP_DIR_PLASMA_GREEN;
weapon[W_AIMED_SHOT].imageIndex[1] = 34; weapon[W_AIMED_SHOT].imageIndex[1] = SP_DIR_PLASMA_RED;
// 3 way spread weapon // 3 way spread weapon
weapon[W_SPREADSHOT].id = WT_SPREAD; weapon[W_SPREADSHOT].id = WT_SPREAD;
@ -160,8 +153,8 @@ void initWeapons()
weapon[W_SPREADSHOT].reload[0] = 10; weapon[W_SPREADSHOT].reload[0] = 10;
weapon[W_SPREADSHOT].speed = 10; weapon[W_SPREADSHOT].speed = 10;
weapon[W_SPREADSHOT].flags = WF_SPREAD; weapon[W_SPREADSHOT].flags = WF_SPREAD;
weapon[W_SPREADSHOT].imageIndex[0] = 0; weapon[W_SPREADSHOT].imageIndex[0] = SP_PLASMA_GREEN;
weapon[W_SPREADSHOT].imageIndex[1] = 1; weapon[W_SPREADSHOT].imageIndex[1] = SP_PLASMA_RED;
// Sid's ion cannon like weapon // Sid's ion cannon like weapon
weapon[W_IONCANNON].id = WT_PLASMA; weapon[W_IONCANNON].id = WT_PLASMA;
@ -170,8 +163,8 @@ void initWeapons()
weapon[W_IONCANNON].reload[0] = 2; weapon[W_IONCANNON].reload[0] = 2;
weapon[W_IONCANNON].speed = 10; weapon[W_IONCANNON].speed = 10;
weapon[W_IONCANNON].flags = WF_DISABLE | WF_AIMED; weapon[W_IONCANNON].flags = WF_DISABLE | WF_AIMED;
weapon[W_IONCANNON].imageIndex[0] = 35; weapon[W_IONCANNON].imageIndex[0] = SP_ION;
weapon[W_IONCANNON].imageIndex[1] = 35; weapon[W_IONCANNON].imageIndex[1] = SP_ION;
// Directional Shock Missile - Used by Kline in final battle // Directional Shock Missile - Used by Kline in final battle
weapon[W_DIRSHOCKMISSILE].id = WT_ROCKET; weapon[W_DIRSHOCKMISSILE].id = WT_ROCKET;
@ -180,6 +173,6 @@ void initWeapons()
weapon[W_DIRSHOCKMISSILE].reload[0] = 60; weapon[W_DIRSHOCKMISSILE].reload[0] = 60;
weapon[W_DIRSHOCKMISSILE].speed = 0; weapon[W_DIRSHOCKMISSILE].speed = 0;
weapon[W_DIRSHOCKMISSILE].flags = WF_AIMED | WF_TIMEDEXPLOSION; weapon[W_DIRSHOCKMISSILE].flags = WF_AIMED | WF_TIMEDEXPLOSION;
weapon[W_DIRSHOCKMISSILE].imageIndex[0] = 4; weapon[W_DIRSHOCKMISSILE].imageIndex[0] = SP_SMALL_EXPLOSION;
weapon[W_DIRSHOCKMISSILE].imageIndex[1] = 4; weapon[W_DIRSHOCKMISSILE].imageIndex[1] = SP_SMALL_EXPLOSION;
} }

View File

@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern object weapon[MAX_WEAPONS]; extern object weapon[MAX_WEAPONS];
extern void setWeaponShapes();
extern void initWeapons(); extern void initWeapons();
#endif #endif