Added swapSelf() to handle current entity handling.

This commit is contained in:
Steve 2018-02-05 08:37:07 +00:00
parent c3ca4a39e2
commit d10356c42c
11 changed files with 37 additions and 0 deletions

View File

@ -55,11 +55,15 @@ void addExplosion(float x, float y, int radius, Entity *owner)
{ {
if (e->flags & EF_BOMB_SHIELD) if (e->flags & EF_BOMB_SHIELD)
{ {
swapSelf(e);
e->applyDamage(2); e->applyDamage(2);
swapSelf(e);
} }
else else
{ {
swapSelf(e);
e->applyDamage((int) power); e->applyDamage((int) power);
swapSelf(e);
} }
if (e->type == ET_BOB) if (e->type == ET_BOB)

View File

@ -26,3 +26,6 @@ extern void addExplosionEffect(int x, int y, int dx, int dy);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); 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 int getDistance(int x1, int y1, int x2, int y2);
extern void swapSelf(Entity *e);
extern Entity *self;

View File

@ -97,7 +97,9 @@ static void touch(Entity *other)
} }
else if (other != b->owner && (!(other->flags & EF_IGNORE_BULLETS)) && b->owner->type != other->type) else if (other != b->owner && (!(other->flags & EF_IGNORE_BULLETS)) && b->owner->type != other->type)
{ {
swapSelf(other);
other->applyDamage(b->damage); other->applyDamage(b->damage);
swapSelf(other);
if (other->flags & EF_EXPLODES) if (other->flags & EF_EXPLODES)
{ {

View File

@ -25,6 +25,7 @@ extern void initEntity(Entity *e);
extern void addSmallFleshChunk(float x, float y); extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y); extern void addSparkParticles(float x, float y);
extern Bullet *createBaseBullet(Unit *owner); extern Bullet *createBaseBullet(Unit *owner);
extern void swapSelf(Entity *e);
extern Camera camera; extern Camera camera;
extern Entity *self; extern Entity *self;

View File

@ -87,7 +87,9 @@ static void touch(Entity *other)
if (!(other->flags & EF_BOMB_SHIELD)) if (!(other->flags & EF_BOMB_SHIELD))
{ {
swapSelf(other);
other->applyDamage(25); other->applyDamage(25);
swapSelf(other);
} }
explode(); explode();

View File

@ -26,6 +26,7 @@ extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y); extern void addSparkParticles(float x, float y);
extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addExplosion(float x, float y, int radius, Entity *owner);
extern void addScorchDecal(int x, int y); extern void addScorchDecal(int x, int y);
extern void swapSelf(Entity *e);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -68,7 +68,9 @@ static void touch(Entity *other)
playSound(SND_FLESH_HIT, CH_ANY); playSound(SND_FLESH_HIT, CH_ANY);
} }
swapSelf(other);
other->applyDamage(2); other->applyDamage(2);
swapSelf(other);
if (b->owner->type == world.bob->type) if (b->owner->type == world.bob->type)
{ {

View File

@ -26,6 +26,7 @@ extern void initLaser(Bullet *b);
extern void addSmallFleshChunk(float x, float y); extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y); extern void addSparkParticles(float x, float y);
extern void stunBob(void); extern void stunBob(void);
extern void swapSelf(Entity *e);
extern Entity *self; extern Entity *self;
extern Game game; extern Game game;

View File

@ -119,12 +119,16 @@ static void touch(Entity *other)
if (t->offTime != 0) if (t->offTime != 0)
{ {
swapSelf(other);
other->applyDamage((int) (other->healthMax / 4)); other->applyDamage((int) (other->healthMax / 4));
swapSelf(other);
} }
else else
{ {
/* instant kill */ /* instant kill */
swapSelf(other);
other->applyDamage((int) other->health); other->applyDamage((int) other->health);
swapSelf(other);
} }
} }

View File

@ -29,6 +29,7 @@ extern int rrnd(int low, int high);
extern void stunBob(void); extern void stunBob(void);
extern void addSparkParticles(float x, float y); extern void addSparkParticles(float x, float y);
extern void addSmallFleshChunk(float x, float y); extern void addSmallFleshChunk(float x, float y);
extern void swapSelf(Entity *e);
extern Entity *self; extern Entity *self;
extern World world; extern World world;

View File

@ -982,3 +982,19 @@ static void addTouched(Entity *e)
} }
} }
} }
void swapSelf(Entity *e)
{
static Entity *oldSelf = NULL;
if (!oldSelf)
{
oldSelf = self;
self = e;
}
else
{
self = oldSelf;
oldSelf = NULL;
}
}