2 Copyright (C) 2003 Parallel Realities
3 Copyright (C) 2011, 2012 Guus Sliepen
4 Copyright (C) 2015, 2016 onpon4 <onpon4@riseup.net>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 3
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "Starfighter.h"
22 bool ship_collision(object *ship, object *otherShip)
26 float w0 = ship->image[0]->w;
27 float h0 = ship->image[0]->h;
29 float x2 = otherShip->x;
30 float y2 = otherShip->y;
31 float w1 = otherShip->image[0]->w;
32 float h1 = otherShip->image[0]->h;
40 return !(x1<x2 || x3<x0 || y1<y2 || y3<y0);
46 void ship_fireBullet(object *ship, int weaponType)
48 if (ship->reload[weaponType] > 0)
51 int y = (ship->image[0]->h) / 5;
53 // Remove some ammo from the player
54 if ((ship == &player) && (weaponType == 1) && (!engine.cheatAmmo))
57 object *theWeapon = &weapon[ship->weaponType[weaponType]];
64 audio_playSound(SFX_PLASMA, ship->x, ship->y);
67 audio_playSound(SFX_MISSILE, ship->x, ship->y);
70 audio_playSound(SFX_LASER, ship->x, ship->y);
73 audio_playSound(SFX_PLASMA3, ship->x, ship->y);
77 if (theWeapon->flags & WF_SPREAD && theWeapon->ammo[0] >= 3)
79 bullet_add(theWeapon, ship, y * 2, -1);
80 bullet_add(theWeapon, ship, y * 4, 1);
82 if (theWeapon->ammo[0] != 4)
83 bullet_add(theWeapon, ship, y * 3, 0);
86 bullet_add(theWeapon, ship, y * 2, 0);
87 bullet_add(theWeapon, ship, y * 4, 0);
90 if (theWeapon->ammo[0] == 5)
92 bullet_add(theWeapon, ship, y * 1, -2);
93 bullet_add(theWeapon, ship, y * 5, 2);
98 if (theWeapon->ammo[0] & 1)
99 bullet_add(theWeapon, ship, y * 3, 0);
101 if (theWeapon->ammo[0] >= 2)
103 bullet_add(theWeapon, ship, y * 2, 0);
104 bullet_add(theWeapon, ship, y * 4, 0);
107 if (theWeapon->ammo[0] >= 4)
109 bullet_add(theWeapon, ship, y * 1, 0);
110 bullet_add(theWeapon, ship, y * 5, 0);
114 // Reset the weapon reload time. Double it if it is not friendly or
116 ship->reload[weaponType] = theWeapon->reload[0];
117 if ((ship->flags & FL_WEAPCO) && (ship != &aliens[ALIEN_BOSS]) &&
118 (ship != &aliens[ALIEN_KLINE]) && (theWeapon->id != W_LASER))
119 ship->reload[weaponType] *= 2;
121 if ((engine.cheatAmmo) || (theWeapon->id == WT_LASER))
124 if ((ship == &player) && (weaponType == 0))
126 if (player.ammo[0] > 0)
129 if (player.ammo[0] <= 0)
131 weapon[W_PLAYER_WEAPON].ammo[0] = game.minPlasmaOutput;
132 weapon[W_PLAYER_WEAPON].damage = game.minPlasmaDamage;
133 weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[game.minPlasmaRate];
142 void ship_fireRay(object *ship)
148 ray.x = (int)(ship->x + ship->image[0]->w);
152 ray.x = (int)(ship->x - 800);
154 ray.y = (int)(ship->y + ship->engineY - 1);
158 int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
159 SDL_FillRect(screen, &ray, red);
160 screen_addBuffer(ray.x, ray.y, ray.w, ray.h);
164 if (player.shield > 0)
166 if (game_collision(player.x, player.y, player.image[0]->w,
167 player.image[0]->h, ray.x, ray.y, ray.w, ray.h) &&
168 (!engine.cheatShield) && (engine.missionCompleteTimer == 0))
170 if (player.shield > engine.lowShield)
172 if (player.shield - 1 <= engine.lowShield)
174 setInfoLine("!!!
\8cx
\8d\90:
\83V
\81[
\83\8b\83h
\92á
\89º !!!", FONT_RED);
179 explosion_add(player.x, player.y, SP_SMALL_EXPLOSION);
180 audio_playSound(SFX_HIT, player.x, player.y);
181 if (player.shield < 1)
183 audio_playSound(SFX_DEATH, player.x, player.y);
184 audio_playSound(SFX_EXPLOSION, player.x, player.y);
190 for (int i = 0 ; i < ALIEN_MAX ; i++)
192 if (aliens[i].flags & FL_IMMORTAL)
195 if ((aliens[i].shield > 0) && (ship != &aliens[i]) &&
196 (ship->classDef != aliens[i].classDef))
198 if (game_collision(aliens[i].x, aliens[i].y, aliens[i].image[0]->w,
199 aliens[i].image[0]->h, ray.x, ray.y, ray.w, ray.h))
201 alien_hurt(&aliens[i], ship->owner, 1, false);
207 if (ship->ammo[0] < 1)
208 ship->flags &= ~FL_FIRERAY;