2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
|
|
|
|
|
|
|
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 2
|
|
|
|
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, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
#include "Starfighter.h"
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Create a new explosion based on supplied parameters.
|
|
|
|
The "type" will actually be used as an explosion frame check.
|
|
|
|
All explosion types have 4 images. The "thinktime" will be used
|
|
|
|
to change frames on a 21, 14, 7 basis.
|
|
|
|
*/
|
|
|
|
void addExplosion(float x, float y, int type)
|
|
|
|
{
|
|
|
|
object *explosion = new object;
|
|
|
|
|
|
|
|
explosion->next = NULL;
|
2011-08-26 16:14:58 +02:00
|
|
|
explosion->active = true;
|
2011-08-24 14:14:44 +02:00
|
|
|
explosion->x = x;
|
|
|
|
explosion->y = y;
|
|
|
|
explosion->thinktime = 28;
|
|
|
|
explosion->face = type;
|
2011-08-26 23:53:46 +02:00
|
|
|
explosion->image[0] = shape[type];
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
engine.explosionTail->next = explosion;
|
|
|
|
engine.explosionTail = explosion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This very simply just adds a tiny explosion at the coordinate specified.
|
|
|
|
* It creates a small engine like effect.
|
|
|
|
*/
|
|
|
|
void addEngine(object *craft)
|
|
|
|
{
|
|
|
|
if (rand() % 2 == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float x = craft->x + (craft->engineX * craft->face);
|
|
|
|
float y = craft->y + craft->engineY;
|
|
|
|
|
2011-08-26 23:27:16 +02:00
|
|
|
y += rrand(-3, 3);
|
2011-08-24 14:14:44 +02:00
|
|
|
addExplosion(x, y, E_TINY_EXPLOSION);
|
|
|
|
}
|
|
|
|
|
2011-08-27 00:29:01 +02:00
|
|
|
static bool isOnScreen(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
return (x + w > 0) && (x < 800) && (y + h > 0) && (y < 600);
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Loops through active explosions and decrements their think time.
|
|
|
|
If their thinktime is divisable by 5, then the frame is changed to
|
|
|
|
the next one up (for example 0->1->2-3). When their think time is 0,
|
|
|
|
the explosion is killed off.
|
|
|
|
*/
|
|
|
|
void doExplosions()
|
|
|
|
{
|
|
|
|
object *prevExplosion = engine.explosionHead;
|
|
|
|
object *explosion = engine.explosionHead;
|
|
|
|
engine.explosionTail = engine.explosionHead;
|
|
|
|
|
|
|
|
while (explosion->next != NULL)
|
|
|
|
{
|
|
|
|
explosion = explosion->next;
|
|
|
|
|
2011-08-26 16:14:58 +02:00
|
|
|
if (explosion->active)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
explosion->x += engine.ssx;
|
|
|
|
explosion->y += engine.ssy;
|
|
|
|
|
|
|
|
if (isOnScreen((int)explosion->x, (int)explosion->y, explosion->image[0]->w, explosion->image[0]->h))
|
2011-08-26 23:53:46 +02:00
|
|
|
blit(explosion->image[0], (int)explosion->x, (int)explosion->y);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2011-08-24 23:08:48 +02:00
|
|
|
if(rand() % 7 == 0)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2011-08-24 23:08:48 +02:00
|
|
|
explosion->thinktime -= 7;
|
|
|
|
|
|
|
|
if(explosion->thinktime < 1)
|
|
|
|
{
|
2011-08-26 16:14:58 +02:00
|
|
|
explosion->active = false;
|
2011-08-24 23:08:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
explosion->face++;
|
2011-08-26 23:53:46 +02:00
|
|
|
explosion->image[0] = shape[explosion->face];
|
2011-08-24 23:08:48 +02:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-26 16:14:58 +02:00
|
|
|
if (explosion->active)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
prevExplosion = explosion;
|
|
|
|
engine.explosionTail = explosion;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prevExplosion->next = explosion->next;
|
|
|
|
delete explosion;
|
2012-03-11 15:21:38 +01:00
|
|
|
explosion = prevExplosion;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|