Merge branch 'master' of git://git.code.sf.net/u/onpon4/starfighter

This commit is contained in:
Guus Sliepen 2012-03-14 19:50:13 +01:00
commit 070d67e91d
11 changed files with 90 additions and 81 deletions

View File

@ -26,19 +26,19 @@ object enemy[MAX_ALIENS];
static bool placeAlien(object *theEnemy)
{
if (rand() % 2 == 0)
theEnemy->x = rrand(800, 1600);
theEnemy->x = rrand(screen->w, screen->w * 2);
else
theEnemy->x = rrand(-800, 0);
theEnemy->x = rrand(-screen->w, 0);
if (rand() % 2 == 0)
theEnemy->y = rrand(600, 1200);
theEnemy->y = rrand(screen->h, screen->h * 2);
else
theEnemy->y = rrand(-600, 0);
theEnemy->y = rrand(-screen->h, 0);
if (currentGame.area == 24)
{
theEnemy->x = 800;
theEnemy->y = rrand(200, 400);
theEnemy->x = screen->w;
theEnemy->y = rrand(screen->h / 3, (2 * screen->h) / 3);
}
for (int i = 0 ; i < MAX_ALIENS ; i++)
@ -396,8 +396,8 @@ static void getPreDefinedAliens()
if (currentGame.area == 5)
{
enemy[WC_BOSS].target = &player;
enemy[WC_BOSS].x = -400;
enemy[WC_BOSS].y = 300;
enemy[WC_BOSS].x = -screen->w / 2;
enemy[WC_BOSS].y = screen->h / 2;
enemy[13].owner = &enemy[WC_BOSS];
enemy[13].target = &player;
@ -412,8 +412,8 @@ static void getPreDefinedAliens()
else if ((currentGame.area == 11) || (currentGame.area == 14))
{
enemy[WC_BOSS].target = &player;
enemy[WC_BOSS].x = -400;
enemy[WC_BOSS].y = 300;
enemy[WC_BOSS].x = -screen->w / 2;
enemy[WC_BOSS].y = screen->h / 2;
enemy[13].owner = &enemy[WC_BOSS];
enemy[13].target = &player;
@ -475,14 +475,14 @@ static void addFriendly(int type)
enemy[type].active = true;
if (rand() % 2 == 0)
enemy[type].x = rrand(400, 550);
enemy[type].x = rrand((int)(screen->w / 2), (int)(screen->w / 2) + 150);
else
enemy[type].x = rrand(250, 400);
enemy[type].x = rrand((int)(screen->w / 2) - 150, (int)(screen->w / 2));
if (rand() % 2 == 0)
enemy[type].y = rrand(300, 450);
enemy[type].y = rrand((int)(screen->h / 2), (int)(screen->h / 2) + 150);
else
enemy[type].y = rrand(150, 300);
enemy[type].y = rrand((int)(screen->h / 2) - 150, (int)(screen->h / 2));
if (type == FR_PHOEBE)
enemy[type].classDef = CD_PHOEBE;
@ -596,8 +596,8 @@ void initAliens()
{
enemy[WC_KLINE].flags |= FL_IMMORTAL | FL_NOFIRE | FL_NOMOVE;
enemy[WC_KLINE].x = 600;
enemy[WC_KLINE].y = 300;
enemy[WC_KLINE].x = (screen->w * 2) / 3;
enemy[WC_KLINE].y = screen->h / 2;
enemy[WC_KLINE].deathCounter = -250;
enemy[WC_KLINE].maxShield = 1500;
@ -1188,7 +1188,7 @@ void doAliens()
limitCharAdd(&theEnemy->hit, -1, 0, 100);
if ((theEnemy->x + theEnemy->image[0]->w > 0) && (theEnemy->x < 800) && (theEnemy->y + theEnemy->image[0]->h > 0) && (theEnemy->y < 600))
if ((theEnemy->x + theEnemy->image[0]->w > 0) && (theEnemy->x < screen->w) && (theEnemy->y + theEnemy->image[0]->h > 0) && (theEnemy->y < screen->h))
{
if ((!(theEnemy->flags & FL_DISABLED)) && (theEnemy->classDef != CD_ASTEROID) && (theEnemy->classDef != CD_ASTEROID2))
addEngine(theEnemy);
@ -1207,7 +1207,7 @@ void doAliens()
else
{
theEnemy->shield--;
if ((theEnemy->x > 0) && (theEnemy->x < 800) && (theEnemy->y > 0) && (theEnemy->y < 600))
if ((theEnemy->x > 0) && (theEnemy->x < screen->w) && (theEnemy->y > 0) && (theEnemy->y < screen->h))
{
blit(theEnemy->image[theEnemy->face], (int)theEnemy->x, (int)theEnemy->y);
addExplosion(theEnemy->x + (rand() % theEnemy->image[0]->w), theEnemy->y + (rand() % theEnemy->image[0]->h), E_BIG_EXPLOSION);

View File

@ -305,3 +305,8 @@ extern const char *systemNames[];
extern const char *systemBackground[];
static const signed char rate2reload[6] = {15, 15, 13, 11, 9, 7};
const int screenWidth = 800;
const int screenHeight = 600;
const int viewBorder = 100;

View File

@ -233,7 +233,7 @@ int mainGameLoop()
if (engine.paused)
{
textSurface(22, "PAUSED", -1, 300, FONT_WHITE);
textSurface(22, "PAUSED", -1, screen->h / 2, FONT_WHITE);
blitText(22);
updateScreen();

View File

@ -718,8 +718,8 @@ void doStarfield()
else if (star[i].speed == 1)
color = darkGrey;
wrapFloat(&(star[i].x += (engine.ssx * star[i].speed)), 0, 799);
wrapFloat(&(star[i].y += (engine.ssy * star[i].speed)), 0, 599);
wrapFloat(&(star[i].x += (engine.ssx * star[i].speed)), 0, screen->w - 1);
wrapFloat(&(star[i].y += (engine.ssy * star[i].speed)), 0, screen->h - 1);
putpixel(screen, (int)star[i].x, (int)star[i].y, color);
r.x = (int)star[i].x;

View File

@ -34,10 +34,10 @@ void initVars()
{
srand(time(NULL));
for (int i = 0 ; i < 200 ; i++)
for (int i = 0 ; i < (int)(screen->w * screen->h / 2400) ; i++)
{
star[i].x = rand() % 800;
star[i].y = rand() % 600;
star[i].x = rand() % screen->w;
star[i].y = rand() % screen->h;
star[i].speed = 1 + (rand() % 3);
}
@ -188,12 +188,12 @@ void initSystem()
SDL_WM_SetIcon(loadImage("gfx/alienDevice.png"), NULL);
if (engine.fullScreen)
screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
screen = SDL_SetVideoMode(screenWidth, screenHeight, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
else
screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
screen = SDL_SetVideoMode(screenWidth, screenHeight, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
if (screen == NULL) {
printf("Couldn't set 800x600x16 video mode: %s\n", SDL_GetError());
printf("Couldn't set %ix%ix16 video mode: %s\n", screenWidth, screenHeight, SDL_GetError());
exit(1);
}

View File

@ -34,8 +34,8 @@ static void doCursor()
{
getPlayerInput();
limitInt(&engine.cursor_x, 10, 790);
limitInt(&engine.cursor_y, 10, 590);
limitInt(&engine.cursor_x, 10, screen->w - 10);
limitInt(&engine.cursor_y, 10, screen->h - 10);
blit(shape[0], engine.cursor_x, engine.cursor_y);
}
@ -442,7 +442,7 @@ static void showOptions(SDL_Surface *optionsSurface)
#if LINUX
SDL_WM_ToggleFullScreen(screen);
#else
screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
drawBackground();
flushBuffer();
#endif
@ -457,7 +457,7 @@ static void showOptions(SDL_Surface *optionsSurface)
#if LINUX
SDL_WM_ToggleFullScreen(screen);
#else
screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
drawBackground();
flushBuffer();
#endif
@ -503,7 +503,8 @@ int galaxyMap()
char string[25];
engine.cursor_x = engine.cursor_y = 500;
engine.cursor_x = screen->w / 2;
engine.cursor_y = screen->h / 2;
shape[0] = loadImage("gfx/cursor.png");
// Icons 1 - 29
@ -631,9 +632,9 @@ int galaxyMap()
r.x = 0;
r.y = 0;
r.h = 600;
r.h = screen->h;
r.w = 1;
for (int i = 40 ; i < 800 ; i+= 40)
for (int i = 40 ; i < screen->w ; i+= 40)
{
r.x = i;
SDL_FillRect(screen, &r, darkerBlue);
@ -642,8 +643,8 @@ int galaxyMap()
r.x = 0;
r.y = 0;
r.h = 1;
r.w = 800;
for (int i = 40 ; i < 600 ; i+= 40)
r.w = screen->w;
for (int i = 40 ; i < screen->h ; i+= 40)
{
r.y = i;
SDL_FillRect(screen, &r, darkerBlue);

View File

@ -107,28 +107,31 @@ static void doTargetArrow()
int distX = (int)(enemy[engine.targetIndex].x - player.x);
int distY = (int)(enemy[engine.targetIndex].y - player.y);
if (distY < -300)
// TODO: This is not very good. It assumes the player is always at (400,300),
// which is not always true, resulting in the arrows sometimes not appearing when
// the enemy is not visible and sometimes appearing when the enemy is visible.
if (distY < -screen->h / 2)
engine.targetArrow = 36;
if (distY > 300)
if (distY > screen->h / 2)
engine.targetArrow = 40;
if (distX < -400)
if (distX < -screen->w / 2)
engine.targetArrow = 42;
if (distX > 400)
if (distX > screen->w / 2)
engine.targetArrow = 38;
if ((distY < -300) && (distX > 400))
if ((distY < -screen->h / 2) && (distX > screen->w / 2))
engine.targetArrow = 37;
if ((distY > 300) && (distX > 400))
if ((distY > screen->h / 2) && (distX > screen->w / 2))
engine.targetArrow = 39;
if ((distY > 300) && (distX < -400))
if ((distY > screen->h / 2) && (distX < -screen->w / 2))
engine.targetArrow = 41;
if ((distY < -300) && (distX < -400))
if ((distY < -screen->h / 2) && (distX < -screen->w / 2))
engine.targetArrow = 43;
if (engine.targetArrow != -1)

View File

@ -672,14 +672,14 @@ bool missionFailed()
static void drawBriefScreen()
{
SDL_Rect r = {0, 0, 800, 2};
SDL_Rect r = {0, 0, screen->w, 2};
for (int i = 0 ; i < 120 ; i++)
for (int i = 0 ; i < (int)(screen->h / 4) - 30 ; i++)
{
r.y = (i * 2) + 60;
r.y = (i * 2) + 62; // Not a typo; a black gap is left in the middle if it's 60.
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0, i, 0));
r.y = (screen->h - (i * 2) - 60);
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0, i, 0));
r.y = (300 + (i * 2));
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0, (120 - i), 0));
}
blevelRect(140, 70, 500, 20, 0x00, 0x77, 0x00);

View File

@ -28,8 +28,8 @@ Initialises the player for a new game.
void initPlayer()
{
player.active = true;
player.x = 200;
player.y = 200;
player.x = screen->w / 2;
player.y = screen->h / 2;
player.speed = 2;
player.maxShield = (25 * currentGame.shieldUnits);
player.systemPower = player.maxShield;
@ -217,8 +217,8 @@ void doPlayer()
if (engine.done == 0)
{
limitFloat(&player.x, 100, 700);
limitFloat(&player.y, 100, 500);
limitFloat(&player.x, viewBorder, screen->w - viewBorder);
limitFloat(&player.y, viewBorder, screen->h - viewBorder);
}
if (player.shield > engine.lowShield)
@ -362,9 +362,9 @@ void leaveSector()
{
player.x += engine.ssx;
engine.ssx -= 1;
if (player.y > 300)
if (player.y > screen->h)
player.y--;
if (player.y < 300)
if (player.y < screen->h)
player.y++;
}
@ -380,7 +380,7 @@ void leaveSector()
player.face = 0;
player.x += 12;
engine.ssx -= 0.2;
if (player.x > 1600)
if (player.x > (2 * screen->w))
engine.done = 1;
}
}

View File

@ -272,14 +272,14 @@ void doCutscene(int scene)
enemy[i].y += enemy[i].dy;
enemy[i].x += engine.ssx;
blit(enemy[i].image[0], (int)enemy[i].x, (int)enemy[i].y);
if (enemy[i].x > 850)
if (enemy[i].x > (screen->w + 50))
{
enemy[i].x = -50;
enemy[i].y = rand() % 560;
enemy[i].y = rand() % (screen->h - 40);
}
if (enemy[i].y < -50)
enemy[i].y = 650;
if (enemy[i].y > 650)
enemy[i].y = (screen->h + 50);
if (enemy[i].y > (screen->h + 50))
enemy[i].y = -50;
}
}
@ -308,7 +308,7 @@ void doCutscene(int scene)
}
if ((showMessage) && (messageBox != NULL))
blit(messageBox, (800 - messageBox->w) / 2, 500);
blit(messageBox, (screen->w - messageBox->w) / 2, screen->h - 100);
delayFrame();

View File

@ -171,11 +171,11 @@ int doTitle()
prlogo = loadImage("gfx/prlogo.png");
sflogo = loadImage("gfx/sflogo.png");
int prx = ((800 - prlogo->w) / 2);
int pry = ((600 - prlogo->h) / 2);
int prx = ((screen->w - prlogo->w) / 2);
int pry = ((screen->h - prlogo->h) / 2);
int sfx = ((800 - sflogo->w) / 2);
int sfy = ((600 - sflogo->h) / 2);
int sfx = ((screen->w - sflogo->w) / 2);
int sfy = ((screen->h - sflogo->h) / 2);
textSurface(0, "PRESENTS", -1, 300, FONT_WHITE);
textSurface(1, "AN SDL GAME", -1, 300, FONT_WHITE);
@ -205,8 +205,8 @@ int doTitle()
enemy[i] = defEnemy[CD_TRANSPORTSHIP];
if ((rand() % 5) == 0)
enemy[i] = defEnemy[CD_MINER];
enemy[i].x = rand() % 800;
enemy[i].y = rand() % 560;
enemy[i].x = rand() % screen->w;
enemy[i].y = rand() % (screen->h - 40);
enemy[i].dx = 1 + rand() % 3;
enemy[i].face = 0;
}
@ -258,7 +258,7 @@ int doTitle()
if (enemy[i].x > 830)
{
enemy[i].x = -40;
enemy[i].y = rand() % 580;
enemy[i].y = rand() % (screen->h - 20);
enemy[i].dx = 1 + rand() % 3;
}
}
@ -414,9 +414,9 @@ int doTitle()
SDL_WM_ToggleFullScreen(screen);
#else
if (engine.fullScreen)
screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
else
screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
drawBackground();
flushBuffer();
@ -491,7 +491,7 @@ void showStory()
{
freeGraphics();
int y = 620;
int y = screen->h + 20;
FILE *fp;
@ -540,7 +540,7 @@ void showStory()
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]) || (engine.keyState[SDLK_SPACE]))
break;
if (textShape[8].y > 450)
if (textShape[8].y > (screen->h / 2) + 150)
{
for (int i = 0 ; i < 9 ; i++)
{
@ -585,8 +585,8 @@ void gameover()
Mix_PlayMusic(engine.music, 1);
}
int x = (800 - gameover->w) / 2;
int y = (600 - gameover->h) / 2;
int x = (screen->w - gameover->w) / 2;
int y = (screen->h - gameover->h) / 2;
updateScreen();
@ -603,8 +603,8 @@ void gameover()
updateScreen();
unBuffer();
x = ((800 - gameover->w) / 2) - rrand(-2, 2);
y = ((600 - gameover->h) / 2) - rrand(-2, 2);
x = ((screen->w - gameover->w) / 2) - rrand(-2, 2);
y = ((screen->h - gameover->h) / 2) - rrand(-2, 2);
blit(gameover, x, y);
delayFrame();
@ -632,7 +632,7 @@ void doCredits()
int lastCredit = 0;
int yPos = 0;
int yPos2 = 600;
int yPos2 = screen->h;
char text[255];
textObject *credit;
@ -665,7 +665,7 @@ void doCredits()
{
fscanf(fp, "%d %[^\n]%*c", &yPos, text);
credit[i].image = textSurface(text, FONT_WHITE);
credit[i].x = (800 - credit[i].image->w) / 2;
credit[i].x = (screen->w - credit[i].image->w) / 2;
yPos2 += yPos;
credit[i].y = yPos2;
}
@ -706,11 +706,11 @@ void doCredits()
for (int i = 0 ; i < numberOfCredits ; i++)
{
if ((credit[i].y > -10) && (credit[i].y < 610))
if ((credit[i].y > -10) && (credit[i].y < (screen->h + 10)))
blit(credit[i].image, (int)credit[i].x, (int)credit[i].y);
if (speed > 0 && credit[lastCredit].y > 400)
if (speed > 0 && credit[lastCredit].y > ((screen->h / 2) + 100))
credit[i].y -= speed;
else if(speed < 0 && credit[0].y < 600)
else if(speed < 0 && credit[0].y < screen->h)
credit[i].y -= speed;
}