2015-03-13 15:10:58 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
|
|
|
Copyright (C) 2011, 2012 Guus Sliepen
|
2016-01-08 03:32:40 +01:00
|
|
|
Copyright (C) 2015, 2016 onpon4 <onpon4@riseup.net>
|
2015-03-13 15:10:58 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 3
|
|
|
|
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
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Starfighter.h"
|
|
|
|
|
2015-09-25 22:28:09 +02:00
|
|
|
bool ship_collision(object *ship, object *otherShip)
|
|
|
|
{
|
|
|
|
float x0 = ship->x;
|
|
|
|
float y0 = ship->y;
|
|
|
|
float w0 = ship->image[0]->w;
|
|
|
|
float h0 = ship->image[0]->h;
|
|
|
|
|
|
|
|
float x2 = otherShip->x;
|
|
|
|
float y2 = otherShip->y;
|
|
|
|
float w1 = otherShip->image[0]->w;
|
|
|
|
float h1 = otherShip->image[0]->h;
|
|
|
|
|
|
|
|
float x1 = x0 + w0;
|
|
|
|
float y1 = y0 + h0;
|
|
|
|
|
|
|
|
float x3 = x2 + w1;
|
|
|
|
float y3 = y2 + h1;
|
|
|
|
|
|
|
|
return !(x1<x2 || x3<x0 || y1<y2 || y3<y0);
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:10:58 +01:00
|
|
|
/*
|
|
|
|
Fill in later...
|
|
|
|
*/
|
|
|
|
void ship_fireBullet(object *ship, int weaponType)
|
|
|
|
{
|
|
|
|
if (ship->reload[weaponType] > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int y = (ship->image[0]->h) / 5;
|
|
|
|
|
|
|
|
// Remove some ammo from the player
|
|
|
|
if ((ship == &player) && (weaponType == 1) && (!engine.cheatAmmo))
|
|
|
|
player.ammo[1]--;
|
|
|
|
|
|
|
|
object *theWeapon = &weapon[ship->weaponType[weaponType]];
|
|
|
|
|
|
|
|
switch(theWeapon->id)
|
|
|
|
{
|
|
|
|
case WT_PLASMA:
|
|
|
|
case WT_SPREAD:
|
|
|
|
case WT_DIRECTIONAL:
|
|
|
|
audio_playSound(SFX_PLASMA, ship->x);
|
|
|
|
break;
|
|
|
|
case WT_ROCKET:
|
|
|
|
audio_playSound(SFX_MISSILE, ship->x);
|
|
|
|
break;
|
|
|
|
case WT_LASER:
|
|
|
|
audio_playSound(SFX_LASER, ship->x);
|
|
|
|
break;
|
|
|
|
case WT_CHARGER:
|
|
|
|
audio_playSound(SFX_PLASMA3, ship->x);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (theWeapon->flags & WF_SPREAD && theWeapon->ammo[0] >= 3)
|
|
|
|
{
|
2015-04-08 03:14:30 +02:00
|
|
|
bullet_add(theWeapon, ship, y * 2, -1);
|
|
|
|
bullet_add(theWeapon, ship, y * 4, 1);
|
2015-03-13 15:10:58 +01:00
|
|
|
|
2015-04-08 03:14:30 +02:00
|
|
|
if (theWeapon->ammo[0] != 4)
|
2015-03-13 15:10:58 +01:00
|
|
|
bullet_add(theWeapon, ship, y * 3, 0);
|
2015-04-08 03:14:30 +02:00
|
|
|
else
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
2015-04-08 03:14:30 +02:00
|
|
|
bullet_add(theWeapon, ship, y * 2, 0);
|
|
|
|
bullet_add(theWeapon, ship, y * 4, 0);
|
2015-03-13 15:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 03:14:30 +02:00
|
|
|
if (theWeapon->ammo[0] == 5)
|
|
|
|
{
|
|
|
|
bullet_add(theWeapon, ship, y * 1, -2);
|
|
|
|
bullet_add(theWeapon, ship, y * 5, 2);
|
|
|
|
}
|
2015-03-13 15:10:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-07 02:35:37 +01:00
|
|
|
if (theWeapon->ammo[0] & 1)
|
2015-03-13 15:10:58 +01:00
|
|
|
bullet_add(theWeapon, ship, y * 3, 0);
|
|
|
|
|
2016-01-07 02:35:37 +01:00
|
|
|
if (theWeapon->ammo[0] >= 2)
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
|
|
|
bullet_add(theWeapon, ship, y * 2, 0);
|
|
|
|
bullet_add(theWeapon, ship, y * 4, 0);
|
|
|
|
}
|
|
|
|
|
2016-01-07 02:35:37 +01:00
|
|
|
if (theWeapon->ammo[0] >= 4)
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
|
|
|
bullet_add(theWeapon, ship, y * 1, 0);
|
|
|
|
bullet_add(theWeapon, ship, y * 5, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the weapon reload time. Double it if it is not friendly or
|
|
|
|
// a boss or Kline
|
|
|
|
ship->reload[weaponType] = theWeapon->reload[0];
|
|
|
|
if ((ship->flags & FL_WEAPCO) && (ship != &aliens[ALIEN_BOSS]) &&
|
|
|
|
(ship != &aliens[ALIEN_KLINE]) && (theWeapon->id != W_LASER))
|
|
|
|
ship->reload[weaponType] *= 2;
|
|
|
|
|
|
|
|
if ((engine.cheatAmmo) || (theWeapon->id == WT_LASER))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((ship == &player) && (weaponType == 0))
|
|
|
|
{
|
|
|
|
if (player.ammo[0] > 0)
|
|
|
|
{
|
|
|
|
player.ammo[0]--;
|
|
|
|
if (player.ammo[0] <= 0)
|
|
|
|
{
|
2015-05-21 01:41:43 +02:00
|
|
|
weapon[W_PLAYER_WEAPON].ammo[0] = game.minPlasmaOutput;
|
|
|
|
weapon[W_PLAYER_WEAPON].damage = game.minPlasmaDamage;
|
|
|
|
weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[game.minPlasmaRate];
|
2015-03-13 15:10:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 15:34:29 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Fill in later...
|
|
|
|
*/
|
|
|
|
void ship_fireRay(object *ship)
|
|
|
|
{
|
|
|
|
SDL_Rect ray;
|
|
|
|
|
|
|
|
if (ship->face == 0)
|
|
|
|
{
|
|
|
|
ray.x = (int)(ship->x + ship->image[0]->w);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ray.x = (int)(ship->x - 800);
|
|
|
|
}
|
|
|
|
ray.y = (int)(ship->y + ship->engineY - 1);
|
|
|
|
ray.h = 3;
|
|
|
|
ray.w = 800;
|
|
|
|
|
|
|
|
int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
|
|
|
|
SDL_FillRect(screen, &ray, red);
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_addBuffer(ray.x, ray.y, ray.w, ray.h);
|
2015-03-17 15:34:29 +01:00
|
|
|
|
|
|
|
if (ship != &player)
|
|
|
|
{
|
|
|
|
if (player.shield > 0)
|
|
|
|
{
|
2015-09-25 22:28:09 +02:00
|
|
|
if (game_collision(player.x, player.y, player.image[0]->w,
|
2016-01-08 22:36:20 +01:00
|
|
|
player.image[0]->h, ray.x, ray.y, ray.w, ray.h) &&
|
|
|
|
(!engine.cheatShield) && (engine.missionCompleteTimer == 0))
|
2015-03-17 15:34:29 +01:00
|
|
|
{
|
|
|
|
if (player.shield > engine.lowShield)
|
|
|
|
{
|
|
|
|
if (player.shield - 1 <= engine.lowShield)
|
|
|
|
{
|
|
|
|
setInfoLine("!!! WARNING: SHIELD LOW !!!", FONT_RED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
player.shield--;
|
|
|
|
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
explosion_add(player.x, player.y, SP_SMALL_EXPLOSION);
|
2015-03-17 15:34:29 +01:00
|
|
|
audio_playSound(SFX_HIT, player.x);
|
|
|
|
if (player.shield < 1)
|
|
|
|
{
|
|
|
|
audio_playSound(SFX_DEATH, player.x);
|
|
|
|
audio_playSound(SFX_EXPLOSION, player.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
|
|
|
{
|
|
|
|
if (aliens[i].flags & FL_IMMORTAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((aliens[i].shield > 0) && (ship != &aliens[i]) &&
|
|
|
|
(ship->classDef != aliens[i].classDef))
|
|
|
|
{
|
2015-09-25 22:28:09 +02:00
|
|
|
if (game_collision(aliens[i].x, aliens[i].y, aliens[i].image[0]->w,
|
2015-03-17 15:34:29 +01:00
|
|
|
aliens[i].image[0]->h, ray.x, ray.y, ray.w, ray.h))
|
|
|
|
{
|
|
|
|
alien_hurt(&aliens[i], ship->owner, 1, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ship->ammo[0]--;
|
|
|
|
if (ship->ammo[0] < 1)
|
|
|
|
ship->flags &= ~FL_FIRERAY;
|
|
|
|
}
|