More reorganization.
This commit is contained in:
parent
1c833b1818
commit
9a211d773c
2
Makefile
2
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
|
||||
|
|
|
@ -44,9 +44,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#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
|
||||
|
|
57
src/game.cpp
57
src/game.cpp
|
@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
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();
|
||||
|
|
|
@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
extern Game game;
|
||||
|
||||
void game_init();
|
||||
void game_doStars();
|
||||
void game_doExplosions();
|
||||
int game_mainLoop();
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -722,7 +722,7 @@ int intermission()
|
|||
unBuffer();
|
||||
}
|
||||
|
||||
doStarfield();
|
||||
game_doStars();
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
|
|
|
@ -243,7 +243,7 @@ void doCutscene(int scene)
|
|||
updateScreen();
|
||||
unBuffer();
|
||||
getPlayerInput();
|
||||
doStarfield();
|
||||
game_doStars();
|
||||
game_doExplosions();
|
||||
|
||||
for (int i = 0 ; i < 15 ; i++)
|
||||
|
|
|
@ -281,7 +281,7 @@ int doTitle()
|
|||
|
||||
now = SDL_GetTicks();
|
||||
|
||||
doStarfield();
|
||||
game_doStars();
|
||||
game_doExplosions();
|
||||
|
||||
for (int i = 0 ; i < 15 ; i++)
|
||||
|
|
Loading…
Reference in New Issue