From 4be080225b358ba927f684ffc8233a4001da0306 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Tue, 5 Jan 2016 22:12:29 -0500 Subject: [PATCH] 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. --- src/bullet.cpp | 4 +-- src/cargo.cpp | 2 +- src/collectable.cpp | 28 +++++++-------- src/defs.h | 74 ++++++++++++++++++++++++++++++++++------ src/engine.cpp | 2 +- src/explosion.cpp | 4 +-- src/game.cpp | 64 ++++++++++++++++++---------------- src/gfx.cpp | 10 +++--- src/gfx.h | 4 +-- src/loadSave.cpp | 2 ++ src/resources.cpp | 83 ++++++++++++++++++++++++++++++++++----------- src/ship.cpp | 2 +- src/weapons.cpp | 63 +++++++++++++++------------------- src/weapons.h | 1 - 14 files changed, 219 insertions(+), 124 deletions(-) diff --git a/src/bullet.cpp b/src/bullet.cpp index 54a1d1c..6faeb37 100644 --- a/src/bullet.cpp +++ b/src/bullet.cpp @@ -22,7 +22,7 @@ along with this program. If not, see . void bullet_add(object *theWeapon, object *attacker, int y, int dy) { object *bullet; - signed char imageIndex; + int imageIndex; int tempX, tempY, steps; bullet = new object; @@ -131,7 +131,7 @@ void bullet_add(object *theWeapon, object *attacker, int y, int dy) { bullet->dx = 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; diff --git a/src/cargo.cpp b/src/cargo.cpp index 96b8eab..9dacc8e 100644 --- a/src/cargo.cpp +++ b/src/cargo.cpp @@ -58,7 +58,7 @@ object *cargo_add(object *owner, int cargoType) cargo[index].dx = 0; cargo[index].dy = 0; cargo[index].collectType = cargoType; - cargo[index].image[0] = gfx_sprites[32]; + cargo[index].image[0] = gfx_sprites[SP_CARGO]; if (cargoType == P_PHOEBE) cargo[index].image[0] = gfx_shipSprites[SS_FRIEND]; diff --git a/src/collectable.cpp b/src/collectable.cpp index e8b55e1..d349d49 100644 --- a/src/collectable.cpp +++ b/src/collectable.cpp @@ -153,52 +153,52 @@ void collectable_add(float x, float y, int type, int value, int life) switch(type) { case P_CASH: - collectable->image = gfx_sprites[24]; + collectable->image = gfx_sprites[SP_PICKUP_MONEY]; break; case P_ROCKET: - collectable->image = gfx_sprites[49]; + collectable->image = gfx_sprites[SP_PICKUP_ROCKETS]; break; case P_PLASMA_AMMO: - collectable->image = gfx_sprites[25]; + collectable->image = gfx_sprites[SP_PICKUP_PLASMA]; break; case P_SHIELD: - collectable->image = gfx_sprites[26]; + collectable->image = gfx_sprites[SP_PICKUP_SHIELD]; break; case P_PLASMA_SHOT: - collectable->image = gfx_sprites[27]; + collectable->image = gfx_sprites[SP_PICKUP_PLASMA_OUTPUT]; break; case P_PLASMA_RATE: - collectable->image = gfx_sprites[28]; + collectable->image = gfx_sprites[SP_PICKUP_PLASMA_RATE]; break; case P_PLASMA_DAMAGE: - collectable->image = gfx_sprites[29]; + collectable->image = gfx_sprites[SP_PICKUP_PLASMA_POWER]; break; case P_CARGO: - collectable->image = gfx_sprites[32]; + collectable->image = gfx_sprites[SP_CARGO]; break; case P_SUPER: - collectable->image = gfx_sprites[50]; + collectable->image = gfx_sprites[SP_SUPERCHARGE]; break; case P_MINE: - collectable->image = gfx_sprites[31]; + collectable->image = gfx_sprites[SP_MINE]; break; case P_SLAVES: case P_ESCAPEPOD: - collectable->image = gfx_sprites[45]; + collectable->image = gfx_sprites[SP_ESCAPE_POD]; break; case P_ORE: - collectable->image = gfx_sprites[46 + rand() % 3]; + collectable->image = gfx_sprites[RANDRANGE(SP_ORE, SP_ORE_L)]; break; } @@ -234,8 +234,8 @@ void collectable_explode(collectables *collectable) audio_playSound(SFX_EXPLOSION, collectable->x); for (int i = 0 ; i < 10 ; i++) - explosion_add(collectable->x + rand() % 25 - rand() % 25, - collectable->y + rand() % 25 - rand() % 25, E_BIG_EXPLOSION); + explosion_add(RANDRANGE(collectable->x - 25, collectable->x + 25), + RANDRANGE(collectable->y - 25, collectable->x + 25), SP_BIG_EXPLOSION); player_checkShockDamage(collectable->x, collectable->y); } diff --git a/src/defs.h b/src/defs.h index 9d3ccc1..f08dec0 100644 --- a/src/defs.h +++ b/src/defs.h @@ -34,7 +34,7 @@ along with this program. If not, see . ((x) + (y) < (a) ? ((b) - (a)) : 0) + \ ((x) + (y) > (b) ? ((a) - (b)) : 0)) #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 @@ -85,13 +85,6 @@ along with this program. If not, see . #define FL_HASMINIMUMSPEED 2097152L #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 #define WF_SPREAD 4 #define WF_SCATTER 8 @@ -105,8 +98,6 @@ along with this program. If not, see . #define WF_TIMEDEXPLOSION 2048 #define MAX_WEAPONS 20 -#define MAX_SPRITES 100 -#define MAX_FONTSPRITES 6 #define MAX_CARGO 20 #define MAX_INFOLINES 3 #define MAX_EVENTS 20 @@ -318,6 +309,66 @@ enum { SP_PLANET_BLUE, SP_PLANET_RED, 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 }; @@ -550,7 +601,8 @@ enum { FONT_YELLOW, FONT_GREEN, FONT_CYAN, - FONT_OUTLINE // a dark blue color + FONT_OUTLINE, // a dark blue color + FONT_MAX }; // Sounds diff --git a/src/engine.cpp b/src/engine.cpp index b562768..a6ddf44 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -266,7 +266,7 @@ void engine_cleanup() delete(engine.collectableHead); delete(screen_bufferHead); - for (int i = 0 ; i < MAX_FONTSPRITES ; i++) + for (int i = 0 ; i < FONT_MAX ; i++) { if (gfx_fontSprites[i] != NULL) SDL_FreeSurface(gfx_fontSprites[i]); diff --git a/src/explosion.cpp b/src/explosion.cpp index 67872f9..064cc09 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -47,12 +47,12 @@ void explosion_add(float x, float y, int type) */ void explosion_addEngine(object *craft) { - if (rand() % 2 == 0) + if (CHANCE(0.5)) return; float x = craft->x + (craft->engineX * craft->face); float y = craft->y + craft->engineY; y += RANDRANGE(-3, 3); - explosion_add(x, y, E_TINY_EXPLOSION); + explosion_add(x, y, SP_TINY_EXPLOSION); } diff --git a/src/game.cpp b/src/game.cpp index b15ee8b..740b84e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -521,11 +521,11 @@ static void game_doBullets() 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) { - explosion_add(bullet->x, bullet->y, E_TINY_EXPLOSION); + explosion_add(bullet->x, bullet->y, SP_TINY_EXPLOSION); } if ((bullet->flags & WF_AIMED)) @@ -637,7 +637,7 @@ static void game_doBullets() for (int i = 0 ; i < 10 ; i++) explosion_add(bullet->x + RANDRANGE(-35, 35), bullet->y + RANDRANGE(-35, 35), - E_BIG_EXPLOSION); + SP_BIG_EXPLOSION); } } else @@ -647,9 +647,9 @@ static void game_doBullets() } if (bullet->id == WT_ROCKET) - explosion_add(bullet->x, bullet->y, E_BIG_EXPLOSION); + explosion_add(bullet->x, bullet->y, SP_BIG_EXPLOSION); 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); for (int i = 0 ; i < 10 ; i++) explosion_add(bullet->x + RANDRANGE(-35, 35), - bullet->y + RANDRANGE(-35, 35), E_BIG_EXPLOSION); + bullet->y + RANDRANGE(-35, 35), SP_BIG_EXPLOSION); } } else @@ -700,9 +700,9 @@ static void game_doBullets() audio_playSound(SFX_HIT, player.x); if (bullet->id == WT_ROCKET) - explosion_add(bullet->x, bullet->y, E_BIG_EXPLOSION); + explosion_add(bullet->x, bullet->y, SP_BIG_EXPLOSION); 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])) { 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); if (cargo[j].collectType != P_PHOEBE) { @@ -726,7 +726,7 @@ static void game_doBullets() for (int i = 0 ; i < 10 ; i++) explosion_add(cargo[j].x + RANDRANGE(-15, 15), cargo[j].y + RANDRANGE(-15, 15), - E_BIG_EXPLOSION); + SP_BIG_EXPLOSION); updateMissionRequirements(M_PROTECT_PICKUP, P_CARGO, 1); } @@ -791,7 +791,7 @@ static void game_doBullets() audio_playSound(SFX_EXPLOSION, bullet->x); for (int i = 0 ; i < 10 ; i++) 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); } @@ -1092,7 +1092,7 @@ static void game_doAliens() if ((rand() % 10) == 0) explosion_add(aliens[i].x + (rand() % aliens[i].image[0]->w), 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); explosion_add(aliens[i].x + (rand() % aliens[i].image[0]->w), aliens[i].y + (rand() % aliens[i].image[0]->h), - E_BIG_EXPLOSION); + SP_BIG_EXPLOSION); } if (aliens[i].shield < aliens[i].deathCounter) { @@ -1399,7 +1399,7 @@ static void game_doPlayer() if ((player.maxShield > 1) && (player.shield <= engine.lowShield) && (rand() % 5 < 1)) explosion_add(player.x + RANDRANGE(-10, 10), - player.y + RANDRANGE(-10, 20), E_SMOKE); + player.y + RANDRANGE(-10, 20), SP_SMOKE); } 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; if ((rand() % 3) == 0) 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) game_addDebris((int)player.x, (int)player.y, player.maxShield); } @@ -1481,7 +1481,7 @@ static void game_doCargo() // draw the chain link line 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; chainY -= dy; } @@ -1508,7 +1508,7 @@ static void game_doDebris() debris->x += debris->dx; 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) @@ -1549,7 +1549,7 @@ void game_doExplosions() screen_blit(explosion->image[0], (int)explosion->x, (int)explosion->y); - if(rand() % 7 == 0) + if(CHANCE(1. / 7.)) { explosion->thinktime -= 7; @@ -1602,12 +1602,15 @@ static void game_doArrow(int i) int arrow; - if (sxy == sx) { - arrow = x < screen->w / 2 ? 42 : 38; + if (sxy == sx) + { + arrow = x < screen->w / 2 ? SP_ARROW_WEST : SP_ARROW_EAST; x -= x > screen->w / 2 ? gfx_sprites[arrow]->w : 0; 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; 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) return; - 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; - } else { - 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; + if (sxy == sx) + { + x -= x > screen->w / 2 ? 5 + gfx_sprites[SP_TARGET]->w : -5 - gfx_sprites[arrow]->w; + y -= (gfx_sprites[SP_TARGET]->h - gfx_sprites[arrow]->h) / 2; + } + 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() diff --git a/src/gfx.cpp b/src/gfx.cpp index 05ce520..3ccdc19 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -22,10 +22,10 @@ along with this program. If not, see . #include "Starfighter.h" 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_shipSprites[SS_MAX]; -SDL_Surface *gfx_fontSprites[MAX_FONTSPRITES]; +SDL_Surface *gfx_fontSprites[FONT_MAX]; SDL_Surface *gfx_shopSprites[SHOP_S_MAX]; textObject gfx_textSprites[TS_MAX]; SDL_Surface *gfx_messageBox; @@ -36,7 +36,7 @@ void gfx_init() screen_bufferHead->next = NULL; screen_bufferTail = screen_bufferHead; - for (int i = 0 ; i < MAX_SPRITES ; i++) + for (int i = 0 ; i < SP_MAX ; i++) gfx_sprites[i] = NULL; for (int i = 0 ; i < SS_MAX ; i++) @@ -48,7 +48,7 @@ void gfx_init() for (int i = 0 ; i < SHOP_S_MAX ; i++) 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_background = NULL; @@ -444,7 +444,7 @@ SDL_Surface *gfx_loadImage(const char *filename) void gfx_free() { - for (int i = 0 ; i < MAX_SPRITES ; i++) + for (int i = 0 ; i < SP_MAX ; i++) { if (gfx_sprites[i] != NULL) { diff --git a/src/gfx.h b/src/gfx.h index e2d9917..faf89d1 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -23,10 +23,10 @@ along with this program. If not, see . #include "Starfighter.h" 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_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 textObject gfx_textSprites[TS_MAX]; extern SDL_Surface *gfx_messageBox; diff --git a/src/loadSave.cpp b/src/loadSave.cpp index 845cef9..3b4e243 100644 --- a/src/loadSave.cpp +++ b/src/loadSave.cpp @@ -116,6 +116,8 @@ bool loadGame(int slot) game.difficulty = DIFFICULTY_NORMAL; 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; // Re-init all the planets in this system... diff --git a/src/resources.cpp b/src/resources.cpp index dd3b4b4..3943b40 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -32,9 +32,6 @@ void loadBackground(const char *filename) void loadGameGraphics() { - int index; - char string[75] = ""; - FILE *fp; Uint32 *p32; Uint16 *p16; Uint8 *p8; @@ -177,16 +174,58 @@ void loadGameGraphics() SDL_MapRGB(gfx_shipSprites[i]->format, 0, 0, 0)); } - strcpy(string, "data/resources_all.dat"); - - fp = fopen(string, "rb"); - - while (fscanf(fp, "%d %s", &index, string) == 2) - { - gfx_sprites[index] = gfx_loadImage(string); - } - - fclose(fp); + // Other sprites + gfx_sprites[SP_PLASMA_GREEN] = gfx_loadImage("gfx/plasmaGreen.png"); + gfx_sprites[SP_PLASMA_RED] = gfx_loadImage("gfx/plasmaRed.png"); + gfx_sprites[SP_DIR_PLASMA_GREEN] = gfx_loadImage("gfx/greenDir.png"); + gfx_sprites[SP_DIR_PLASMA_RED] = gfx_loadImage("gfx/redDir.png"); + gfx_sprites[SP_ROCKET] = gfx_loadImage("gfx/rocket1.png"); + 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"); + 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]); @@ -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; - for (int i = 0 ; i < MAX_FONTSPRITES ; i++) + for (int i = 0 ; i < FONT_MAX ; i++) { image = IMG_Load("gfx/smallFont.png"); @@ -224,19 +267,19 @@ void loadFont() switch(i) { - case 1: + case FONT_RED: SDL_SetSurfaceColorMod(image, 255, 0, 0); break; - case 2: + case FONT_YELLOW: SDL_SetSurfaceColorMod(image, 255, 255, 0); break; - case 3: + case FONT_GREEN: SDL_SetSurfaceColorMod(image, 0, 255, 0); break; - case 4: + case FONT_CYAN: SDL_SetSurfaceColorMod(image, 0, 255, 255); break; - case 5: + case FONT_OUTLINE: SDL_SetSurfaceColorMod(image, 0, 0, 10); break; } diff --git a/src/ship.cpp b/src/ship.cpp index 97be05f..ed877c4 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -176,7 +176,7 @@ void ship_fireRay(object *ship) } 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); if (player.shield < 1) { diff --git a/src/weapons.cpp b/src/weapons.cpp index 0842ae4..f268072 100644 --- a/src/weapons.cpp +++ b/src/weapons.cpp @@ -21,15 +21,6 @@ along with this program. If not, see . 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. */ @@ -41,8 +32,8 @@ void initWeapons() weapon[W_PLAYER_WEAPON].damage = 1; weapon[W_PLAYER_WEAPON].reload[0] = 15; weapon[W_PLAYER_WEAPON].speed = 10; - weapon[W_PLAYER_WEAPON].imageIndex[0] = 0; - weapon[W_PLAYER_WEAPON].imageIndex[1] = 0; + weapon[W_PLAYER_WEAPON].imageIndex[0] = SP_PLASMA_GREEN; + weapon[W_PLAYER_WEAPON].imageIndex[1] = SP_PLASMA_GREEN; weapon[W_PLAYER_WEAPON].flags = WF_SPREAD; // Single Shot @@ -51,8 +42,8 @@ void initWeapons() weapon[W_SINGLE_SHOT].damage = 1; weapon[W_SINGLE_SHOT].reload[0] = 15; weapon[W_SINGLE_SHOT].speed = 10; - weapon[W_SINGLE_SHOT].imageIndex[0] = 0; - weapon[W_SINGLE_SHOT].imageIndex[1] = 1; + weapon[W_SINGLE_SHOT].imageIndex[0] = SP_PLASMA_GREEN; + weapon[W_SINGLE_SHOT].imageIndex[1] = SP_PLASMA_RED; weapon[W_SINGLE_SHOT].flags = 0; // Double Shot @@ -70,8 +61,8 @@ void initWeapons() weapon[W_ROCKETS].reload[0] = 45; weapon[W_ROCKETS].speed = 20; weapon[W_ROCKETS].flags = 0; - weapon[W_ROCKETS].imageIndex[0] = 2; - weapon[W_ROCKETS].imageIndex[1] = 3; + weapon[W_ROCKETS].imageIndex[0] = SP_ROCKET; + weapon[W_ROCKETS].imageIndex[1] = SP_ROCKET_L; // Double Rockets (uses ROCKETS as base) weapon[W_DOUBLE_ROCKETS] = weapon[W_ROCKETS]; @@ -85,8 +76,8 @@ void initWeapons() weapon[W_MICRO_ROCKETS].reload[0] = 30; weapon[W_MICRO_ROCKETS].speed = 15; weapon[W_MICRO_ROCKETS].flags = WF_VARIABLE_SPEED; - weapon[W_MICRO_ROCKETS].imageIndex[0] = 2; - weapon[W_MICRO_ROCKETS].imageIndex[1] = 3; + weapon[W_MICRO_ROCKETS].imageIndex[0] = SP_ROCKET; + weapon[W_MICRO_ROCKETS].imageIndex[1] = SP_ROCKET_L; // Energy Ray weapon[W_ENERGYRAY].id = WT_ENERGYRAY; @@ -94,6 +85,8 @@ void initWeapons() weapon[W_ENERGYRAY].damage = 1; weapon[W_ENERGYRAY].reload[0] = 25; // reload for energy ray is never used 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; // Laser @@ -102,8 +95,8 @@ void initWeapons() weapon[W_LASER].damage = 3; weapon[W_LASER].reload[0] = 1; weapon[W_LASER].speed = 10; - weapon[W_LASER].imageIndex[0] = 1; - weapon[W_LASER].imageIndex[1] = 1; + weapon[W_LASER].imageIndex[0] = SP_PLASMA_RED; + weapon[W_LASER].imageIndex[1] = SP_PLASMA_RED; weapon[W_LASER].flags = 0; // Beam up weapon @@ -113,8 +106,8 @@ void initWeapons() weapon[W_CHARGER].reload[0] = 0; weapon[W_CHARGER].speed = 12; weapon[W_CHARGER].flags = 0; - weapon[W_CHARGER].imageIndex[0] = 33; - weapon[W_CHARGER].imageIndex[1] = 34; + weapon[W_CHARGER].imageIndex[0] = SP_DIR_PLASMA_GREEN; + weapon[W_CHARGER].imageIndex[1] = SP_DIR_PLASMA_RED; // Homing missile weapon[W_HOMING_MISSILE].id = WT_ROCKET; @@ -123,15 +116,15 @@ void initWeapons() weapon[W_HOMING_MISSILE].reload[0] = 35; weapon[W_HOMING_MISSILE].speed = 10; weapon[W_HOMING_MISSILE].flags = WF_HOMING; - weapon[W_HOMING_MISSILE].imageIndex[0] = 4; - weapon[W_HOMING_MISSILE].imageIndex[1] = 4; + weapon[W_HOMING_MISSILE].imageIndex[0] = SP_SMALL_EXPLOSION; + weapon[W_HOMING_MISSILE].imageIndex[1] = SP_SMALL_EXPLOSION; // Double homing missile weapon[W_DOUBLE_HOMING_MISSILES] = weapon[W_HOMING_MISSILE]; weapon[W_DOUBLE_HOMING_MISSILES].ammo[0] = 2; weapon[W_DOUBLE_HOMING_MISSILES].reload[0] = 65; - weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[0] = 4; - weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[1] = 4; + weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[0] = SP_SMALL_EXPLOSION; + weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[1] = SP_SMALL_EXPLOSION; // Micro homing missiles 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].speed = 3; weapon[W_MICRO_HOMING_MISSILES].flags = WF_HOMING; - weapon[W_MICRO_HOMING_MISSILES].imageIndex[0] = 4; - weapon[W_MICRO_HOMING_MISSILES].imageIndex[1] = 4; + weapon[W_MICRO_HOMING_MISSILES].imageIndex[0] = SP_SMALL_EXPLOSION; + weapon[W_MICRO_HOMING_MISSILES].imageIndex[1] = SP_SMALL_EXPLOSION; // Aimed plasma bolt weapon[W_AIMED_SHOT].id = WT_DIRECTIONAL; @@ -150,8 +143,8 @@ void initWeapons() weapon[W_AIMED_SHOT].reload[0] = 15; weapon[W_AIMED_SHOT].speed = 0; weapon[W_AIMED_SHOT].flags = WF_AIMED; - weapon[W_AIMED_SHOT].imageIndex[0] = 33; - weapon[W_AIMED_SHOT].imageIndex[1] = 34; + weapon[W_AIMED_SHOT].imageIndex[0] = SP_DIR_PLASMA_GREEN; + weapon[W_AIMED_SHOT].imageIndex[1] = SP_DIR_PLASMA_RED; // 3 way spread weapon weapon[W_SPREADSHOT].id = WT_SPREAD; @@ -160,8 +153,8 @@ void initWeapons() weapon[W_SPREADSHOT].reload[0] = 10; weapon[W_SPREADSHOT].speed = 10; weapon[W_SPREADSHOT].flags = WF_SPREAD; - weapon[W_SPREADSHOT].imageIndex[0] = 0; - weapon[W_SPREADSHOT].imageIndex[1] = 1; + weapon[W_SPREADSHOT].imageIndex[0] = SP_PLASMA_GREEN; + weapon[W_SPREADSHOT].imageIndex[1] = SP_PLASMA_RED; // Sid's ion cannon like weapon weapon[W_IONCANNON].id = WT_PLASMA; @@ -170,8 +163,8 @@ void initWeapons() weapon[W_IONCANNON].reload[0] = 2; weapon[W_IONCANNON].speed = 10; weapon[W_IONCANNON].flags = WF_DISABLE | WF_AIMED; - weapon[W_IONCANNON].imageIndex[0] = 35; - weapon[W_IONCANNON].imageIndex[1] = 35; + weapon[W_IONCANNON].imageIndex[0] = SP_ION; + weapon[W_IONCANNON].imageIndex[1] = SP_ION; // Directional Shock Missile - Used by Kline in final battle weapon[W_DIRSHOCKMISSILE].id = WT_ROCKET; @@ -180,6 +173,6 @@ void initWeapons() weapon[W_DIRSHOCKMISSILE].reload[0] = 60; weapon[W_DIRSHOCKMISSILE].speed = 0; weapon[W_DIRSHOCKMISSILE].flags = WF_AIMED | WF_TIMEDEXPLOSION; - weapon[W_DIRSHOCKMISSILE].imageIndex[0] = 4; - weapon[W_DIRSHOCKMISSILE].imageIndex[1] = 4; + weapon[W_DIRSHOCKMISSILE].imageIndex[0] = SP_SMALL_EXPLOSION; + weapon[W_DIRSHOCKMISSILE].imageIndex[1] = SP_SMALL_EXPLOSION; } diff --git a/src/weapons.h b/src/weapons.h index 7d9f2c4..4170c0f 100644 --- a/src/weapons.h +++ b/src/weapons.h @@ -22,7 +22,6 @@ along with this program. If not, see . extern object weapon[MAX_WEAPONS]; -extern void setWeaponShapes(); extern void initWeapons(); #endif