From 1b426ec9d3c3c84f3de9447fb9fb3c07f0e81aa8 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 08:08:17 +0000 Subject: [PATCH] Decoration. --- common.mk | 5 +- src/structs.h | 2 + src/world/entities/decoration/debris.c | 65 ++++++++++++++++++++++ src/world/entities/decoration/debris.h | 27 +++++++++ src/world/entities/decoration/fleshChunk.c | 62 +++++++++++++++++++++ src/world/entities/decoration/fleshChunk.h | 26 +++++++++ 6 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 src/world/entities/decoration/debris.c create mode 100644 src/world/entities/decoration/debris.h create mode 100644 src/world/entities/decoration/fleshChunk.c create mode 100644 src/world/entities/decoration/fleshChunk.h diff --git a/common.mk b/common.mk index e81af85..a8cb71a 100644 --- a/common.mk +++ b/common.mk @@ -14,6 +14,7 @@ SEARCHPATH += src/world/entities SEARCHPATH += src/world/entities/blobs SEARCHPATH += src/world/entities/boss SEARCHPATH += src/world/entities/cannons +SEARCHPATH += src/world/entities/decoration SEARCHPATH += src/world/entities/items vpath %.c $(SEARCHPATH) @@ -24,9 +25,9 @@ DEPS += defs.h structs.h OBJS += atlas.o OBJS += battery.o blaze.o bob.o boss.o blobBoss.o OBJS += camera.o cannon.o cell.o cherry.o combat.o consumable.o -OBJS += draw.o +OBJS += debris.o draw.o OBJS += effects.o entities.o explosions.o eyeDroidCommander.o -OBJS += frost.o +OBJS += fleshChunk.o frost.o OBJS += game.o OBJS += heart.o hub.o hud.o OBJS += init.o input.o io.o item.o items.o diff --git a/src/structs.h b/src/structs.h index 7d16a1a..2547932 100644 --- a/src/structs.h +++ b/src/structs.h @@ -109,6 +109,8 @@ struct Entity { int ty; int reload; int isOnGround; + int effectType; + int bleedTime; int facing; int damage; int weaponType; diff --git a/src/world/entities/decoration/debris.c b/src/world/entities/decoration/debris.c new file mode 100644 index 0000000..fde7a09 --- /dev/null +++ b/src/world/entities/decoration/debris.c @@ -0,0 +1,65 @@ +/* +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 "debris.h" + +static void tick(void); +static void action(void); +static void touch(Entity *other); + +void initDebris(Entity *e) +{ + initEntity(e); + + e->effectType = rand() % 2; + + e->flags |= EF_BOUNCES | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_NO_TELEPORT; + + e->tick = tick; + e->action = action; + e->touch = touch; +} + +static void tick(void) +{ + self->health--; +} + +static void action(void) +{ + if (self->effectType == 0) + { + addFlameParticles(self->x + (rand() % self->w), self->y + (rand() % self->h)); + } + else + { + addSmokeParticles(self->x + (rand() % self->w), self->y + (rand() % self->h)); + } + + self->thinkTime = 1; +} + +static void touch(Entity *other) +{ + if (other == NULL) + { + self->dx *= 0.9; + } +} diff --git a/src/world/entities/decoration/debris.h b/src/world/entities/decoration/debris.h new file mode 100644 index 0000000..0023aa4 --- /dev/null +++ b/src/world/entities/decoration/debris.h @@ -0,0 +1,27 @@ +/* +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 void initEntity(Entity *e); +extern void addFlameParticles(float x, float y); +extern void addSmokeParticles(float x, float y); + +extern Entity *self; diff --git a/src/world/entities/decoration/fleshChunk.c b/src/world/entities/decoration/fleshChunk.c new file mode 100644 index 0000000..8d6ce6e --- /dev/null +++ b/src/world/entities/decoration/fleshChunk.c @@ -0,0 +1,62 @@ +/* +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 "fleshChunk.h" + +static void tick(void); +static void action(void); +static void touch(Entity *other); + +void initFleshChunk(Entity *e) +{ + initEntity(e); + + e->flags |= EF_BOUNCES | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_NO_TELEPORT; + + e->bleedTime = FPS * 3; + + e->tick = tick; + e->action = action; + e->touch = touch; +} + +static void tick(void) +{ + self->health--; + self->bleedTime--; +} + +static void action(void) +{ + if (self->bleedTime > 0) + { + addBlood(self->x + (rand() % self->w), self->y + (rand() % self->h)); + } + + self->thinkTime = 1; +} + +static void touch(Entity *other) +{ + if (other == NULL) + { + self->dx *= 0.9; + } +} diff --git a/src/world/entities/decoration/fleshChunk.h b/src/world/entities/decoration/fleshChunk.h new file mode 100644 index 0000000..6c9c266 --- /dev/null +++ b/src/world/entities/decoration/fleshChunk.h @@ -0,0 +1,26 @@ +/* +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 void initEntity(Entity *e); +extern void addBlood(float x, float y); + +extern Entity *self;