Moved all rope handling code to rope.c.
This commit is contained in:
parent
67967a2a34
commit
9ce6624fc0
|
@ -118,6 +118,8 @@ void doEntities(void)
|
|||
battle.playerSelect = battle.epic;
|
||||
}
|
||||
|
||||
cutRope(e);
|
||||
|
||||
prev->next = e->next;
|
||||
free(e);
|
||||
e = prev;
|
||||
|
|
|
@ -31,6 +31,7 @@ extern void removeFromGrid(Entity *e);
|
|||
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
|
||||
extern void doRope(Entity *e);
|
||||
extern void drawRope(Entity *e);
|
||||
extern void cutRope(Entity *e);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
static void think(void);
|
||||
static void handleFleeingEntities(void);
|
||||
static void cutTowRope(Entity *e);
|
||||
|
||||
Entity *spawnExtractionPoint(void)
|
||||
{
|
||||
|
@ -57,28 +56,13 @@ static void handleFleeingEntities(void)
|
|||
Entity *e, **candidates;
|
||||
int i;
|
||||
|
||||
candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self);
|
||||
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->flags & EF_FLEEING && getDistance(e->x, e->y, self->x, self->y) <= 64)
|
||||
if (e->health > 0 && e->flags & EF_FLEEING && getDistance(self->x, self->y, e->x, e->y) <= 64)
|
||||
{
|
||||
e->alive = ALIVE_ESCAPED;
|
||||
|
||||
cutTowRope(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cutTowRope(Entity *attachment)
|
||||
{
|
||||
Entity *e;
|
||||
|
||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
if (e->towing == attachment)
|
||||
{
|
||||
e->towing = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ extern SDL_Texture *getTexture(char *filename);
|
|||
extern Entity *spawnEntity(void);
|
||||
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 destroyRope(Entity *owner);
|
||||
|
||||
extern Battle battle;
|
||||
extern Entity *self;
|
||||
|
|
|
@ -27,7 +27,6 @@ static void spinDie(void);
|
|||
static void straightDie(void);
|
||||
static void randomizeDart(Entity *dart);
|
||||
static void randomizeDartGuns(Entity *dart);
|
||||
static void attachRope(void);
|
||||
|
||||
Entity *spawnFighter(char *name, int x, int y, int side)
|
||||
{
|
||||
|
@ -335,30 +334,6 @@ static void separate(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void attachRope(void)
|
||||
{
|
||||
int i, distance;
|
||||
Entity *e, **candidates;
|
||||
|
||||
if ((self->flags & EF_HAS_ROPE) && self->towing == NULL)
|
||||
{
|
||||
candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self);
|
||||
|
||||
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
||||
{
|
||||
if ((e->flags & EF_DISABLED) && e->alive == ALIVE_ALIVE)
|
||||
{
|
||||
distance = getDistance(e->x, e->y, self->x, self->y);
|
||||
|
||||
if (distance > 0 && distance <= 32)
|
||||
{
|
||||
self->towing = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawFighter(Entity *e)
|
||||
{
|
||||
SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png");
|
||||
|
|
|
@ -42,7 +42,7 @@ extern void checkTrigger(char *name, int type);
|
|||
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
|
||||
extern Entity *spawnEntity(void);
|
||||
extern void adjustObjectiveTargetValue(char *name, int type, int amount);
|
||||
extern void addRope(Entity *src, Entity *dest);
|
||||
extern void attachRope(void);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -20,6 +20,32 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "rope.h"
|
||||
|
||||
void attachRope(void)
|
||||
{
|
||||
int i, distance;
|
||||
Entity *e, **candidates;
|
||||
|
||||
if ((self->flags & EF_HAS_ROPE) && self->towing == NULL)
|
||||
{
|
||||
candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self);
|
||||
|
||||
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
||||
{
|
||||
if ((e->flags & EF_DISABLED) && e->alive == ALIVE_ALIVE)
|
||||
{
|
||||
distance = getDistance(e->x, e->y, self->x, self->y);
|
||||
|
||||
if (distance > 0 && distance <= 64)
|
||||
{
|
||||
self->towing = e;
|
||||
e->owner = self;
|
||||
addHudMessage(colors.white, "Tow rope attached");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doRope(Entity *owner)
|
||||
{
|
||||
float dx, dy, angle, force;
|
||||
|
@ -55,3 +81,12 @@ void drawRope(Entity *owner)
|
|||
SDL_RenderDrawLine(app.renderer, owner->x - battle.camera.x, owner->y - battle.camera.y, owner->towing->x - battle.camera.x, owner->towing->y - battle.camera.y);
|
||||
}
|
||||
}
|
||||
|
||||
void cutRope(Entity *e)
|
||||
{
|
||||
if (e->owner && e->owner->towing == e)
|
||||
{
|
||||
e->owner->towing = NULL;
|
||||
e->owner = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
extern float getAngle(int x1, int y1, int x2, int y2);
|
||||
extern int getDistance(int x1, int y1, int x2, int y2);
|
||||
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
|
||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
extern Colors colors;
|
||||
extern Entity *self;
|
||||
|
|
|
@ -111,6 +111,7 @@ struct Entity {
|
|||
SDL_Point targetLocation;
|
||||
Entity *towing;
|
||||
Entity *target;
|
||||
Entity *owner;
|
||||
void (*action)(void);
|
||||
void (*defaultAction)(void);
|
||||
void (*die)(void);
|
||||
|
|
Loading…
Reference in New Issue