diff --git a/common.mk b/common.mk index 84a8ad0..e79496f 100644 --- a/common.mk +++ b/common.mk @@ -19,7 +19,7 @@ OBJS += hud.o OBJS += i18n.o init.o input.o io.o items.o OBJS += jumpgate.o OBJS += load.o locations.o lookup.o -OBJS += main.o messageBox.o mission.o missionInfo.o modalDialog.o +OBJS += main.o messageBox.o mine.o mission.o missionInfo.o modalDialog.o OBJS += objectives.o options.o OBJS += player.o OBJS += quadtree.o diff --git a/gfx/entities/mine.png b/gfx/entities/mine.png new file mode 100644 index 0000000..bc1df10 Binary files /dev/null and b/gfx/entities/mine.png differ diff --git a/src/battle/effects.c b/src/battle/effects.c index 8b71890..f3684e8 100644 --- a/src/battle/effects.c +++ b/src/battle/effects.c @@ -284,6 +284,36 @@ void addSmallExplosion(void) } } +void addMineExplosion(void) +{ + int i; + Effect *e; + + for (i = 0 ; i < 16 ; i++) + { + e = malloc(sizeof(Effect)); + memset(e, 0, sizeof(Effect)); + battle.effectTail->next = e; + battle.effectTail = e; + + e->type = EFFECT_TEXTURE; + + e->x = self->x + rand() % 16 - rand() % 16; + e->y = self->y + rand() % 16 - rand() % 16; + e->texture = explosionTexture; + e->size = 32 + (rand() % 32); + e->r = 255; + + setRandomFlameHue(e); + + e->a = 32 + (rand() % 192); + e->health = e->a; + + e->x -= e->size / 2; + e->y -= e->size / 2; + } +} + void addLargeExplosion(void) { int i; diff --git a/src/battle/mine.c b/src/battle/mine.c new file mode 100644 index 0000000..4f673f7 --- /dev/null +++ b/src/battle/mine.c @@ -0,0 +1,66 @@ +/* +Copyright (C) 2015-2016 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 "mine.h" + +static void think(void); +static void lookForFighters(void); + +Entity *spawnMine(void) +{ + Entity *mine = spawnEntity(); + + mine->type = ET_MINE; + mine->health = mine->maxHealth = 1; + mine->texture = getTexture("gfx/entities/mine.png"); + mine->action = think; + + return mine; +} + +static void think(void) +{ + self->angle += 0.1; + + if (self->angle >= 360) + { + self->angle -= 360; + } + + lookForFighters(); +} + +static void lookForFighters(void) +{ + Entity *e, **candidates; + int i; + + candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self); + + for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) + { + if (e->health > 0 && e->type == ET_FIGHTER && getDistance(self->x, self->y, e->x, e->y) <= 128) + { + self->health = 0; + + addMineExplosion(); + } + } +} diff --git a/src/battle/mine.h b/src/battle/mine.h new file mode 100644 index 0000000..2eef022 --- /dev/null +++ b/src/battle/mine.h @@ -0,0 +1,29 @@ +/* +Copyright (C) 2015-2016 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 Entity *spawnEntity(void); +extern SDL_Texture *getTexture(char *filename); +extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern int getDistance(int x1, int y1, int x2, int y2); +extern void addMineExplosion(void); + +extern Entity *self; diff --git a/src/defs.h b/src/defs.h index 3f83cd1..7470e83 100644 --- a/src/defs.h +++ b/src/defs.h @@ -151,6 +151,7 @@ enum ET_ITEM, ET_WAYPOINT, ET_JUMPGATE, + ET_MINE, ET_CAPITAL_SHIP_GUN, ET_CAPITAL_SHIP_COMPONENT, ET_CAPITAL_SHIP_ENGINE, diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 4da86a0..66ac781 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -351,6 +351,10 @@ static void loadEntities(cJSON *node) case ET_JUMPGATE: e = spawnJumpgate(); break; + + case ET_MINE: + e = spawnMine(); + break; default: printf("Error: Unhandled entity type: %s\n", cJSON_GetObjectItem(node, "type")->valuestring); diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 420bafd..aa13bd7 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -57,6 +57,7 @@ extern void loadFighters(cJSON *node); extern void loadItems(cJSON *node); extern void loadLocations(cJSON *node); extern void loadSpawners(cJSON *node); +extern Entity *spawnMine(void); extern Battle battle; extern Dev dev; diff --git a/src/system/lookup.c b/src/system/lookup.c index 02bcb85..0bf0e78 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -45,6 +45,7 @@ void initLookups(void) addLookup("ET_WAYPOINT", ET_WAYPOINT); addLookup("ET_JUMPGATE", ET_JUMPGATE); addLookup("ET_CAPITAL_SHIP", ET_CAPITAL_SHIP); + addLookup("ET_MINE", ET_MINE); addLookup("EF_NO_KILL", EF_NO_KILL); addLookup("EF_DISABLED", EF_DISABLED);