Initial conversion to SDL2.

This commit is contained in:
Guus Sliepen 2013-09-30 16:52:43 +02:00
parent c357c28966
commit 593ea01386
20 changed files with 209 additions and 174 deletions

View File

@ -1,9 +1,9 @@
CXXFLAGS ?= -O2 -Wall -g
CXXFLAGS += `sdl-config --cflags` -DLINUX
LIBS = `sdl-config --libs` -lSDL_mixer -lSDL_image -lstdc++
CXXFLAGS += `pkg-config --cflags sdl2 SDL2_image SDL2_mixer` -DLINUX
LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer`
OBJS = ai.o aliens.o audio.o bullets.o cargo.o collectable.o comms.o debris.o events.o explosions.o game.o globals.o graphics.o init.o intermission.o loadSave.o messages.o misc.o missions.o player.o resources.o script.o shop.o Starfighter.o title.o unpack.o weapons.o
VERSION = 1.2
VERSION = 1.2-SDL2
PROG = starfighter
PACK = starfighter.pak
DOCS = docs/*

View File

@ -1,4 +1,4 @@
SONGS = space warm-up
SONGS = space warm-up number2
OGG = $(SONGS:%=%.ogg)
WAV = $(SONGS:%=%.wav)
MID = $(SONGS:%=%.mid)

View File

@ -29,9 +29,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/stat.h>
#include <unistd.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include "defs.h"
#include "structs.h"

View File

@ -129,7 +129,7 @@ static void createMissionDetailSurface(SDL_Surface *comms, int missionSlot)
void doComms(SDL_Surface *comms)
{
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
{
if (engine.commsSection == 0)
{
@ -138,7 +138,7 @@ void doComms(SDL_Surface *comms)
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 170, 180 + (i * 60), 430, 50))
{
createMissionDetailSurface(comms, i);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
}
}
@ -147,7 +147,7 @@ void doComms(SDL_Surface *comms)
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 170, 440, 160, 20))
{
createCommsSurface(comms);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
}
}

View File

@ -31,7 +31,7 @@ bool checkPauseRequest()
{
getPlayerInput();
if (engine.keyState[SDLK_ESCAPE])
if (engine.keyState[KEY_ESCAPE])
{
engine.paused = false;
engine.done = 1;
@ -39,10 +39,10 @@ bool checkPauseRequest()
return true;
}
if (engine.keyState[SDLK_p])
if (engine.keyState[KEY_PAUSE])
{
engine.paused = false;
engine.keyState[SDLK_p] = 0;
engine.keyState[KEY_PAUSE] = 0;
}
return false;

View File

@ -136,7 +136,7 @@ int mainGameLoop()
// Default to no aliens dead...
engine.allAliensDead = 0;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
flushInput();
while (engine.done != 1)

View File

@ -51,7 +51,7 @@ void defineGlobals()
engine.commsSection = 0;
for (int i = 0 ; i < 350 ; i++)
for (int i = 0; i < KEY_LAST; i++)
engine.keyState[i] = 0;
engine.eventTimer = 0;

View File

@ -38,6 +38,9 @@ Uint32 black;
Uint32 white;
Uint32 lightGrey;
Uint32 darkGrey;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Surface *screen, *background;
SDL_Surface *shape[MAX_SHAPES];
SDL_Surface *shipShape[MAX_SHIPSHAPES];
@ -132,7 +135,7 @@ void initGraphics()
SDL_Surface *setTransparent(SDL_Surface *sprite)
{
SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(sprite->format, 0, 0, 0));
SDL_SetColorKey(sprite, (SDL_TRUE|SDL_RLEACCEL), SDL_MapRGB(sprite->format, 0, 0, 0));
return sprite;
}
@ -351,7 +354,9 @@ void clearScreen(Uint32 color)
void updateScreen()
{
SDL_Flip(screen);
SDL_UpdateTexture(texture, NULL, screen->pixels, screen->w * 4);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
/*
@ -514,7 +519,7 @@ void blevelRect(int x, int y, int w, int h, Uint8 red, Uint8 green, Uint8 blue)
SDL_Surface *createSurface(int width, int height)
{
SDL_Surface *surface, *newImage;
SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
@ -538,11 +543,7 @@ SDL_Surface *createSurface(int width, int height)
showErrorAndExit(2, "");
}
newImage = SDL_DisplayFormat(surface);
SDL_FreeSurface(surface);
return newImage;
return surface;
}
SDL_Surface *textSurface(const char *inString, int color)
@ -584,7 +585,7 @@ SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green, blue));
SDL_SetAlpha(surface, SDL_SRCALPHA|SDL_RLEACCEL, 128);
SDL_SetSurfaceAlphaMod(surface, 128);
return surface;
}
@ -680,7 +681,7 @@ SDL_Surface *loadImage(const char *filename)
showErrorAndExit(0, filename);
}
newImage = SDL_DisplayFormat(image);
newImage = SDL_ConvertSurface(image, screen->format, 0);
if ( newImage ) {
SDL_FreeSurface(image);
} else {

View File

@ -33,6 +33,9 @@ extern Uint32 black;
extern Uint32 white;
extern Uint32 lightGrey;
extern Uint32 darkGrey;
extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern SDL_Texture *texture;
extern SDL_Surface *screen, *background;
extern SDL_Surface *shape[MAX_SHAPES];
extern SDL_Surface *shipShape[MAX_SHIPSHAPES];

View File

@ -96,9 +96,9 @@ void showErrorAndExit(int errorId, const char *name)
updateScreen();
engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_ALTFIRE] = 0;
while (!engine.keyState[SDLK_SPACE])
while (!engine.keyState[KEY_ALTFIRE])
{
getPlayerInput();
delayFrame();
@ -184,16 +184,36 @@ void initSystem()
engine.useSound = useSound;
engine.useMusic = useMusic;
SDL_WM_SetCaption("Project: Starfighter", "starfighter");
SDL_WM_SetIcon(loadImage("gfx/alienDevice.png"), NULL);
screen = SDL_CreateRGBSurface(0, screenWidth, screenHeight, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
if (engine.fullScreen)
screen = SDL_SetVideoMode(screenWidth, screenHeight, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
else
screen = SDL_SetVideoMode(screenWidth, screenHeight, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
if (!screen) {
printf("Couldn't create %ix%ix32 surface: %s\n", screenWidth, screenHeight, SDL_GetError());
exit(1);
}
if (screen == NULL) {
printf("Couldn't set %ix%ix16 video mode: %s\n", screenWidth, screenHeight, SDL_GetError());
window = SDL_CreateWindow("Project: Starfighter", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen->w, screen->h, 0);
if (window == NULL) {
printf("Could not create window: %s\n", SDL_GetError());
exit(1);
}
SDL_SetWindowIcon(window, loadImage("gfx/alienDevice.png"));
SDL_SetWindowFullscreen(window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
printf("Could not create renderer: %s\n", SDL_GetError());
exit(1);
}
SDL_RenderSetLogicalSize(renderer, screen->w, screen->h);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h);
if (!texture) {
printf("Couldn't create %ix%ix32 texture: %s\n", screen->w, screen->h, SDL_GetError());
exit(1);
}

View File

@ -275,7 +275,7 @@ static bool showSystem(float x, float y, bool selectable)
if (selectable && collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, r.x, r.y, systemPlanet[planet].image->w, systemPlanet[planet].image->h))
{
drawString(systemPlanet[planet].name, -1, 545, FONT_WHITE);
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
{
if (currentGame.system == 0)
{
@ -291,7 +291,7 @@ static bool showSystem(float x, float y, bool selectable)
}
rtn = true;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
}
@ -314,9 +314,9 @@ static void showStatus(SDL_Surface *infoSurface)
{
float speed = 0.25;
if(engine.keyState[SDLK_DOWN])
if(engine.keyState[KEY_DOWN])
speed = 1;
else if(engine.keyState[SDLK_UP])
else if(engine.keyState[KEY_UP])
speed = -1;
blit(infoSurface, 100, 80);
@ -407,7 +407,7 @@ static void createOptions(SDL_Surface *optionsSurface)
static void showOptions(SDL_Surface *optionsSurface)
{
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
{
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 172, 45, 22))
engine.useSound = true;
@ -439,13 +439,7 @@ static void showOptions(SDL_Surface *optionsSurface)
{
if (!engine.fullScreen)
{
#if LINUX
SDL_WM_ToggleFullScreen(screen);
#else
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
drawBackground();
flushBuffer();
#endif
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
engine.fullScreen = true;
}
}
@ -454,13 +448,7 @@ static void showOptions(SDL_Surface *optionsSurface)
{
if (engine.fullScreen)
{
#if LINUX
SDL_WM_ToggleFullScreen(screen);
#else
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
drawBackground();
flushBuffer();
#endif
SDL_SetWindowFullscreen(window, 0);
engine.fullScreen = false;
}
}
@ -468,7 +456,7 @@ static void showOptions(SDL_Surface *optionsSurface)
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 322, 100, 22))
{
wrapChar(&(++currentGame.autoSaveSlot), -1, 4);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
createOptions(optionsSurface);
@ -534,7 +522,7 @@ int galaxyMap()
shape[FACE_KLINE] = loadImage("gfx/face_kline.png");
engine.done = 0;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
engine.ssx = engine.ssy = 0;
SDL_Rect r;
@ -611,7 +599,7 @@ int galaxyMap()
player.shield = player.maxShield;
flushInput();
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
engine.done = 0;
while (!engine.done)
@ -695,10 +683,10 @@ int galaxyMap()
break;
case 1:
if (engine.keyState[SDLK_SPACE])
if (engine.keyState[KEY_ALTFIRE])
{
movePlanets = !movePlanets;
engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_ALTFIRE] = 0;
}
if (movePlanets)
@ -830,17 +818,17 @@ int galaxyMap()
blit(iconInfo[11].image, (int)iconInfo[i].x, 545);
}
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
{
redrawBackGround = true;
section = i;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
}
}
}
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
doCursor();
delayFrame();

View File

@ -153,7 +153,7 @@ void saveGame(int slot)
// Recall to update the save slots... (lazy, yes)
initSaveSlots();
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
void createSavesSurface(SDL_Surface *savesSurface, signed char clickedSlot)
@ -203,7 +203,7 @@ void createSavesSurface(SDL_Surface *savesSurface, signed char clickedSlot)
break;
}
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
}
/*
@ -221,7 +221,7 @@ int showSaveSlots(SDL_Surface *savesSurface, signed char saveSlot)
int clickedSlot = -1;
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
{
for (int i = 0 ; i < 5 ; i++)
{

View File

@ -396,7 +396,7 @@ void doInfo()
if (player.shield < 1)
return;
if ((!engine.keyState[SDLK_SPACE]) && (player.weaponType[1] == W_LASER) && (engine.eventTimer % 8 == 1))
if ((!engine.keyState[KEY_ALTFIRE]) && (player.weaponType[1] == W_LASER) && (engine.eventTimer % 8 == 1))
limitCharAdd(&player.ammo[1], -1, 1, 255);
if ((engine.eventTimer < 30) && (player.shield <= engine.lowShield))

View File

@ -789,13 +789,13 @@ void missionBriefScreen()
flushInput();
engine.done = 0;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
while (true)
{
delayFrame();
getPlayerInput();
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
break;
}
@ -887,13 +887,13 @@ void missionFinishedScreen()
flushInput();
engine.done = 0;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
while (true)
{
delayFrame();
getPlayerInput();
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
break;
}
}

View File

@ -86,10 +86,10 @@ void doPlayer()
{
if (player.shield > 0)
{
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
fireBullet(&player, 0);
if ((engine.keyState[SDLK_SPACE]) && (player.weaponType[1] != W_NONE))
if ((engine.keyState[KEY_ALTFIRE]) && (player.weaponType[1] != W_NONE))
{
if ((player.weaponType[1] != W_CHARGER) && (player.weaponType[1] != W_LASER) && (player.ammo[1] > 0))
{
@ -113,7 +113,7 @@ void doPlayer()
if (player.weaponType[1] == W_CHARGER)
{
if (engine.keyState[SDLK_SPACE])
if (engine.keyState[KEY_ALTFIRE])
{
limitCharAdd(&player.ammo[1], 1, 0, 200);
}
@ -125,7 +125,7 @@ void doPlayer()
}
}
if ((engine.keyState[SDLK_LSHIFT]) || (engine.keyState[SDLK_RSHIFT]))
if ((engine.keyState[KEY_SWITCH]))
{
if(weapon[0].ammo[0] >= 3 && weapon[0].ammo[0] <= currentGame.maxPlasmaOutput)
{
@ -141,39 +141,39 @@ void doPlayer()
}
}
engine.keyState[SDLK_LSHIFT] = engine.keyState[SDLK_RSHIFT] = 0;
engine.keyState[KEY_SWITCH] = 0;
}
limitCharAdd(&player.reload[0], -1, 0, 999);
limitCharAdd(&player.reload[1], -1, 0, 999);
if (engine.keyState[SDLK_UP])
if (engine.keyState[KEY_UP])
{
player.y -= player.speed;
engine.ssy += 0.1;
}
if (engine.keyState[SDLK_DOWN])
if (engine.keyState[KEY_DOWN])
{
player.y += player.speed;
engine.ssy -= 0.1;
}
if (engine.keyState[SDLK_LEFT])
if (engine.keyState[KEY_LEFT])
{
player.x -= player.speed;
engine.ssx += 0.1;
player.face = 1;
}
if (engine.keyState[SDLK_RIGHT])
if (engine.keyState[KEY_RIGHT])
{
player.x += player.speed;
engine.ssx -= 0.1;
player.face = 0;
}
if (engine.keyState[SDLK_ESCAPE])
if (engine.keyState[KEY_ESCAPE])
{
if ((engine.done == 0) && (engine.gameSection == SECTION_GAME) && (currentMission.remainingObjectives1 == 0))
{
@ -183,13 +183,13 @@ void doPlayer()
}
}
if (engine.keyState[SDLK_p] || !(SDL_GetAppState() & SDL_APPINPUTFOCUS))
if (engine.keyState[KEY_PAUSE])
{
engine.paused = true;
engine.keyState[SDLK_p] = 0;
engine.keyState[KEY_PAUSE] = 0;
}
if ((engine.keyState[SDLK_t]) && (currentGame.area != 10))
if ((engine.keyState[KEY_TARGET]) && (currentGame.area != 10))
{
if (engine.targetArrowTimer == -1 && currentGame.difficulty < DIFFICULTY_HARD) {
engine.targetArrowTimer = -2;
@ -202,7 +202,7 @@ void doPlayer()
setInfoLine("Showing mission target", FONT_WHITE);
}
engine.keyState[SDLK_t] = 0;
engine.keyState[KEY_TARGET] = 0;
}
if ((engine.missionCompleteTimer == 0) && (engine.targetArrowTimer == -1))
@ -261,7 +261,7 @@ void doPlayer()
playSound(SFX_EXPLOSION, player.x);
}
engine.keyState[SDLK_UP] = engine.keyState[SDLK_DOWN] = engine.keyState[SDLK_LEFT] = engine.keyState[SDLK_RIGHT] = 0;
engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0;
if ((rand() % 3) == 0)
addExplosion(player.x + rrand(-10, 10), player.y + rrand(-10, 10), E_BIG_EXPLOSION);
if (player.shield == -99)
@ -291,12 +291,43 @@ void doPlayer()
void flushInput()
{
for (int i = 0 ; i < 350 ; i++)
for (int i = 0; i < KEY_LAST; i++)
engine.keyState[i] = 0;
while (SDL_PollEvent(&engine.event)){}
}
static enum keys mapkey(uint32_t code) {
switch (code) {
case SDLK_UP:
return KEY_UP;
case SDLK_DOWN:
return KEY_DOWN;
case SDLK_LEFT:
return KEY_LEFT;
case SDLK_RIGHT:
return KEY_RIGHT;
case SDLK_LCTRL:
case SDLK_RCTRL:
return KEY_FIRE;
case SDLK_SPACE:
return KEY_ALTFIRE;
case SDLK_t:
return KEY_TARGET;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
return KEY_SWITCH;
case SDLK_p:
return KEY_PAUSE;
case SDLK_ESCAPE:
return KEY_ESCAPE;
case SDLK_F11:
return KEY_FULLSCREEN;
default:
return KEY_DUMMY;
}
}
void getPlayerInput()
{
while (SDL_PollEvent(&engine.event))
@ -310,16 +341,17 @@ void getPlayerInput()
case SDL_MOUSEBUTTONDOWN:
if (engine.gameSection == SECTION_INTERMISSION)
{
if (engine.event.button.button == SDL_BUTTON_LEFT) engine.keyState[SDLK_LCTRL] = 1;
if (engine.event.button.button == SDL_BUTTON_RIGHT) engine.keyState[SDLK_SPACE] = 1;
if (engine.event.button.button == SDL_BUTTON_LEFT) engine.keyState[KEY_FIRE] = 1;
if (engine.event.button.button == SDL_BUTTON_RIGHT) engine.keyState[KEY_ALTFIRE] = 1;
}
break;
case SDL_KEYDOWN:
if (engine.gameSection == SECTION_TITLE)
addKeyEvent(SDL_GetKeyName(engine.event.key.keysym.sym));
//TODO: reenable somehow?
//if (engine.gameSection == SECTION_TITLE)
// addKeyEvent(SDL_GetKeyName(engine.event.key.keysym.sym));
engine.keyState[engine.event.key.keysym.sym] = 1;
engine.keyState[mapkey(engine.event.key.keysym.sym)] = 1;
if (engine.gameSection != SECTION_GAME)
engine.paused = false;
@ -327,8 +359,8 @@ void getPlayerInput()
break;
case SDL_KEYUP:
if (engine.event.key.keysym.sym != SDLK_p)
engine.keyState[engine.event.key.keysym.sym] = 0;
if (engine.event.key.keysym.sym != SDLK_p && engine.event.key.keysym.sym != SDLK_t)
engine.keyState[mapkey(engine.event.key.keysym.sym)] = 0;
break;
case SDL_JOYBUTTONDOWN:
@ -336,25 +368,25 @@ void getPlayerInput()
switch (engine.event.jbutton.button)
{
case 0:
engine.keyState[SDLK_LCTRL] = engine.event.jbutton.state;
engine.keyState[KEY_FIRE] = engine.event.jbutton.state;
break;
case 1:
engine.keyState[SDLK_SPACE] = engine.event.jbutton.state;
engine.keyState[KEY_ALTFIRE] = engine.event.jbutton.state;
break;
case 2:
engine.keyState[SDLK_LSHIFT] = engine.event.jbutton.state;
engine.keyState[KEY_SWITCH] = engine.event.jbutton.state;
break;
case 3:
engine.keyState[SDLK_t] = engine.event.jbutton.state;
engine.keyState[KEY_TARGET] = engine.event.jbutton.state;
break;
}
break;
case SDL_JOYHATMOTION:
engine.keyState[SDLK_UP] = engine.event.jhat.value & SDL_HAT_UP;
engine.keyState[SDLK_DOWN] = engine.event.jhat.value & SDL_HAT_DOWN;
engine.keyState[SDLK_LEFT] = engine.event.jhat.value & SDL_HAT_LEFT;
engine.keyState[SDLK_RIGHT] = engine.event.jhat.value & SDL_HAT_RIGHT;
engine.keyState[KEY_UP] = engine.event.jhat.value & SDL_HAT_UP;
engine.keyState[KEY_DOWN] = engine.event.jhat.value & SDL_HAT_DOWN;
engine.keyState[KEY_LEFT] = engine.event.jhat.value & SDL_HAT_LEFT;
engine.keyState[KEY_RIGHT] = engine.event.jhat.value & SDL_HAT_RIGHT;
break;
case SDL_JOYAXISMOTION:
@ -363,28 +395,30 @@ void getPlayerInput()
bool joyup = engine.event.jaxis.value < -16384;
bool joydown = engine.event.jaxis.value >= 16384;
if(joyup != prevjoyup)
engine.keyState[SDLK_UP] = prevjoyup = joyup;
engine.keyState[KEY_UP] = prevjoyup = joyup;
if(joydown != prevjoydown)
engine.keyState[SDLK_DOWN] = prevjoydown = joydown;
engine.keyState[KEY_DOWN] = prevjoydown = joydown;
} else {
bool joyleft = engine.event.jaxis.value < -16384;
bool joyright = engine.event.jaxis.value >= 16384;
if(joyleft != prevjoyleft)
engine.keyState[SDLK_LEFT] = prevjoyleft = joyleft;
engine.keyState[KEY_LEFT] = prevjoyleft = joyleft;
if(joyright != prevjoyright)
engine.keyState[SDLK_RIGHT] = prevjoyright = joyright;
engine.keyState[KEY_RIGHT] = prevjoyright = joyright;
}
break;
default:
case SDL_WINDOWEVENT:
if(engine.event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
engine.paused = 1;
break;
}
if ((engine.keyState[SDLK_F11]) || ((engine.keyState[SDLK_RETURN]) && (engine.keyState[SDLK_LALT])))
if (engine.keyState[KEY_FULLSCREEN])
{
SDL_WM_ToggleFullScreen(screen);
engine.fullScreen = !engine.fullScreen;
engine.keyState[SDLK_F11] = engine.keyState[SDLK_LALT] = engine.keyState[SDLK_RETURN] = 0;
SDL_SetWindowFullscreen(window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
engine.keyState[KEY_FULLSCREEN] = 0;
}
}
@ -395,13 +429,13 @@ void getPlayerInput()
int x, y;
SDL_GetMouseState(&x, &y);
if (px == x && py == y) {
if(engine.keyState[SDLK_UP] && engine.cursor_y > 0)
if(engine.keyState[KEY_UP] && engine.cursor_y > 0)
engine.cursor_y -= 4;
if(engine.keyState[SDLK_DOWN] && engine.cursor_y < screen->h - 4)
if(engine.keyState[KEY_DOWN] && engine.cursor_y < screen->h - 4)
engine.cursor_y += 4;
if(engine.keyState[SDLK_LEFT] && engine.cursor_x > 0)
if(engine.keyState[KEY_LEFT] && engine.cursor_x > 0)
engine.cursor_x -= 4;
if(engine.keyState[SDLK_RIGHT] && engine.cursor_x < screen->w - 4)
if(engine.keyState[KEY_RIGHT] && engine.cursor_x < screen->w - 4)
engine.cursor_x += 4;
} else {
engine.cursor_x = px = x;
@ -413,8 +447,8 @@ void getPlayerInput()
void leaveSector()
{
engine.keyState[SDLK_UP] = engine.keyState[SDLK_DOWN] = engine.keyState[SDLK_LEFT] = engine.keyState[SDLK_RIGHT] = 0;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
if (engine.done == 0)
engine.done = 3;

View File

@ -116,7 +116,7 @@ void loadGameGraphics()
}
}
SDL_SetColorKey(shipShape[i], (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(shipShape[i]->format, 0, 0, 0));
SDL_SetColorKey(shipShape[i], (SDL_TRUE|SDL_RLEACCEL), SDL_MapRGB(shipShape[i]->format, 0, 0, 0));
}
strcpy(string, "data/resources_all.dat");
@ -178,22 +178,6 @@ void freeSound()
}
static void setFontColor(SDL_Surface *image, int red, int green, int blue)
{
SDL_Color colors[256];
colors[0].r = 0;
colors[0].g = 0;
colors[0].b = 0;
for (int i = 1 ; i < 256 ; i++)
{
colors[i].r = red;
colors[i].g = green;
colors[i].b = blue;
}
SDL_SetPalette(image, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
}
/*
Custom loading to alter the font color before doing
all other things
@ -219,23 +203,23 @@ void loadFont()
switch(i)
{
case 1:
setFontColor(image, 255, 0, 0);
SDL_SetSurfaceColorMod(image, 255, 0, 0);
break;
case 2:
setFontColor(image, 255, 255, 0);
SDL_SetSurfaceColorMod(image, 255, 255, 0);
break;
case 3:
setFontColor(image, 0, 255, 0);
SDL_SetSurfaceColorMod(image, 0, 255, 0);
break;
case 4:
setFontColor(image, 0, 255, 255);
SDL_SetSurfaceColorMod(image, 0, 255, 255);
break;
case 5:
setFontColor(image, 0, 0, 10);
SDL_SetSurfaceColorMod(image, 0, 0, 10);
break;
}
newImage = SDL_DisplayFormat(image);
newImage = SDL_ConvertSurface(image, screen->format, 0);
fontShape[i] = setTransparent(newImage);

View File

@ -202,7 +202,7 @@ void doCutscene(int scene)
updateScreen();
clearScreen(black);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
engine.ssx = -0.5;
engine.ssy = 0;
@ -314,7 +314,7 @@ void doCutscene(int scene)
delayFrame();
if (engine.keyState[SDLK_ESCAPE])
if (engine.keyState[KEY_ESCAPE])
break;
}

View File

@ -672,14 +672,14 @@ void showShop()
else if (currentGame.system == 2)
icons = 15;
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
if ((engine.keyState[KEY_FIRE]))
{
for (int i = 0 ; i < icons ; i++)
{
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, shopItems[i].x, shopItems[i].y, 32, 25))
{
shopSelectedItem = i;
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
drawShop();
}
}
@ -689,14 +689,14 @@ void showShop()
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 60, 350, 24, 16))
{
buy(shopSelectedItem);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
drawShop();
}
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 700, 350, 24, 16))
{
sell(shopSelectedItem);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = 0;
drawShop();
}
}

View File

@ -207,6 +207,21 @@ struct Planet {
char subject[100];
};
enum keys {
KEY_UP,
KEY_DOWN,
KEY_LEFT,
KEY_RIGHT,
KEY_FIRE,
KEY_ALTFIRE,
KEY_TARGET,
KEY_SWITCH,
KEY_PAUSE,
KEY_ESCAPE,
KEY_FULLSCREEN,
KEY_DUMMY,
KEY_LAST
};
struct globalEngineVariables {
@ -274,7 +289,7 @@ struct globalEngineVariables {
// This really only applies to Linux users.
char userHomeDirectory[1024];
char keyState[350];
char keyState[KEY_LAST];
bool cheat; // overall cheat
bool cheatShield;

View File

@ -265,7 +265,7 @@ int doTitle()
engine.done = 0;
flushInput();
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
if ((engine.useMusic) && (engine.useAudio))
Mix_PlayMusic(engine.music, 1);
@ -338,18 +338,18 @@ int doTitle()
if (redGlow <= 0) {redDir = 2; redGlow = 0;}
if (redGlow >= 255) {redDir = -2; redGlow = 255;}
if (engine.keyState[SDLK_UP])
if (engine.keyState[KEY_UP])
{
engine.keyState[SDLK_UP] = 0;
engine.keyState[KEY_UP] = 0;
wrapChar(&(--selectedOption), 1, listLength + 1);
if (menuType == 0)
if ((selectedOption == 2) || (selectedOption == 3))
if (continueSaveSlot == 0)
selectedOption = 1;
}
if (engine.keyState[SDLK_DOWN])
if (engine.keyState[KEY_DOWN])
{
engine.keyState[SDLK_DOWN] = 0;
engine.keyState[KEY_DOWN] = 0;
wrapChar(&(++selectedOption), 0, listLength);
if (menuType == 0)
if ((selectedOption == 2) || (selectedOption == 3))
@ -382,7 +382,7 @@ int doTitle()
engine.cheatCredits = false;
}
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]) || (engine.keyState[SDLK_SPACE]))
if ((engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE]))
{
if ((now - then <= 27500) && (!skip))
{
@ -445,17 +445,7 @@ int doTitle()
else if (selectedOption == 3)
{
engine.fullScreen = !engine.fullScreen;
#if LINUX
SDL_WM_ToggleFullScreen(screen);
#else
if (engine.fullScreen)
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
else
screen = SDL_SetVideoMode(screen->w, screen->h, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
drawBackground();
flushBuffer();
#endif
SDL_SetWindowFullscreen(window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
}
else if (selectedOption == 4)
wrapChar(&(++currentGame.autoSaveSlot), -1, 4);
@ -499,7 +489,7 @@ int doTitle()
break;
}
}
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
}
delayFrame();
@ -510,7 +500,7 @@ int doTitle()
SDL_FreeSurface(prlogo);
SDL_FreeSurface(sflogo);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
resetLists();
@ -578,7 +568,7 @@ void showStory()
flushBuffer();
flushInput();
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
while (true)
{
@ -587,7 +577,7 @@ void showStory()
getPlayerInput();
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]) || (engine.keyState[SDLK_SPACE]))
if ((engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE]))
break;
if (textShape[8].y > (screen->h / 2) + 150)
@ -617,7 +607,7 @@ void gameover()
freeGraphics();
SDL_FillRect(background, NULL, black);
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
engine.gameSection = SECTION_INTERMISSION;
loadMusic("music/Wybierak.mod");
@ -641,13 +631,13 @@ void gameover()
updateScreen();
flushInput();
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0;
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
while (true)
{
getPlayerInput();
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]) || (engine.keyState[SDLK_SPACE]))
if ((engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE]))
break;
updateScreen();
@ -736,7 +726,7 @@ void doCredits()
lastCredit = numberOfCredits - 1;
engine.keyState[SDLK_ESCAPE] = 0;
engine.keyState[KEY_ESCAPE] = 0;
flushInput();
while (true)
@ -745,13 +735,13 @@ void doCredits()
unBuffer();
getPlayerInput();
if (engine.keyState[SDLK_ESCAPE])
if (engine.keyState[KEY_ESCAPE])
break;
float speed = 0.5;
if(engine.keyState[SDLK_DOWN])
if(engine.keyState[KEY_DOWN])
speed = 2;
else if(engine.keyState[SDLK_UP])
else if(engine.keyState[KEY_UP])
speed = -2;
for (int i = 0 ; i < numberOfCredits ; i++)