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
|
|
|
|
Copyright (C) 2012, 2015 Julian Marchant
|
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"
|
|
|
|
|
|
|
|
object player;
|
2015-03-03 15:25:32 +01:00
|
|
|
static bool charger_fired = false;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Initialises the player for a new game.
|
|
|
|
*/
|
|
|
|
void initPlayer()
|
|
|
|
{
|
2011-08-26 16:14:58 +02:00
|
|
|
player.active = true;
|
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;
|
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
player.image[0] = shipShape[0];
|
|
|
|
player.image[1] = shipShape[1];
|
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;
|
|
|
|
|
2015-02-28 14:15:53 +01:00
|
|
|
if(weapon[W_PLAYER_WEAPON].ammo[0] < currentGame.minPlasmaOutput)
|
|
|
|
weapon[W_PLAYER_WEAPON].ammo[0] = currentGame.minPlasmaOutput;
|
|
|
|
if(weapon[W_PLAYER_WEAPON].damage < currentGame.minPlasmaDamage)
|
|
|
|
weapon[W_PLAYER_WEAPON].damage = currentGame.minPlasmaDamage;
|
|
|
|
if(weapon[W_PLAYER_WEAPON].reload[0] > rate2reload[currentGame.minPlasmaRate])
|
|
|
|
weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[currentGame.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;
|
|
|
|
|
|
|
|
if (player.weaponType[1] == W_CHARGER)
|
|
|
|
player.ammo[1] = 0;
|
|
|
|
|
|
|
|
if (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;
|
|
|
|
engine.targetShield = 85;
|
2015-03-07 15:42:24 +01:00
|
|
|
engine.targetShield /= aliens[index].shield;
|
2015-03-07 05:18:31 +01:00
|
|
|
}
|
|
|
|
|
2011-08-29 09:10:50 +02:00
|
|
|
void exitPlayer()
|
|
|
|
{
|
2015-03-01 02:20:36 +01:00
|
|
|
charger_fired = false;
|
|
|
|
|
2011-08-29 09:10:50 +02:00
|
|
|
if (player.weaponType[1] == W_CHARGER)
|
|
|
|
player.ammo[1] = 0;
|
|
|
|
|
|
|
|
if (player.weaponType[1] == W_LASER)
|
|
|
|
player.ammo[1] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void doPlayer()
|
|
|
|
{
|
|
|
|
// This causes the motion to slow
|
|
|
|
engine.ssx *= 0.99;
|
|
|
|
engine.ssy *= 0.99;
|
|
|
|
|
2015-02-27 05:23:08 +01:00
|
|
|
engine.smx = 0;
|
|
|
|
engine.smy = 0;
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
int shapeToUse;
|
2015-02-27 06:25:00 +01:00
|
|
|
float cd;
|
|
|
|
float cc;
|
|
|
|
bool xmoved = false;
|
|
|
|
bool ymoved = false;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (player.shield > -100)
|
|
|
|
{
|
|
|
|
if (player.shield > 0)
|
|
|
|
{
|
2013-09-30 16:52:43 +02:00
|
|
|
if ((engine.keyState[KEY_FIRE]))
|
2015-03-13 15:10:58 +01:00
|
|
|
ship_fireBullet(&player, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if ((engine.keyState[KEY_ALTFIRE]) && (player.weaponType[1] != W_NONE))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
if ((player.weaponType[1] != W_CHARGER) &&
|
|
|
|
(player.weaponType[1] != W_LASER) && (player.ammo[1] > 0))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-13 15:10:58 +01:00
|
|
|
ship_fireBullet(&player, 1);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (player.weaponType[1] == W_LASER)
|
|
|
|
{
|
|
|
|
if (player.ammo[1] < 100)
|
|
|
|
{
|
2015-03-13 15:10:58 +01:00
|
|
|
ship_fireBullet(&player, 1);
|
2011-08-24 14:14:44 +02:00
|
|
|
player.ammo[1] += 2;
|
|
|
|
if (player.ammo[1] >= 100)
|
|
|
|
{
|
|
|
|
player.ammo[1] = 200;
|
|
|
|
setInfoLine("Laser Overheat!!", FONT_WHITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player.weaponType[1] == W_CHARGER)
|
|
|
|
{
|
2015-02-27 02:51:30 +01:00
|
|
|
if (engine.keyState[KEY_ALTFIRE] && !(engine.keyState[KEY_FIRE]))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
Reduced charger's max charge, make it fire when it reaches max.
The original charge cannon is so overpowered it's ridiculous. The
strongest weapon in the game, unlimited ammo, and the only setback
it has is that you need to charge it a bit. The lack of balance
obsoletes the laser weapon, which is fine, but it also obsoletes
homing missile weapons, *including* ones that are newer and more
expensive than the charge cannon!
Now, it's much more balanced. You actually need to shoot the thing
before it hits max (or have your target in sight when it does),
rather than being able to just hold the button at max forever and
release when optimal like you previously could. Basically, the charge
cannon is still the weapon which does the most damage, but it's now
much harder to use. Incidentally, not only should homing missiles
be a sensible option now, even the laser cannon has a place after
the charge cannon becomes available.
2015-02-28 14:36:04 +01:00
|
|
|
if (!charger_fired)
|
|
|
|
{
|
2015-03-09 03:01:37 +01:00
|
|
|
limitCharAdd(&player.ammo[1], 1, 0, 150);
|
|
|
|
if (player.ammo[1] >= 150)
|
Reduced charger's max charge, make it fire when it reaches max.
The original charge cannon is so overpowered it's ridiculous. The
strongest weapon in the game, unlimited ammo, and the only setback
it has is that you need to charge it a bit. The lack of balance
obsoletes the laser weapon, which is fine, but it also obsoletes
homing missile weapons, *including* ones that are newer and more
expensive than the charge cannon!
Now, it's much more balanced. You actually need to shoot the thing
before it hits max (or have your target in sight when it does),
rather than being able to just hold the button at max forever and
release when optimal like you previously could. Basically, the charge
cannon is still the weapon which does the most damage, but it's now
much harder to use. Incidentally, not only should homing missiles
be a sensible option now, even the laser cannon has a place after
the charge cannon becomes available.
2015-02-28 14:36:04 +01:00
|
|
|
{
|
2015-03-13 15:10:58 +01:00
|
|
|
ship_fireBullet(&player, 1);
|
Reduced charger's max charge, make it fire when it reaches max.
The original charge cannon is so overpowered it's ridiculous. The
strongest weapon in the game, unlimited ammo, and the only setback
it has is that you need to charge it a bit. The lack of balance
obsoletes the laser weapon, which is fine, but it also obsoletes
homing missile weapons, *including* ones that are newer and more
expensive than the charge cannon!
Now, it's much more balanced. You actually need to shoot the thing
before it hits max (or have your target in sight when it does),
rather than being able to just hold the button at max forever and
release when optimal like you previously could. Basically, the charge
cannon is still the weapon which does the most damage, but it's now
much harder to use. Incidentally, not only should homing missiles
be a sensible option now, even the laser cannon has a place after
the charge cannon becomes available.
2015-02-28 14:36:04 +01:00
|
|
|
player.ammo[1] = 0;
|
|
|
|
charger_fired = true;
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (player.ammo[1] > 0)
|
2015-03-13 15:10:58 +01:00
|
|
|
ship_fireBullet(&player, 1);
|
2011-08-24 14:14:44 +02:00
|
|
|
player.ammo[1] = 0;
|
Reduced charger's max charge, make it fire when it reaches max.
The original charge cannon is so overpowered it's ridiculous. The
strongest weapon in the game, unlimited ammo, and the only setback
it has is that you need to charge it a bit. The lack of balance
obsoletes the laser weapon, which is fine, but it also obsoletes
homing missile weapons, *including* ones that are newer and more
expensive than the charge cannon!
Now, it's much more balanced. You actually need to shoot the thing
before it hits max (or have your target in sight when it does),
rather than being able to just hold the button at max forever and
release when optimal like you previously could. Basically, the charge
cannon is still the weapon which does the most damage, but it's now
much harder to use. Incidentally, not only should homing missiles
be a sensible option now, even the laser cannon has a place after
the charge cannon becomes available.
2015-02-28 14:36:04 +01:00
|
|
|
charger_fired = false;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if ((engine.keyState[KEY_SWITCH]))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-02-28 14:15:53 +01:00
|
|
|
if ((weapon[W_PLAYER_WEAPON].ammo[0] >= 3) &&
|
|
|
|
(weapon[W_PLAYER_WEAPON].ammo[0] <= currentGame.maxPlasmaOutput))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-02-28 14:15:53 +01:00
|
|
|
weapon[W_PLAYER_WEAPON].flags ^= WF_SPREAD;
|
2011-09-04 18:24:54 +02:00
|
|
|
|
2015-02-28 14:15:53 +01:00
|
|
|
if (weapon[W_PLAYER_WEAPON].flags & WF_SPREAD)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2011-09-04 18:24:54 +02:00
|
|
|
setInfoLine("Weapon set to Spread", FONT_WHITE);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
2011-09-04 18:24:54 +02:00
|
|
|
else
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2011-09-04 18:24:54 +02:00
|
|
|
setInfoLine("Weapon set to Concentrate", FONT_WHITE);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-04 18:24:54 +02:00
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_SWITCH] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:27:16 +02:00
|
|
|
limitCharAdd(&player.reload[0], -1, 0, 999);
|
|
|
|
limitCharAdd(&player.reload[1], -1, 0, 999);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_UP])
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
player.y -= player.speed;
|
|
|
|
engine.ssy += 0.1;
|
2015-02-27 06:25:00 +01:00
|
|
|
ymoved = true;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_DOWN])
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
player.y += player.speed;
|
|
|
|
engine.ssy -= 0.1;
|
2015-02-27 06:25:00 +01:00
|
|
|
ymoved = true;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_LEFT])
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
player.x -= player.speed;
|
|
|
|
engine.ssx += 0.1;
|
|
|
|
player.face = 1;
|
2015-02-27 06:25:00 +01:00
|
|
|
xmoved = true;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_RIGHT])
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
player.x += player.speed;
|
|
|
|
engine.ssx -= 0.1;
|
|
|
|
player.face = 0;
|
2015-02-27 06:25:00 +01:00
|
|
|
xmoved = true;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_ESCAPE])
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-03 15:25:32 +01:00
|
|
|
if ((engine.done == 0) && (engine.gameSection == SECTION_GAME) &&
|
|
|
|
(currentMission.remainingObjectives1 == 0))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-08 15:38:58 +01:00
|
|
|
audio_playSound(SFX_FLY, screen->w / 2);
|
2011-08-24 14:14:44 +02:00
|
|
|
engine.done = 2;
|
|
|
|
engine.missionCompleteTimer = (SDL_GetTicks() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if (engine.keyState[KEY_PAUSE])
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2011-08-26 16:14:58 +02:00
|
|
|
engine.paused = true;
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_PAUSE] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 01:59:33 +01:00
|
|
|
if (((currentGame.area == 18) && (aliens[ALIEN_BOSS].shield > 0)) ||
|
2015-03-07 15:42:24 +01:00
|
|
|
(currentGame.area == 24))
|
2015-02-27 15:30:30 +01:00
|
|
|
{
|
2011-08-24 14:14:44 +02:00
|
|
|
player.face = 0;
|
2015-02-27 15:30:30 +01:00
|
|
|
xmoved = true;
|
|
|
|
ymoved = true;
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (engine.done == 0)
|
|
|
|
{
|
2015-02-27 06:25:00 +01:00
|
|
|
if (xmoved)
|
2015-02-27 05:23:08 +01:00
|
|
|
{
|
2015-02-27 06:25:00 +01:00
|
|
|
if (player.x < xViewBorder)
|
|
|
|
{
|
|
|
|
engine.smx += xViewBorder - player.x;
|
|
|
|
player.x = xViewBorder;
|
|
|
|
}
|
|
|
|
else if (player.x > screen->w - xViewBorder)
|
|
|
|
{
|
|
|
|
engine.smx += (screen->w - xViewBorder) - player.x;
|
|
|
|
player.x = screen->w - xViewBorder;
|
|
|
|
}
|
2015-02-27 05:23:08 +01:00
|
|
|
}
|
2015-02-27 06:25:00 +01:00
|
|
|
else
|
2015-02-27 05:23:08 +01:00
|
|
|
{
|
2015-02-27 06:25:00 +01:00
|
|
|
cd = player.x - screen->w / 2;
|
|
|
|
if (cd < 0)
|
|
|
|
{
|
2015-02-28 05:14:33 +01:00
|
|
|
cc = max(cd / 10, max(0, engine.ssx) - cameraMaxSpeed);
|
2015-02-27 07:10:27 +01:00
|
|
|
player.x -= cc;
|
|
|
|
engine.smx -= cc;
|
2015-02-27 06:25:00 +01:00
|
|
|
}
|
|
|
|
else if (cd > 0)
|
|
|
|
{
|
2015-02-28 05:14:33 +01:00
|
|
|
cc = min(cd / 10, cameraMaxSpeed + min(0, engine.ssx));
|
2015-02-27 07:10:27 +01:00
|
|
|
player.x -= cc;
|
|
|
|
engine.smx -= cc;
|
2015-02-27 06:25:00 +01:00
|
|
|
}
|
2015-02-27 05:23:08 +01:00
|
|
|
}
|
2015-02-27 06:25:00 +01:00
|
|
|
if (ymoved)
|
2015-02-27 05:23:08 +01:00
|
|
|
{
|
2015-02-27 06:25:00 +01:00
|
|
|
if (player.y < yViewBorder)
|
|
|
|
{
|
|
|
|
engine.smy += yViewBorder - player.y;
|
|
|
|
player.y = yViewBorder;
|
|
|
|
}
|
|
|
|
else if (player.y > screen->h - yViewBorder)
|
|
|
|
{
|
|
|
|
engine.smy += (screen->h - yViewBorder) - player.y;
|
|
|
|
player.y = screen->h - yViewBorder;
|
|
|
|
}
|
2015-02-27 05:23:08 +01:00
|
|
|
}
|
2015-02-27 06:25:00 +01:00
|
|
|
else
|
2015-02-27 05:23:08 +01:00
|
|
|
{
|
2015-02-27 06:25:00 +01:00
|
|
|
cd = player.y - screen->h / 2;
|
|
|
|
if (cd < 0)
|
|
|
|
{
|
2015-02-28 05:14:33 +01:00
|
|
|
cc = max(cd / 10, max(0, engine.ssy) - cameraMaxSpeed);
|
2015-02-27 07:10:27 +01:00
|
|
|
player.y -= cc;
|
|
|
|
engine.smy -= cc;
|
2015-02-27 06:25:00 +01:00
|
|
|
}
|
|
|
|
else if (cd > 0)
|
|
|
|
{
|
2015-02-28 05:14:33 +01:00
|
|
|
cc = min(cd / 10, cameraMaxSpeed + min(0, engine.ssy));
|
2015-02-27 07:10:27 +01:00
|
|
|
player.y -= cc;
|
|
|
|
engine.smy -= cc;
|
2015-02-27 06:25:00 +01:00
|
|
|
}
|
2015-02-27 05:23:08 +01:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2015-02-28 04:22:27 +01:00
|
|
|
if ((player.maxShield <= 1) || (player.shield > engine.lowShield))
|
2011-08-24 14:14:44 +02:00
|
|
|
addEngine(&player);
|
|
|
|
|
|
|
|
shapeToUse = player.face;
|
|
|
|
|
|
|
|
if (player.hit)
|
|
|
|
shapeToUse += SHIP_HIT_INDEX;
|
|
|
|
|
2011-08-26 23:27:16 +02:00
|
|
|
limitCharAdd(&player.hit, -1, 0, 100);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
blit(shipShape[shapeToUse], (int)player.x, (int)player.y);
|
2015-02-28 04:22:27 +01:00
|
|
|
if ((player.maxShield > 1) && (player.shield <= engine.lowShield) &&
|
|
|
|
(rand() % 5 < 1))
|
2011-08-26 23:27:16 +02:00
|
|
|
addExplosion(player.x + rrand(-10, 10), player.y + rrand(-10, 20), E_SMOKE);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-26 16:14:58 +02:00
|
|
|
player.active = false;
|
2011-08-24 14:14:44 +02:00
|
|
|
player.shield--;
|
|
|
|
if (player.shield == -1)
|
|
|
|
{
|
2015-03-09 01:59:33 +01:00
|
|
|
if ((currentGame.hasWingMate1) || (aliens[ALIEN_KLINE].active))
|
2011-08-24 14:14:44 +02:00
|
|
|
getPlayerDeathMessage();
|
|
|
|
|
|
|
|
// Make it look like the ships are all still moving...
|
|
|
|
if (currentGame.area == 18)
|
|
|
|
{
|
2015-03-09 01:59:33 +01:00
|
|
|
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[i].flags |= FL_LEAVESECTOR;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2015-03-08 15:38:58 +01:00
|
|
|
audio_playSound(SFX_DEATH, player.x);
|
|
|
|
audio_playSound(SFX_EXPLOSION, player.x);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
if ((rand() % 3) == 0)
|
2011-08-26 23:27:16 +02:00
|
|
|
addExplosion(player.x + rrand(-10, 10), player.y + rrand(-10, 10), E_BIG_EXPLOSION);
|
2011-08-24 14:14:44 +02:00
|
|
|
if (player.shield == -99)
|
|
|
|
addDebris((int)player.x, (int)player.y, player.maxShield);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 06:25:00 +01:00
|
|
|
limitFloat(&engine.ssx, -cameraMaxSpeed, cameraMaxSpeed);
|
|
|
|
limitFloat(&engine.ssy, -cameraMaxSpeed, cameraMaxSpeed);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
// Specific for the mission were you have to chase the Executive Transport
|
2015-03-09 01:59:33 +01:00
|
|
|
if ((currentGame.area == 18) && (aliens[ALIEN_BOSS].shield > 0) &&
|
2015-03-07 15:42:24 +01:00
|
|
|
(player.shield > 0))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
engine.ssx = -6;
|
|
|
|
engine.ssy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentGame.area == 24)
|
|
|
|
{
|
|
|
|
engine.ssx = -6;
|
|
|
|
engine.ssy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.dx = engine.ssx;
|
|
|
|
player.dy = engine.ssy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void flushInput()
|
|
|
|
{
|
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)){}
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
static enum keys mapkey(uint32_t code) {
|
|
|
|
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:
|
|
|
|
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:
|
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:
|
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:
|
|
|
|
return KEY_PAUSE;
|
|
|
|
case SDLK_ESCAPE:
|
2015-03-04 01:28:15 +01:00
|
|
|
case SDLK_q:
|
|
|
|
case SDLK_BACKSPACE:
|
2013-09-30 16:52:43 +02:00
|
|
|
return KEY_ESCAPE;
|
|
|
|
case SDLK_F11:
|
|
|
|
return KEY_FULLSCREEN;
|
|
|
|
default:
|
|
|
|
return KEY_DUMMY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
void getPlayerInput()
|
|
|
|
{
|
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)
|
|
|
|
{
|
2013-09-30 16:52:43 +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:
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[mapkey(engine.event.key.keysym.sym)] = 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (engine.gameSection != SECTION_GAME)
|
2011-08-26 16:14:58 +02:00
|
|
|
engine.paused = false;
|
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:
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_ALTFIRE] = 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:
|
2015-03-02 01:59:27 +01:00
|
|
|
engine.keyState[KEY_FIRE] = engine.event.jbutton.state;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 6:
|
|
|
|
engine.keyState[KEY_ESCAPE] = engine.event.jbutton.state;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_SWITCH] = engine.event.jbutton.state;
|
2013-07-10 21:37:08 +02:00
|
|
|
break;
|
2015-03-02 01:59:27 +01:00
|
|
|
case 9:
|
|
|
|
if (engine.event.jbutton.state)
|
|
|
|
engine.keyState[KEY_PAUSE] = 1;
|
|
|
|
break;
|
2013-07-10 21:37:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_JOYHATMOTION:
|
2013-09-30 16:52:43 +02:00
|
|
|
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;
|
2013-07-10 21:37:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_JOYAXISMOTION:
|
2013-07-13 15:10:29 +02:00
|
|
|
static bool prevjoyup, prevjoydown, prevjoyleft, prevjoyright;
|
2013-07-10 21:37:08 +02:00
|
|
|
if (engine.event.jaxis.axis & 1) {
|
2013-07-13 15:10:29 +02:00
|
|
|
bool joyup = engine.event.jaxis.value < -16384;
|
|
|
|
bool joydown = engine.event.jaxis.value >= 16384;
|
|
|
|
if(joyup != prevjoyup)
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_UP] = prevjoyup = joyup;
|
2013-07-13 15:10:29 +02:00
|
|
|
if(joydown != prevjoydown)
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_DOWN] = prevjoydown = joydown;
|
2013-07-10 21:37:08 +02:00
|
|
|
} else {
|
2013-07-13 15:10:29 +02:00
|
|
|
bool joyleft = engine.event.jaxis.value < -16384;
|
|
|
|
bool joyright = engine.event.jaxis.value >= 16384;
|
|
|
|
if(joyleft != prevjoyleft)
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_LEFT] = prevjoyleft = joyleft;
|
2013-07-13 15:10:29 +02:00
|
|
|
if(joyright != prevjoyright)
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_RIGHT] = prevjoyright = joyright;
|
2013-07-10 21:37:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
if(engine.event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
|
|
|
engine.paused = 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
engine.fullScreen = !engine.fullScreen;
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetWindowFullscreen(window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
|
|
|
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
|
|
|
|
static int px = -1, py = -1;
|
|
|
|
int x, y;
|
|
|
|
SDL_GetMouseState(&x, &y);
|
|
|
|
if (px == x && py == y) {
|
2013-09-30 16:52:43 +02:00
|
|
|
if(engine.keyState[KEY_UP] && engine.cursor_y > 0)
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_y -= 4;
|
2013-09-30 16:52:43 +02:00
|
|
|
if(engine.keyState[KEY_DOWN] && engine.cursor_y < screen->h - 4)
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_y += 4;
|
2013-09-30 16:52:43 +02:00
|
|
|
if(engine.keyState[KEY_LEFT] && engine.cursor_x > 0)
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_x -= 4;
|
2013-09-30 16:52:43 +02:00
|
|
|
if(engine.keyState[KEY_RIGHT] && engine.cursor_x < screen->w - 4)
|
2013-07-10 21:54:14 +02:00
|
|
|
engine.cursor_x += 4;
|
|
|
|
} else {
|
|
|
|
engine.cursor_x = px = x;
|
|
|
|
engine.cursor_y = py = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void leaveSector()
|
|
|
|
{
|
2013-09-30 16:52:43 +02:00
|
|
|
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;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (engine.done == 0)
|
|
|
|
engine.done = 3;
|
|
|
|
|
|
|
|
if (engine.done == 3)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
engine.done = 2;
|
2015-03-08 15:38:58 +01:00
|
|
|
audio_playSound(SFX_FLY, screen->w / 2);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (engine.done == 2)
|
|
|
|
{
|
|
|
|
player.face = 0;
|
|
|
|
player.x += 12;
|
|
|
|
engine.ssx -= 0.2;
|
2012-03-12 04:16:56 +01:00
|
|
|
if (player.x > (2 * screen->w))
|
2011-08-24 14:14:44 +02:00
|
|
|
engine.done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|