Added destructable.

This commit is contained in:
Steve 2018-01-27 08:28:50 +00:00
parent 45244303f8
commit e4f9c33c74
5 changed files with 119 additions and 1 deletions

View File

@ -16,6 +16,7 @@ SEARCHPATH += src/world/entities/boss
SEARCHPATH += src/world/entities/cannons
SEARCHPATH += src/world/entities/decoration
SEARCHPATH += src/world/entities/items
SEARCHPATH += src/world/entities/misc
vpath %.c $(SEARCHPATH)
vpath %.h $(SEARCHPATH)
@ -25,7 +26,7 @@ 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 += debris.o draw.o
OBJS += debris.o destructable.o draw.o
OBJS += effects.o entities.o explosions.o eyeDroidCommander.o
OBJS += fleshChunk.o frost.o
OBJS += game.o

View File

@ -246,6 +246,7 @@ Bullet *createBaseBullet(Entity *owner)
bullet->damage = 1;
bullet->owner = owner;
bullet->health = FPS * 3;
bullet->flags |= EF_WEIGHTLESS | EF_IGNORE_BULLETS | EF_NO_ENVIRONMENT | EF_KILL_OFFSCREEN | EF_NO_TELEPORT;
return bullet;
}

View File

@ -93,6 +93,7 @@ struct Entity {
unsigned long uniqueId;
char name[MAX_NAME_LENGTH];
char spriteName[MAX_NAME_LENGTH];
char targetNames[MAX_DESCRIPTION_LENGTH];
int type;
float x;
float y;
@ -344,6 +345,7 @@ struct Bullet {
float dx;
float dy;
int sprite[2];
long flags;
Entity *owner;
Bullet *next;
};

View File

@ -0,0 +1,83 @@
/*
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 "destructable.h"
static void applyDamage(int amount);
static void action(void);
void initDestructable(Entity *e)
{
e->isMissionTarget = 1;
STRNCPY(e->spriteName, "Crate4", MAX_NAME_LENGTH);
e->flags |= EF_EXPLODES;
e->health = e->healthMax = 10;
e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex(e->spriteName);
e->applyDamage = applyDamage;
e->action = action;
}
static void applyDamage(int amount)
{
if (self->health > 0)
{
self->health -= amount;
}
}
static void action(void)
{
int mx, my;
if (self->health <= 0)
{
self->health--;
if (self->health % 3 == 0)
{
mx = (int) ((self->x + (self->w / 2)) / MAP_TILE_SIZE);
my = (int) ((self->y + self->h) / MAP_TILE_SIZE);
addScorchDecal(mx, my);
addExplosion(self->x, self->y, 50, self);
self->dx = rrnd(-10, 10);
self->dy = rrnd(-10, 10);
}
if (self->health <= -50)
{
dropCarriedItem();
updateObjective(self->name);
if (strlen(self->targetNames) > 0)
{
activateEntities(self->targetNames, 1);
}
self->alive = ALIVE_DEAD;
}
}
}

View File

@ -0,0 +1,31 @@
/*
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 activateEntities(char *names, int activate);
extern void dropCarriedItem(void);
extern int rrnd(int low, int high);
extern void addExplosion(float x, float y, int radius, Entity *owner);
extern void addScorchDecal(int x, int y);
extern int getSpriteIndex(char *name);
extern void updateObjective(char *targetName);
extern Entity *self;