More reorganization.

This commit is contained in:
onpon4 2015-06-20 11:58:37 -04:00
parent 1c833b1818
commit 9a211d773c
10 changed files with 64 additions and 64 deletions

View File

@ -3,7 +3,7 @@ CXXFLAGS += `pkg-config --cflags sdl2 SDL2_image SDL2_mixer`
LIBS = `pkg-config --libs 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 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 PROG = starfighter
DOCS = docs/* DOCS = docs/*
DATA = data gfx sound music DATA = data gfx sound music

View File

@ -44,9 +44,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif #endif
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 4096 #define PATH_MAX 4096
#endif #endif
#define STARS_NUM 200
// Object Flags // Object Flags
#define FL_WEAPCO 1 #define FL_WEAPCO 1
#define FL_FRIEND 2 #define FL_FRIEND 2

View File

@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Game game; Game game;
static Star stars[STARS_NUM];
void game_init() void game_init()
{ {
game.system = 0; game.system = 0;
@ -124,6 +126,13 @@ void game_init()
player.weaponType[0] = W_PLAYER_WEAPON; player.weaponType[0] = W_PLAYER_WEAPON;
player.weaponType[1] = W_ROCKETS; 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(); initWeapons();
initMissions(); initMissions();
initPlanetMissions(game.system); 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 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 will travel in the direction that was defined when it was made. Its life will decreased
@ -2146,7 +2201,7 @@ int game_mainLoop()
} }
unBuffer(); unBuffer();
doStarfield(); game_doStars();
game_doCollectables(); game_doCollectables();
game_doBullets(); game_doBullets();
game_doAliens(); game_doAliens();

View File

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern Game game; extern Game game;
void game_init(); void game_init();
void game_doStars();
void game_doExplosions(); void game_doExplosions();
int game_mainLoop(); int game_mainLoop();

View File

@ -21,8 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Starfighter.h" #include "Starfighter.h"
Star star[200];
static unsigned long frameLimit; static unsigned long frameLimit;
static int thirds; static int thirds;
@ -685,49 +683,3 @@ SDL_Surface *loadImage(const char *filename)
return setTransparent(newImage); 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);
}
}

View File

@ -20,8 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef GRAPHICS_H #ifndef GRAPHICS_H
#define GRAPHICS_H #define GRAPHICS_H
extern Star star[200];
extern SDL_Window *window; extern SDL_Window *window;
extern SDL_Renderer *renderer; extern SDL_Renderer *renderer;
extern SDL_Texture *texture; extern SDL_Texture *texture;
@ -69,6 +67,5 @@ extern void createMessageBox(SDL_Surface *face, const char *message, signed char
extern void freeGraphics(); extern void freeGraphics();
extern SDL_Surface *loadImage(const char *filename); extern SDL_Surface *loadImage(const char *filename);
extern void doStarfield();
#endif #endif

View File

@ -31,13 +31,6 @@ void initVars()
{ {
srand(time(NULL)); 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) if (engine.useAudio)
{ {
Mix_Volume(-1, 100); Mix_Volume(-1, 100);

View File

@ -722,7 +722,7 @@ int intermission()
unBuffer(); unBuffer();
} }
doStarfield(); game_doStars();
r.x = 0; r.x = 0;
r.y = 0; r.y = 0;

View File

@ -243,7 +243,7 @@ void doCutscene(int scene)
updateScreen(); updateScreen();
unBuffer(); unBuffer();
getPlayerInput(); getPlayerInput();
doStarfield(); game_doStars();
game_doExplosions(); game_doExplosions();
for (int i = 0 ; i < 15 ; i++) for (int i = 0 ; i < 15 ; i++)

View File

@ -281,7 +281,7 @@ int doTitle()
now = SDL_GetTicks(); now = SDL_GetTicks();
doStarfield(); game_doStars();
game_doExplosions(); game_doExplosions();
for (int i = 0 ; i < 15 ; i++) for (int i = 0 ; i < 15 ; i++)