diff --git a/Makefile b/Makefile
index d52b8a8..c3c46bb 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ CXXFLAGS += `pkg-config --cflags sdl2 SDL2_image SDL2_mixer`
LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer`
OBJS = alien.o audio.o bullet.o cargo.o collectable.o colors.o engine.o explosion.o game.o graphics.o init.o intermission.o loadSave.o messages.o misc.o missions.o player.o resources.o script.o ship.o shop.o Starfighter.o title.o weapons.o
-VERSION = 1.4
+VERSION = 1.4.1-dev
PROG = starfighter
DOCS = docs/*
DATA = data gfx sound music
diff --git a/src/defs.h b/src/defs.h
index c66b4aa..432daec 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -44,9 +44,11 @@ along with this program. If not, see .
#endif
#ifndef PATH_MAX
-#define PATH_MAX 4096
+#define PATH_MAX 4096
#endif
+#define STARS_NUM 200
+
// Object Flags
#define FL_WEAPCO 1
#define FL_FRIEND 2
diff --git a/src/game.cpp b/src/game.cpp
index 0e26b44..2367cfe 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -21,6 +21,8 @@ along with this program. If not, see .
Game game;
+static Star stars[STARS_NUM];
+
void game_init()
{
game.system = 0;
@@ -124,6 +126,13 @@ void game_init()
player.weaponType[0] = W_PLAYER_WEAPON;
player.weaponType[1] = W_ROCKETS;
+ for (int i = 0 ; i < STARS_NUM ; i++)
+ {
+ stars[i].x = rand() % screen->w;
+ stars[i].y = rand() % screen->h;
+ stars[i].speed = 1 + (rand() % 3);
+ }
+
initWeapons();
initMissions();
initPlanetMissions(game.system);
@@ -165,6 +174,52 @@ static void game_addDebris(int x, int y, int amount)
}
}
+/*
+Simply draws the stars in their positions on screen and moves
+them around.
+*/
+void game_doStars()
+{
+ /* Lock the screen for direct access to the pixels */
+ if (SDL_MUSTLOCK(screen))
+ {
+ if (SDL_LockSurface(screen) < 0 )
+ showErrorAndExit(2, "");
+ }
+
+ int color = 0;
+
+ SDL_Rect r;
+
+ for (int i = 0 ; i < STARS_NUM ; i++)
+ {
+ if (stars[i].speed == 3)
+ color = white;
+ else if (stars[i].speed == 2)
+ color = lightGrey;
+ else if (stars[i].speed == 1)
+ color = darkGrey;
+
+ WRAP_ADD(stars[i].x, (engine.ssx + engine.smx) * stars[i].speed, 0,
+ screen->w - 1);
+ WRAP_ADD(stars[i].y, (engine.ssy + engine.smy) * stars[i].speed, 0,
+ screen->h - 1);
+
+ putpixel(screen, (int)stars[i].x, (int)stars[i].y, color);
+ r.x = (int)stars[i].x;
+ r.y = (int)stars[i].y;
+ r.w = 1;
+ r.h = 1;
+
+ addBuffer(r.x, r.y, r.w, r.h);
+ }
+
+ if (SDL_MUSTLOCK(screen))
+ {
+ SDL_UnlockSurface(screen);
+ }
+}
+
/*
Loops through the currently active collectables (in a linked list). The collectable
will travel in the direction that was defined when it was made. Its life will decreased
@@ -2146,7 +2201,7 @@ int game_mainLoop()
}
unBuffer();
- doStarfield();
+ game_doStars();
game_doCollectables();
game_doBullets();
game_doAliens();
diff --git a/src/game.h b/src/game.h
index 0e05f46..911d4f6 100644
--- a/src/game.h
+++ b/src/game.h
@@ -23,6 +23,7 @@ along with this program. If not, see .
extern Game game;
void game_init();
+void game_doStars();
void game_doExplosions();
int game_mainLoop();
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 79de564..66e7cd2 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -21,8 +21,6 @@ along with this program. If not, see .
#include "Starfighter.h"
-Star star[200];
-
static unsigned long frameLimit;
static int thirds;
@@ -685,49 +683,3 @@ SDL_Surface *loadImage(const char *filename)
return setTransparent(newImage);
}
-
-/*
-Simply draws the stars in their positions on screen and moves
-them around.
-*/
-void doStarfield()
-{
- /* Lock the screen for direct access to the pixels */
- if (SDL_MUSTLOCK(screen))
- {
- if (SDL_LockSurface(screen) < 0 )
- showErrorAndExit(2, "");
- }
-
- int color = 0;
-
- SDL_Rect r;
-
- for (int i = 0 ; i < 200 ; i++)
- {
- if (star[i].speed == 3)
- color = white;
- else if (star[i].speed == 2)
- color = lightGrey;
- else if (star[i].speed == 1)
- color = darkGrey;
-
- WRAP_ADD(star[i].x, (engine.ssx + engine.smx) * star[i].speed, 0,
- screen->w - 1);
- WRAP_ADD(star[i].y, (engine.ssy + engine.smy) * star[i].speed, 0,
- screen->h - 1);
-
- putpixel(screen, (int)star[i].x, (int)star[i].y, color);
- r.x = (int)star[i].x;
- r.y = (int)star[i].y;
- r.w = 1;
- r.h = 1;
-
- addBuffer(r.x, r.y, r.w, r.h);
- }
-
- if (SDL_MUSTLOCK(screen))
- {
- SDL_UnlockSurface(screen);
- }
-}
diff --git a/src/graphics.h b/src/graphics.h
index 8353951..3bb70cf 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -20,8 +20,6 @@ along with this program. If not, see .
#ifndef GRAPHICS_H
#define GRAPHICS_H
-extern Star star[200];
-
extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern SDL_Texture *texture;
@@ -69,6 +67,5 @@ extern void createMessageBox(SDL_Surface *face, const char *message, signed char
extern void freeGraphics();
extern SDL_Surface *loadImage(const char *filename);
-extern void doStarfield();
#endif
diff --git a/src/init.cpp b/src/init.cpp
index 89a2665..790b305 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -31,13 +31,6 @@ void initVars()
{
srand(time(NULL));
- for (int i = 0 ; i < (int)(screen->w * screen->h / 2400) ; i++)
- {
- star[i].x = rand() % screen->w;
- star[i].y = rand() % screen->h;
- star[i].speed = 1 + (rand() % 3);
- }
-
if (engine.useAudio)
{
Mix_Volume(-1, 100);
diff --git a/src/intermission.cpp b/src/intermission.cpp
index cba6975..866b7bc 100644
--- a/src/intermission.cpp
+++ b/src/intermission.cpp
@@ -722,7 +722,7 @@ int intermission()
unBuffer();
}
- doStarfield();
+ game_doStars();
r.x = 0;
r.y = 0;
diff --git a/src/script.cpp b/src/script.cpp
index a2bc6fa..461e119 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -243,7 +243,7 @@ void doCutscene(int scene)
updateScreen();
unBuffer();
getPlayerInput();
- doStarfield();
+ game_doStars();
game_doExplosions();
for (int i = 0 ; i < 15 ; i++)
diff --git a/src/title.cpp b/src/title.cpp
index b4506b3..aa57c91 100644
--- a/src/title.cpp
+++ b/src/title.cpp
@@ -281,7 +281,7 @@ int doTitle()
now = SDL_GetTicks();
- doStarfield();
+ game_doStars();
game_doExplosions();
for (int i = 0 ; i < 15 ; i++)