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
|
2020-05-24 03:10:45 +02:00
|
|
|
Copyright (C) 2012, 2015-2020 Layla Marchant <diligentcircle@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
|
|
|
*/
|
|
|
|
|
2020-06-22 04:19:28 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "SDL.h"
|
2011-08-26 21:29:04 +02:00
|
|
|
|
2016-11-26 00:21:31 +01:00
|
|
|
#include "defs.h"
|
|
|
|
#include "structs.h"
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "alien.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "engine.h"
|
2019-05-30 18:29:47 +02:00
|
|
|
#include "colors.h"
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "game.h"
|
|
|
|
#include "gfx.h"
|
2019-05-11 03:09:34 +02:00
|
|
|
#include "info.h"
|
2019-05-11 08:49:21 +02:00
|
|
|
#include "player.h"
|
2019-05-30 18:29:47 +02:00
|
|
|
#include "renderer.h"
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "screen.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
#include "window.h"
|
|
|
|
|
2016-11-25 18:37:26 +01:00
|
|
|
Object player;
|
2016-11-19 17:43:50 +01:00
|
|
|
int player_chargerFired = 0;
|
2019-05-11 08:15:36 +02:00
|
|
|
int player_damageDelay = 0;
|
|
|
|
int player_resetDamageDelay = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Initialises the player for a new game.
|
|
|
|
*/
|
2016-11-26 00:01:36 +01:00
|
|
|
void player_init()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-11-19 17:43:50 +01:00
|
|
|
player.active = 1;
|
2012-03-14 16:54:48 +01:00
|
|
|
player.x = screen->w / 2;
|
|
|
|
player.y = screen->h / 2;
|
2011-08-24 14:14:44 +02:00
|
|
|
player.speed = 2;
|
|
|
|
player.systemPower = player.maxShield;
|
|
|
|
player.face = 0;
|
|
|
|
|
2016-01-04 22:34:29 +01:00
|
|
|
player.image[0] = gfx_shipSprites[SS_FIREFLY];
|
|
|
|
player.image[1] = gfx_shipSprites[SS_FIREFLY_L];
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
player.engineX = player.image[0]->w;
|
|
|
|
player.engineY = (player.image[0]->h / 2);
|
|
|
|
|
|
|
|
player.owner = &player;
|
|
|
|
player.flags = FL_FRIEND;
|
|
|
|
|
|
|
|
player.weaponType[0] = W_PLAYER_WEAPON;
|
|
|
|
|
2016-11-25 19:47:12 +01:00
|
|
|
if (weapons[W_PLAYER_WEAPON].ammo[0] < game.minPlasmaOutput)
|
|
|
|
weapons[W_PLAYER_WEAPON].ammo[0] = game.minPlasmaOutput;
|
|
|
|
if (weapons[W_PLAYER_WEAPON].damage < game.minPlasmaDamage)
|
|
|
|
weapons[W_PLAYER_WEAPON].damage = game.minPlasmaDamage;
|
|
|
|
if (weapons[W_PLAYER_WEAPON].reload[0] > rate2reload[game.minPlasmaRate])
|
|
|
|
weapons[W_PLAYER_WEAPON].reload[0] = rate2reload[game.minPlasmaRate];
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
player.hit = 0;
|
|
|
|
|
2015-02-27 04:35:49 +01:00
|
|
|
engine.lowShield = (player.maxShield >= 3) ? (player.maxShield / 3) : 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
engine.averageShield = engine.lowShield + engine.lowShield;
|
|
|
|
|
2015-03-28 18:59:33 +01:00
|
|
|
if ((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER))
|
2011-08-29 09:10:50 +02:00
|
|
|
player.ammo[1] = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-07 05:18:31 +01:00
|
|
|
void player_setTarget(int index)
|
|
|
|
{
|
|
|
|
engine.targetIndex = index;
|
|
|
|
}
|
|
|
|
|
2019-05-25 04:05:09 +02:00
|
|
|
/*
|
|
|
|
Attempt to damage the player by ``amount``. If ``delay`` is specified,
|
|
|
|
delay any damage dealt by that number of frames (i.e. require that
|
|
|
|
number of frames of continuous damage before it registers).
|
|
|
|
Return 1 if damage is inflicted, 0 otherwise.
|
|
|
|
*/
|
2019-05-11 08:15:36 +02:00
|
|
|
void player_damage(int amount, int delay)
|
2019-05-11 03:09:34 +02:00
|
|
|
{
|
|
|
|
int oldshield = player.shield;
|
2019-05-11 08:15:36 +02:00
|
|
|
|
|
|
|
player_resetDamageDelay = 0;
|
|
|
|
|
2019-05-11 03:09:34 +02:00
|
|
|
if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0) &&
|
2019-05-11 08:15:36 +02:00
|
|
|
((!player.hit) ||
|
2019-05-11 08:38:21 +02:00
|
|
|
(game.difficulty == DIFFICULTY_ORIGINAL) ||
|
2019-05-11 08:15:36 +02:00
|
|
|
((player.shield != engine.lowShield) &&
|
|
|
|
(player.shield != 1))))
|
2019-05-11 03:09:34 +02:00
|
|
|
{
|
2019-05-11 08:15:36 +02:00
|
|
|
if ((game.difficulty == DIFFICULTY_ORIGINAL) ||
|
|
|
|
(player_damageDelay >= delay))
|
|
|
|
{
|
|
|
|
player.shield -= amount;
|
|
|
|
|
2019-05-25 04:05:09 +02:00
|
|
|
LIMIT(player.shield, 0, player.maxShield);
|
|
|
|
player.hit = 5; // Damage flash timer
|
|
|
|
audio_playSound(SFX_HIT, player.x, player.y);
|
2019-05-11 03:09:34 +02:00
|
|
|
|
2019-05-25 04:05:09 +02:00
|
|
|
// Damage tiers (not in Classic mode)
|
|
|
|
if ((oldshield > engine.lowShield) &&
|
|
|
|
(player.shield <= engine.lowShield))
|
2019-05-11 08:49:21 +02:00
|
|
|
{
|
2019-05-25 04:05:09 +02:00
|
|
|
info_setLine("!!! WARNING: SHIELD LOW !!!", FONT_RED);
|
|
|
|
if (game.difficulty != DIFFICULTY_ORIGINAL)
|
|
|
|
{
|
|
|
|
player.shield = engine.lowShield;
|
|
|
|
player_damageDelay = 0;
|
|
|
|
}
|
2019-05-11 08:49:21 +02:00
|
|
|
}
|
2019-05-25 04:05:09 +02:00
|
|
|
else if ((oldshield > 1) && (player.shield <= 1))
|
2019-05-11 08:49:21 +02:00
|
|
|
{
|
2019-05-25 04:05:09 +02:00
|
|
|
info_setLine("!!! WARNING: SHIELD CRITICAL !!!", FONT_RED);
|
|
|
|
if (game.difficulty != DIFFICULTY_ORIGINAL)
|
|
|
|
{
|
|
|
|
player.shield = 1;
|
|
|
|
player_damageDelay = 0;
|
|
|
|
}
|
2019-05-11 08:49:21 +02:00
|
|
|
}
|
2019-05-11 03:09:34 +02:00
|
|
|
}
|
2019-05-25 04:05:09 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
player_damageDelay += amount;
|
|
|
|
}
|
2019-05-11 03:09:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 22:37:55 +02:00
|
|
|
void player_checkShockDamage(float x, float y)
|
2015-04-07 22:09:17 +02:00
|
|
|
{
|
2015-04-24 22:37:55 +02:00
|
|
|
float distX = fabsf(x - player.x);
|
|
|
|
float distY = fabsf(y - player.y);
|
|
|
|
|
2015-04-07 22:09:17 +02:00
|
|
|
// Don't let the player be hurt by an explosion after they have completed
|
2016-11-25 18:37:26 +01:00
|
|
|
// all the mission Objectives. That would be *really* annoying!
|
2015-04-07 22:09:17 +02:00
|
|
|
if ((engine.cheatShield) || (engine.missionCompleteTimer != 0))
|
2015-04-24 22:37:55 +02:00
|
|
|
return;
|
2015-04-07 22:09:17 +02:00
|
|
|
|
|
|
|
if ((distX <= 50) && (distY <= 50))
|
|
|
|
{
|
|
|
|
if (distX >= 1)
|
|
|
|
distX /= 5;
|
|
|
|
|
|
|
|
if (distY >= 1)
|
|
|
|
distY /= 5;
|
|
|
|
|
2019-05-11 08:49:21 +02:00
|
|
|
player_damage((int)((10 - distX) + (10 - distY)), 0);
|
2015-04-07 22:09:17 +02:00
|
|
|
player.hit = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-26 00:01:36 +01:00
|
|
|
void player_exit()
|
2011-08-29 09:10:50 +02:00
|
|
|
{
|
2016-11-19 17:43:50 +01:00
|
|
|
player_chargerFired = 0;
|
2015-03-01 02:20:36 +01:00
|
|
|
|
2015-03-28 18:59:33 +01:00
|
|
|
if ((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER))
|
2011-08-29 09:10:50 +02:00
|
|
|
player.ammo[1] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2016-11-26 00:01:36 +01:00
|
|
|
void player_flushInput()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2013-09-30 16:52:43 +02:00
|
|
|
for (int i = 0; i < KEY_LAST; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
engine.keyState[i] = 0;
|
|
|
|
|
|
|
|
while (SDL_PollEvent(&engine.event)){}
|
|
|
|
}
|
|
|
|
|
2017-01-22 06:22:03 +01:00
|
|
|
static enum keys mapkey(int code) {
|
2013-09-30 16:52:43 +02:00
|
|
|
switch (code) {
|
|
|
|
case SDLK_UP:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_KP_8:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_UP;
|
|
|
|
case SDLK_DOWN:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_KP_2:
|
|
|
|
case SDLK_KP_5:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_DOWN;
|
|
|
|
case SDLK_LEFT:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_KP_4:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_LEFT;
|
|
|
|
case SDLK_RIGHT:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_KP_6:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_RIGHT;
|
|
|
|
case SDLK_LCTRL:
|
|
|
|
case SDLK_RCTRL:
|
2015-02-28 01:23:19 +01:00
|
|
|
case SDLK_RETURN:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_z:
|
2015-04-07 21:19:14 +02:00
|
|
|
case SDLK_y:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_c:
|
|
|
|
case SDLK_a:
|
2015-03-07 23:13:37 +01:00
|
|
|
case SDLK_d:
|
|
|
|
case SDLK_f:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_SLASH:
|
|
|
|
case SDLK_COMMA:
|
|
|
|
case SDLK_1:
|
|
|
|
case SDLK_3:
|
|
|
|
case SDLK_KP_0:
|
2017-02-05 21:45:24 +01:00
|
|
|
case SDLK_HOME:
|
|
|
|
case SDLK_END:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_FIRE;
|
|
|
|
case SDLK_SPACE:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_x:
|
|
|
|
case SDLK_s:
|
|
|
|
case SDLK_PERIOD:
|
|
|
|
case SDLK_2:
|
|
|
|
case SDLK_KP_1:
|
2017-02-05 21:45:24 +01:00
|
|
|
case SDLK_PAGEUP:
|
|
|
|
case SDLK_PAGEDOWN:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_ALTFIRE;
|
|
|
|
case SDLK_LSHIFT:
|
|
|
|
case SDLK_RSHIFT:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_LALT:
|
|
|
|
case SDLK_RALT:
|
|
|
|
case SDLK_KP_7:
|
|
|
|
case SDLK_KP_9:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_SWITCH;
|
|
|
|
case SDLK_p:
|
2017-02-05 21:45:24 +01:00
|
|
|
case SDLK_PAUSE:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_PAUSE;
|
|
|
|
case SDLK_ESCAPE:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_q:
|
|
|
|
case SDLK_BACKSPACE:
|
2017-02-05 21:45:24 +01:00
|
|
|
case SDLK_DELETE:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_ESCAPE;
|
|
|
|
case SDLK_F11:
|
|
|
|
return KEY_FULLSCREEN;
|
|
|
|
default:
|
|
|
|
return KEY_DUMMY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-26 00:01:36 +01:00
|
|
|
void player_getInput()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2020-07-27 16:36:10 +02:00
|
|
|
static int prevjoyup = 0, prevjoydown = 0, prevjoyleft = 0, prevjoyright = 0;
|
|
|
|
int joyup, joydown, joyleft, joyright;
|
2020-06-22 04:19:28 +02:00
|
|
|
double val;
|
2019-05-21 08:09:26 +02:00
|
|
|
static int px = -1, py = -1;
|
|
|
|
int x, y, w, h;
|
|
|
|
|
2013-07-10 21:37:08 +02:00
|
|
|
while (SDL_PollEvent(&engine.event))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
switch (engine.event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
if (engine.gameSection == SECTION_INTERMISSION)
|
|
|
|
{
|
2020-07-27 17:29:35 +02:00
|
|
|
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;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
2019-05-30 17:32:50 +02:00
|
|
|
if (!engine.event.key.repeat)
|
|
|
|
{
|
|
|
|
engine.keyState[mapkey(engine.event.key.keysym.sym)] = 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2019-05-30 17:32:50 +02:00
|
|
|
if (engine.gameSection != SECTION_GAME)
|
|
|
|
engine.paused = 0;
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_KEYUP:
|
2015-02-27 01:27:38 +01:00
|
|
|
if (engine.event.key.keysym.sym != SDLK_p)
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[mapkey(engine.event.key.keysym.sym)] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
2013-07-10 21:37:08 +02:00
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
|
case SDL_JOYBUTTONUP:
|
|
|
|
switch (engine.event.jbutton.button)
|
|
|
|
{
|
|
|
|
case 0:
|
2015-03-02 01:59:27 +01:00
|
|
|
case 3:
|
2020-07-27 17:29:35 +02:00
|
|
|
engine.keyState[KEY_ALTFIRE] = CSDLP(
|
|
|
|
engine.event.jbutton.state);
|
2013-07-10 21:37:08 +02:00
|
|
|
break;
|
2015-03-02 01:59:27 +01:00
|
|
|
case 1:
|
2013-07-10 21:37:08 +02:00
|
|
|
case 2:
|
2020-07-27 17:29:35 +02:00
|
|
|
engine.keyState[KEY_FIRE] = CSDLP(
|
|
|
|
engine.event.jbutton.state);
|
2015-03-02 01:59:27 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 6:
|
2020-07-27 17:29:35 +02:00
|
|
|
engine.keyState[KEY_ESCAPE] = CSDLP(
|
|
|
|
engine.event.jbutton.state);
|
2015-03-02 01:59:27 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
2020-07-27 17:29:35 +02:00
|
|
|
engine.keyState[KEY_SWITCH] = CSDLP(
|
|
|
|
engine.event.jbutton.state);
|
2013-07-10 21:37:08 +02:00
|
|
|
break;
|
2015-03-02 01:59:27 +01:00
|
|
|
case 9:
|
2020-07-27 17:29:35 +02:00
|
|
|
engine.keyState[KEY_PAUSE] = CSDLP(
|
|
|
|
engine.event.jbutton.state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
|
|
case SDL_CONTROLLERBUTTONUP:
|
|
|
|
switch (engine.event.cbutton.button)
|
|
|
|
{
|
|
|
|
case SDL_CONTROLLER_BUTTON_A:
|
|
|
|
case SDL_CONTROLLER_BUTTON_Y:
|
|
|
|
engine.keyState[KEY_ALTFIRE] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_B:
|
|
|
|
case SDL_CONTROLLER_BUTTON_X:
|
|
|
|
engine.keyState[KEY_FIRE] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
|
|
|
|
engine.keyState[KEY_ESCAPE] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_BACK:
|
|
|
|
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
|
|
|
|
engine.keyState[KEY_SWITCH] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_START:
|
|
|
|
engine.keyState[KEY_PAUSE] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_UP:
|
|
|
|
engine.keyState[KEY_UP] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
|
|
|
|
engine.keyState[KEY_DOWN] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
|
|
|
|
engine.keyState[KEY_LEFT] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
|
|
|
engine.keyState[KEY_RIGHT] = CSDLP(
|
|
|
|
engine.event.cbutton.state);
|
2015-03-02 01:59:27 +01:00
|
|
|
break;
|
2013-07-10 21:37:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_JOYHATMOTION:
|
2020-07-16 17:43:45 +02:00
|
|
|
engine.keyState[KEY_UP] = (engine.event.jhat.value & SDL_HAT_UP ? 1 : 0);
|
|
|
|
engine.keyState[KEY_DOWN] = (engine.event.jhat.value & SDL_HAT_DOWN ? 1 : 0);
|
|
|
|
engine.keyState[KEY_LEFT] = (engine.event.jhat.value & SDL_HAT_LEFT ? 1 : 0);
|
|
|
|
engine.keyState[KEY_RIGHT] = (engine.event.jhat.value & SDL_HAT_RIGHT ? 1 : 0);
|
2013-07-10 21:37:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_JOYAXISMOTION:
|
2020-07-27 16:36:10 +02:00
|
|
|
if (engine.gameSection == SECTION_TITLE) {
|
|
|
|
if (engine.event.jaxis.axis == 0) {
|
|
|
|
joyleft = engine.event.jaxis.value < -16384;
|
|
|
|
joyright = engine.event.jaxis.value >= 16384;
|
|
|
|
if (joyleft != prevjoyleft)
|
|
|
|
engine.keyState[KEY_LEFT] = prevjoyleft = joyleft;
|
|
|
|
if (joyright != prevjoyright)
|
|
|
|
engine.keyState[KEY_RIGHT] = prevjoyright = joyright;
|
|
|
|
} else if (engine.event.jaxis.axis == 1) {
|
|
|
|
joyup = engine.event.jaxis.value < -16384;
|
|
|
|
joydown = engine.event.jaxis.value >= 16384;
|
|
|
|
if (joyup != prevjoyup)
|
|
|
|
engine.keyState[KEY_UP] = prevjoyup = joyup;
|
|
|
|
if (joydown != prevjoydown)
|
|
|
|
engine.keyState[KEY_DOWN] = prevjoydown = joydown;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = MIN(1, (double)(abs(engine.event.jaxis.value)) / JS_MAX);
|
|
|
|
if (val < JS_DEADZONE)
|
|
|
|
val = 0;
|
|
|
|
|
|
|
|
if (engine.event.jaxis.axis == 0)
|
|
|
|
engine.xaxis = copysign(val, engine.event.jaxis.value);
|
|
|
|
else if (engine.event.jaxis.axis == 1)
|
|
|
|
engine.yaxis = copysign(val, engine.event.jaxis.value);
|
|
|
|
}
|
2020-06-22 04:19:28 +02:00
|
|
|
|
2013-07-10 21:37:08 +02:00
|
|
|
break;
|
2015-05-22 00:30:23 +02:00
|
|
|
|
2020-07-27 17:29:35 +02:00
|
|
|
case SDL_CONTROLLERAXISMOTION:
|
|
|
|
if (engine.gameSection == SECTION_TITLE) {
|
|
|
|
if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX)
|
|
|
|
{
|
|
|
|
joyleft = engine.event.caxis.value < -16384;
|
|
|
|
joyright = engine.event.caxis.value >= 16384;
|
|
|
|
if (joyleft != prevjoyleft)
|
|
|
|
engine.keyState[KEY_LEFT] = prevjoyleft = joyleft;
|
|
|
|
if (joyright != prevjoyright)
|
|
|
|
engine.keyState[KEY_RIGHT] = prevjoyright = joyright;
|
|
|
|
}
|
|
|
|
else if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY)
|
|
|
|
{
|
|
|
|
joyup = engine.event.caxis.value < -16384;
|
|
|
|
joydown = engine.event.caxis.value >= 16384;
|
|
|
|
if (joyup != prevjoyup)
|
|
|
|
engine.keyState[KEY_UP] = prevjoyup = joyup;
|
|
|
|
if (joydown != prevjoydown)
|
|
|
|
engine.keyState[KEY_DOWN] = prevjoydown = joydown;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = MIN(1, (double)(abs(engine.event.caxis.value)) / JS_MAX);
|
|
|
|
if (val < JS_DEADZONE)
|
|
|
|
val = 0;
|
|
|
|
|
|
|
|
if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX)
|
|
|
|
engine.xaxis = copysign(val, engine.event.caxis.value);
|
|
|
|
else if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY)
|
|
|
|
engine.yaxis = copysign(val, engine.event.caxis.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-05-22 00:30:23 +02:00
|
|
|
case SDL_WINDOWEVENT:
|
2019-05-30 18:29:47 +02:00
|
|
|
if (engine.event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
|
|
{
|
2019-05-30 19:14:32 +02:00
|
|
|
screen_adjustDimensions(engine.event.window.data1, engine.event.window.data2);
|
|
|
|
renderer_reset();
|
2019-05-30 22:46:55 +02:00
|
|
|
gfx_scaleBackground();
|
2019-05-30 18:29:47 +02:00
|
|
|
screen_clear(black);
|
|
|
|
renderer_update();
|
|
|
|
screen_clear(black);
|
|
|
|
screen_addBuffer(0, 0, screen->w, screen->h);
|
|
|
|
}
|
|
|
|
|
2015-05-22 00:49:04 +02:00
|
|
|
if (engine.autoPause &&
|
|
|
|
(engine.event.window.event == SDL_WINDOWEVENT_FOCUS_LOST))
|
2016-11-19 17:43:50 +01:00
|
|
|
engine.paused = 1;
|
2015-05-22 00:30:23 +02:00
|
|
|
break;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
2011-09-05 22:13:11 +02:00
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_FULLSCREEN])
|
2011-09-05 22:13:11 +02:00
|
|
|
{
|
2019-05-30 18:01:42 +02:00
|
|
|
engine_setFullscreen(!engine.fullScreen);
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_FULLSCREEN] = 0;
|
2011-09-05 22:13:11 +02:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
2013-07-10 21:54:14 +02:00
|
|
|
|
|
|
|
if (engine.gameSection == SECTION_INTERMISSION)
|
|
|
|
{
|
|
|
|
// Get the current mouse position
|
|
|
|
SDL_GetMouseState(&x, &y);
|
2015-07-05 06:31:36 +02:00
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
2016-01-04 02:41:48 +01:00
|
|
|
x = screen->w * x / w;
|
|
|
|
y = screen->h * y / h;
|
2013-07-10 21:54:14 +02:00
|
|
|
if (px == x && py == y) {
|
2020-06-22 04:19:28 +02:00
|
|
|
if (engine.keyState[KEY_UP])
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_y -= 4;
|
2020-06-22 04:19:28 +02:00
|
|
|
if (engine.keyState[KEY_DOWN])
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_y += 4;
|
2020-06-22 04:19:28 +02:00
|
|
|
if (engine.keyState[KEY_LEFT])
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_x -= 4;
|
2020-06-22 04:19:28 +02:00
|
|
|
if (engine.keyState[KEY_RIGHT])
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_x += 4;
|
2020-06-22 04:19:28 +02:00
|
|
|
if (engine.xaxis)
|
|
|
|
engine.cursor_x += 10 * engine.xaxis;
|
|
|
|
if (engine.yaxis)
|
|
|
|
engine.cursor_y += 10 * engine.yaxis;
|
2013-07-10 21:54:14 +02:00
|
|
|
} else {
|
|
|
|
engine.cursor_x = px = x;
|
|
|
|
engine.cursor_y = py = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2016-11-26 00:01:36 +01:00
|
|
|
void player_leaveSector()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-29 22:49:33 +02:00
|
|
|
engine.keyState[KEY_UP] = 0;
|
|
|
|
engine.keyState[KEY_DOWN] = 0;
|
|
|
|
engine.keyState[KEY_LEFT] = 0;
|
|
|
|
engine.keyState[KEY_RIGHT] = 0;
|
|
|
|
engine.keyState[KEY_FIRE] = 0;
|
|
|
|
engine.keyState[KEY_ALTFIRE] = 0;
|
2020-07-16 17:43:45 +02:00
|
|
|
engine.xaxis = 0;
|
|
|
|
engine.yaxis = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2020-05-24 03:10:45 +02:00
|
|
|
if (engine.done == ENGINE_RUNNING)
|
|
|
|
engine.done = ENGINE_FORMATION;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2020-05-24 03:10:45 +02:00
|
|
|
if (engine.done == ENGINE_FORMATION)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
player.face = 0;
|
|
|
|
if (player.x > -100)
|
|
|
|
{
|
|
|
|
player.x += engine.ssx;
|
|
|
|
engine.ssx -= 1;
|
2015-02-26 20:18:27 +01:00
|
|
|
if (player.y > screen->h / 2)
|
2011-08-24 14:14:44 +02:00
|
|
|
player.y--;
|
2015-02-26 20:18:27 +01:00
|
|
|
if (player.y < screen->h / 2)
|
2011-08-24 14:14:44 +02:00
|
|
|
player.y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player.x <= -100)
|
|
|
|
{
|
2020-05-24 03:10:45 +02:00
|
|
|
engine.done = ENGINE_SYSEXIT;
|
2016-01-11 05:56:26 +01:00
|
|
|
audio_playSound(SFX_FLY, screen->w / 2, screen->h / 2);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 03:10:45 +02:00
|
|
|
if (engine.done == ENGINE_SYSEXIT)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
player.face = 0;
|
2019-06-06 15:30:22 +02:00
|
|
|
player.x += WARP_SPEED;
|
2011-08-24 14:14:44 +02:00
|
|
|
engine.ssx -= 0.2;
|
2012-03-12 04:16:56 +01:00
|
|
|
if (player.x > (2 * screen->w))
|
2020-05-24 03:10:45 +02:00
|
|
|
engine.done = ENGINE_CLOSING;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|