Explosions.

This commit is contained in:
Steve 2018-01-22 07:44:15 +00:00
parent 821fa54110
commit 5b37609404
11 changed files with 228 additions and 2 deletions

View File

@ -10,15 +10,16 @@ DEPS += defs.h structs.h
OBJS += camera.o combat.o
OBJS += draw.o
OBJS += effects.o entities.o
OBJS += effects.o entities.o explosions.o
OBJS += game.o
OBJS += hud.o
OBJS += init.o input.o io.o
OBJS += lookup.o
OBJS += main.o map.o maths.o
OBJS += objectives.o
OBJS += player.o
OBJS += quadtree.o
OBJS += sprites.o
OBJS += sound.o sprites.o
OBJS += text.o textures.o title.o triggers.o
OBJS += util.o
OBJS += widgets.o

View File

@ -118,3 +118,8 @@ static int isBlockedByEntities(Entity *src, Entity *dest)
return 0;
}
int enemyCanSeePlayer(Entity *e)
{
return hasLineOfSight(e, world.bob);
}

79
src/combat/explosions.c Normal file
View File

@ -0,0 +1,79 @@
/*
Copyright (C) 2018 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.
*/
#include "explosions.h"
static SDL_Rect radiusRect;
void addExplosion(float x, float y, int radius, Entity *owner)
{
Entity **candidates, *e;
float power;
int i;
playSound(SND_EXPLOSION, CH_EXPLODE);
/* assuming x and y were from the top left of the entity */
x += radius / 2;
y += radius / 2;
addExplosionEffect(x, y, radius, radius / 4);
radiusRect.x = (int) (x - radius);
radiusRect.y = (int) (y - radius);
radiusRect.w = radius * 2;
radiusRect.h = radius * 2;
candidates = getAllEntsWithin(radiusRect.x, radiusRect.y, radiusRect.w, radiusRect.h, NULL);
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
{
if (e != owner && (e->type == ET_BOB || e->type == ET_ENEMY || e->type == ET_DESTRUCTABLE || e->type == ET_BOSS))
{
power = radius - getDistance(e->x + (e->w / 2), e->y + (e->h / 2), x, y);
if (power > 0)
{
if (!(e->flags & EF_IMMUNE))
{
if (e->flags & EF_BOMB_SHIELD)
{
applyEntityDamage(e, 2);
}
else
{
applyEntityDamage(e, (int) power);
}
if (e->type == ET_BOB)
{
stunPlayer();
}
if (e->health <= 0)
{
e->dx = rrnd(-radius / 8, radius / 8);
e->dy = rrnd(-5, 0);
}
}
}
}
}
}

29
src/combat/explosions.h Normal file
View File

@ -0,0 +1,29 @@
/*
Copyright (C) 2018 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.
*/
#include "../common.h"
extern int rrnd(int low, int high);
extern void stunPlayer(void);
extern void applyEntityDamage(Entity *e, int amount);
extern void addExplosionEffect(int x, int y, int dx, int dy);
extern void playSound(int snd, int ch);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern int getDistance(int x1, int y1, int x2, int y2);

View File

@ -79,10 +79,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define ET_ENEMY 0
#define ET_KEY 1
#define ET_MIA 2
#define ET_BOB 3
#define ET_DESTRUCTABLE 4
#define ET_BOSS 5
#define EF_NONE 0
#define EF_HEART_CELL (2 << 0)
#define EF_WEIGHTLESS (2 << 1)
#define EF_BOMB_SHIELD (2 << 2)
#define EF_IMMUNE (2 << 3)
enum
{
@ -129,8 +134,14 @@ enum
MSG_OBJECTIVE
};
enum
{
SND_EXPLOSION
};
enum
{
CH_PLAYER,
CH_EXPLODE,
CH_MAX
};

25
src/system/sound.c Normal file
View File

@ -0,0 +1,25 @@
/*
Copyright (C) 2018 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.
*/
#include "sound.h"
void playSound(int snd, int ch)
{
}

21
src/system/sound.h Normal file
View File

@ -0,0 +1,21 @@
/*
Copyright (C) 2018 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.
*/
#include "../common.h"

View File

@ -34,6 +34,10 @@ void initEffects(void)
debris[2] = getSpriteIndex("Debris3");
}
void addExplosionEffect(int x, int y, float dx, float dy)
{
}
void addSmallFleshChunk(double x, double y)
{
Entity *chunk;

View File

@ -23,3 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void activateEntities(char *names, int activate)
{
}
void applyEntityDamage(Entity *e, int amount)
{
}

25
src/world/player.c Normal file
View File

@ -0,0 +1,25 @@
/*
Copyright (C) 2018 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.
*/
#include "player.h"
void stunPlayer(void)
{
}

22
src/world/player.h Normal file
View File

@ -0,0 +1,22 @@
/*
Copyright (C) 2018 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.
*/
#include "../common.h"