Use entities from grid for separation.
This commit is contained in:
parent
f10ec392ef
commit
e620ceccad
|
@ -258,21 +258,24 @@ static void separate(void)
|
||||||
int distance;
|
int distance;
|
||||||
float dx, dy, force;
|
float dx, dy, force;
|
||||||
int count;
|
int count;
|
||||||
Entity *f;
|
Entity *e, **candidates;
|
||||||
|
int i;
|
||||||
|
|
||||||
dx = dy = 0;
|
dx = dy = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
force = 0;
|
force = 0;
|
||||||
|
|
||||||
for (f = battle.entityHead.next ; f != NULL ; f = f->next)
|
candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self);
|
||||||
|
i = 0;
|
||||||
|
e = candidates[i];
|
||||||
|
|
||||||
|
while (e)
|
||||||
{
|
{
|
||||||
if (f != self && f->active)
|
distance = getDistance(e->x, e->y, self->x, self->y);
|
||||||
{
|
|
||||||
distance = getDistance(f->x, f->y, self->x, self->y);
|
|
||||||
|
|
||||||
if (distance > 0 && distance < self->separationRadius)
|
if (distance > 0 && distance < self->separationRadius)
|
||||||
{
|
{
|
||||||
angle = getAngle(self->x, self->y, f->x, f->y);
|
angle = getAngle(self->x, self->y, e->x, e->y);
|
||||||
|
|
||||||
dx += sin(TO_RAIDANS(angle));
|
dx += sin(TO_RAIDANS(angle));
|
||||||
dy += -cos(TO_RAIDANS(angle));
|
dy += -cos(TO_RAIDANS(angle));
|
||||||
|
@ -280,7 +283,10 @@ static void separate(void)
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
|
|
|
@ -38,6 +38,7 @@ extern void updateCondition(char *name, int type);
|
||||||
extern Entity *getFighterDef(char *name);
|
extern Entity *getFighterDef(char *name);
|
||||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||||
extern void checkTrigger(char *name, int type);
|
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 Entity *spawnEntity(void);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
|
|
Loading…
Reference in New Issue