2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
2015-03-01 21:37:32 +01:00
|
|
|
Copyright (C) 2011, 2012, 2013 Guus Sliepen
|
2016-01-02 22:59:48 +01:00
|
|
|
Copyright (C) 2015, 2016 onpon4 <onpon4@riseup.net>
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
as published by the Free Software Foundation; either version 3
|
2011-08-24 14:14:44 +02:00
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-26 17:20:36 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
#include "Starfighter.h"
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2011-08-24 14:42:59 +02:00
|
|
|
void loadBackground(const char *filename)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-11-07 01:43:34 +01:00
|
|
|
if (gfx_background != NULL)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-11-07 01:43:34 +01:00
|
|
|
SDL_FreeSurface(gfx_background);
|
|
|
|
gfx_background = NULL;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
2016-01-02 22:59:48 +01:00
|
|
|
gfx_background = gfx_loadImage(filename);
|
2015-11-07 01:43:34 +01:00
|
|
|
SDL_SetColorKey(gfx_background, 0, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loadGameGraphics()
|
|
|
|
{
|
|
|
|
int index;
|
2012-03-11 15:16:19 +01:00
|
|
|
char string[75] = "";
|
2015-03-06 15:37:21 +01:00
|
|
|
FILE *fp;
|
2015-03-30 13:52:44 +02:00
|
|
|
Uint32 *p32;
|
|
|
|
Uint16 *p16;
|
|
|
|
Uint8 *p8;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-02 22:59:48 +01:00
|
|
|
gfx_free();
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-04 04:39:16 +01:00
|
|
|
gfx_shipSprites[0] = gfx_loadImage("gfx/firefly1.png");
|
|
|
|
gfx_shipSprites[1] = gfx_loadImage("gfx/firefly2.png");
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-05-21 01:41:43 +02:00
|
|
|
switch(game.system)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
strcpy(string, "data/resources_spirit.dat");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
strcpy(string, "data/resources_eyananth.dat");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcpy(string, "data/resources_mordor.dat");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strcpy(string, "data/resources_sol.dat");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = fopen(string, "rb");
|
|
|
|
|
|
|
|
if (fp == NULL)
|
|
|
|
exit(1);
|
|
|
|
|
2015-02-27 23:59:25 +01:00
|
|
|
while (fscanf(fp, "%d %s", &index, string) == 2)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-04 04:39:16 +01:00
|
|
|
gfx_shipSprites[index] = gfx_loadImage(string);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/*
|
2012-02-28 13:35:39 +01:00
|
|
|
Create images of ships being hit that show a lot of red
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
2016-01-04 04:39:16 +01:00
|
|
|
for (int i = SHIP_HIT_INDEX ; i < MAX_SHIPSPRITES ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-04 04:39:16 +01:00
|
|
|
if (gfx_shipSprites[i - SHIP_HIT_INDEX] == NULL)
|
2011-08-24 14:14:44 +02:00
|
|
|
continue;
|
2016-01-04 04:39:16 +01:00
|
|
|
gfx_shipSprites[i] = gfx_createSurface(gfx_shipSprites[i - SHIP_HIT_INDEX]->w,
|
|
|
|
gfx_shipSprites[i - SHIP_HIT_INDEX]->h);
|
|
|
|
SDL_SetSurfaceBlendMode(gfx_shipSprites[i - SHIP_HIT_INDEX], SDL_BLENDMODE_NONE);
|
|
|
|
gfx_blit(gfx_shipSprites[i - SHIP_HIT_INDEX], 0, 0, gfx_shipSprites[i]);
|
|
|
|
SDL_SetSurfaceBlendMode(gfx_shipSprites[i - SHIP_HIT_INDEX], SDL_BLENDMODE_BLEND);
|
2012-03-09 16:08:31 +01:00
|
|
|
|
2016-01-04 04:39:16 +01:00
|
|
|
switch (gfx_shipSprites[i]->format->BitsPerPixel)
|
2015-03-06 15:37:21 +01:00
|
|
|
{
|
2015-03-30 13:52:44 +02:00
|
|
|
case 32:
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_LockSurface(gfx_shipSprites[i]);
|
|
|
|
p32 = (Uint32 *)gfx_shipSprites[i]->pixels;
|
|
|
|
for (int j = 0; j < gfx_shipSprites[i]->w * gfx_shipSprites[i]->h; j++)
|
2015-03-06 15:37:21 +01:00
|
|
|
{
|
|
|
|
if (p32[j])
|
2016-01-04 04:39:16 +01:00
|
|
|
p32[j] |= gfx_shipSprites[i]->format->Rmask;
|
2015-03-06 15:37:21 +01:00
|
|
|
}
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_UnlockSurface(gfx_shipSprites[i]);
|
2012-03-09 16:08:31 +01:00
|
|
|
break;
|
|
|
|
|
2015-03-30 13:52:44 +02:00
|
|
|
case 16:
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_LockSurface(gfx_shipSprites[i]);
|
|
|
|
p16 = (Uint16 *)gfx_shipSprites[i]->pixels;
|
|
|
|
for (int j = 0; j < gfx_shipSprites[i]->w * gfx_shipSprites[i]->h; j++)
|
2015-03-06 15:37:21 +01:00
|
|
|
{
|
|
|
|
if (p16[j])
|
2016-01-04 04:39:16 +01:00
|
|
|
p16[j] |= gfx_shipSprites[i]->format->Rmask;
|
2015-03-06 15:37:21 +01:00
|
|
|
}
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_UnlockSurface(gfx_shipSprites[i]);
|
2012-03-09 16:08:31 +01:00
|
|
|
break;
|
|
|
|
|
2015-03-30 13:52:44 +02:00
|
|
|
case 8:
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_LockSurface(gfx_shipSprites[i]);
|
|
|
|
p8 = (Uint8 *)gfx_shipSprites[i]->pixels;
|
|
|
|
for (int j = 0; j < gfx_shipSprites[i]->w * gfx_shipSprites[i]->h; j++)
|
2015-03-06 15:37:21 +01:00
|
|
|
{
|
|
|
|
if (p8[j])
|
2016-01-04 04:39:16 +01:00
|
|
|
p8[j] = SDL_MapRGB(gfx_shipSprites[i]->format, 255, 0, 0);
|
2015-03-06 15:37:21 +01:00
|
|
|
}
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_UnlockSurface(gfx_shipSprites[i]);
|
2012-03-09 16:08:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-04 04:39:16 +01:00
|
|
|
SDL_SetColorKey(gfx_shipSprites[i], SDL_TRUE,
|
|
|
|
SDL_MapRGB(gfx_shipSprites[i]->format, 0, 0, 0));
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(string, "data/resources_all.dat");
|
|
|
|
|
|
|
|
fp = fopen(string, "rb");
|
|
|
|
|
2015-02-27 23:59:25 +01:00
|
|
|
while (fscanf(fp, "%d %s", &index, string) == 2)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-04 04:39:16 +01:00
|
|
|
gfx_sprites[index] = gfx_loadImage(string);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2015-05-21 01:41:43 +02:00
|
|
|
loadBackground(systemBackground[game.system]);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-03-07 15:42:24 +01:00
|
|
|
for (int i = 0 ; i < CD_MAX ; i++)
|
2015-03-07 05:18:31 +01:00
|
|
|
{
|
2016-01-04 04:39:16 +01:00
|
|
|
if (gfx_shipSprites[alien_defs[i].imageIndex[0]] != NULL)
|
2015-03-07 05:18:31 +01:00
|
|
|
{
|
2016-01-04 04:39:16 +01:00
|
|
|
alien_defs[i].image[0] = gfx_shipSprites[alien_defs[i].imageIndex[0]];
|
|
|
|
alien_defs[i].image[1] = gfx_shipSprites[alien_defs[i].imageIndex[1]];
|
2015-03-07 15:42:24 +01:00
|
|
|
alien_defs[i].engineX = alien_defs[i].image[0]->w;
|
|
|
|
alien_defs[i].engineY = (alien_defs[i].image[0]->h / 2);
|
2015-03-07 05:18:31 +01:00
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
setWeaponShapes();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Custom loading to alter the font color before doing
|
|
|
|
all other things
|
|
|
|
*/
|
|
|
|
void loadFont()
|
|
|
|
{
|
|
|
|
SDL_Surface *image, *newImage;
|
|
|
|
|
2016-01-04 04:39:16 +01:00
|
|
|
for (int i = 0 ; i < MAX_FONTSPRITES ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2011-08-27 16:18:29 +02:00
|
|
|
image = IMG_Load("gfx/smallFont.png");
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (image == NULL) {
|
|
|
|
printf("Couldn't load game font! (%s) Exitting.\n", SDL_GetError());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 1:
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetSurfaceColorMod(image, 255, 0, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetSurfaceColorMod(image, 255, 255, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetSurfaceColorMod(image, 0, 255, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetSurfaceColorMod(image, 0, 255, 255);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetSurfaceColorMod(image, 0, 0, 10);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
newImage = SDL_ConvertSurface(image, screen->format, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-04 04:39:16 +01:00
|
|
|
gfx_fontSprites[i] = gfx_setTransparent(newImage);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
SDL_FreeSurface(image);
|
|
|
|
}
|
|
|
|
}
|