diff --git a/common.mk b/common.mk index aad931e..c2c6c4b 100644 --- a/common.mk +++ b/common.mk @@ -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 diff --git a/src/combat/combat.c b/src/combat/combat.c index 2eb4fe3..617302c 100644 --- a/src/combat/combat.c +++ b/src/combat/combat.c @@ -118,3 +118,8 @@ static int isBlockedByEntities(Entity *src, Entity *dest) return 0; } + +int enemyCanSeePlayer(Entity *e) +{ + return hasLineOfSight(e, world.bob); +} diff --git a/src/combat/explosions.c b/src/combat/explosions.c new file mode 100644 index 0000000..af89e58 --- /dev/null +++ b/src/combat/explosions.c @@ -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); + } + } + } + } + } +} diff --git a/src/combat/explosions.h b/src/combat/explosions.h new file mode 100644 index 0000000..10217be --- /dev/null +++ b/src/combat/explosions.h @@ -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); diff --git a/src/defs.h b/src/defs.h index e1d7eb0..7ff15e6 100644 --- a/src/defs.h +++ b/src/defs.h @@ -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 }; diff --git a/src/system/sound.c b/src/system/sound.c new file mode 100644 index 0000000..958773b --- /dev/null +++ b/src/system/sound.c @@ -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) +{ +} diff --git a/src/system/sound.h b/src/system/sound.h new file mode 100644 index 0000000..8ad0dc9 --- /dev/null +++ b/src/system/sound.h @@ -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" diff --git a/src/world/effects.c b/src/world/effects.c index ea733cd..6056fff 100644 --- a/src/world/effects.c +++ b/src/world/effects.c @@ -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; diff --git a/src/world/entities.c b/src/world/entities.c index 2f8819f..cac9283 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -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) +{ +} diff --git a/src/world/player.c b/src/world/player.c new file mode 100644 index 0000000..2fff4f3 --- /dev/null +++ b/src/world/player.c @@ -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) +{ +} diff --git a/src/world/player.h b/src/world/player.h new file mode 100644 index 0000000..c3b03ff --- /dev/null +++ b/src/world/player.h @@ -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" +