Collision bug fixes.
This commit is contained in:
parent
0a131e25c0
commit
c77cea92a6
|
@ -61,7 +61,7 @@ static int isBlockedByMap(Entity *src, Entity *dest)
|
|||
mapBlock.w = MAP_TILE_SIZE;
|
||||
mapBlock.h = MAP_TILE_SIZE;
|
||||
|
||||
if (lineIntersectsRect(mapBlock, src->x, src->y, dest->x, dest->y))
|
||||
if (lineRectIntersection(src->x, src->y, dest->x, dest->y, &mapBlock))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ static int isBlockedByMap(Entity *src, Entity *dest)
|
|||
static int isBlockedByEntities(Entity *src, Entity *dest)
|
||||
{
|
||||
Entity **candidates, *e;
|
||||
SDL_Rect losBounds;
|
||||
SDL_Rect losBounds, eBounds;
|
||||
int i;
|
||||
|
||||
losBounds.x = (int) MIN(src->x, dest->x);
|
||||
|
@ -92,7 +92,12 @@ static int isBlockedByEntities(Entity *src, Entity *dest)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (lineIntersectsRect(e->bounds, src->x, src->y, dest->x, dest->y))
|
||||
eBounds.x = e->x;
|
||||
eBounds.y = e->y;
|
||||
eBounds.w = e->w;
|
||||
eBounds.h = e->h;
|
||||
|
||||
if (lineRectIntersection(src->x, src->y, dest->x, dest->y, &eBounds))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -23,5 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
extern int isSolid(int x, int y);
|
||||
extern int lineIntersectsRect(SDL_Rect r, int x1, int y1, int x2, int y2);
|
||||
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
|
||||
extern int lineRectIntersection(int x1, int y1, int x2, int y2, SDL_Rect *r);
|
||||
|
||||
extern World world;
|
||||
|
|
|
@ -29,7 +29,6 @@ static void die1(void);
|
|||
static void die2(void);
|
||||
static void attack(void);
|
||||
static void applyDamage(int amount);
|
||||
static SDL_Rect *getBounds(void);
|
||||
static void preFire(void);
|
||||
static void selectWeapon(void);
|
||||
static void moveTowardsPlayer(void);
|
||||
|
@ -62,7 +61,6 @@ void initTankCommander(Entity *e)
|
|||
b->tick = tick;
|
||||
b->die = die1;
|
||||
b->applyDamage = applyDamage;
|
||||
b->getBounds = getBounds;
|
||||
|
||||
brakingTimer = 0;
|
||||
|
||||
|
@ -348,23 +346,3 @@ static void applyDamage(int amount)
|
|||
addExplosion(self->x + self->w / 2, self->y + self->h / 2, 50, self);
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Rect *getBounds(void)
|
||||
{
|
||||
if (self->facing == FACING_LEFT)
|
||||
{
|
||||
self->bounds.x = self->x + 98;
|
||||
self->bounds.y = self->y;
|
||||
self->bounds.w = 140;
|
||||
self->bounds.h = self->h;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->bounds.x = self->x;
|
||||
self->bounds.y = self->y;
|
||||
self->bounds.w = 140;
|
||||
self->bounds.h = self->h;
|
||||
}
|
||||
|
||||
return &self->bounds;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
static Entity *tankCommander;
|
||||
static void tick(void);
|
||||
static void touch(Entity *other);
|
||||
static SDL_Rect *getBounds(void);
|
||||
static void animate(void);
|
||||
static void (*superAnimate)(void);
|
||||
|
||||
|
@ -43,7 +42,6 @@ void initTankTrack(Entity *e, Entity *tank)
|
|||
|
||||
e->tick = tick;
|
||||
e->touch = touch;
|
||||
e->getBounds = getBounds;
|
||||
e->animate = animate;
|
||||
|
||||
tankCommander = tank;
|
||||
|
@ -88,16 +86,6 @@ static void touch(Entity *other)
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_Rect *getBounds(void)
|
||||
{
|
||||
self->bounds.x = self->x + 16;
|
||||
self->bounds.y = self->y;
|
||||
self->bounds.w = self->w - 32;
|
||||
self->bounds.h = self->h;
|
||||
|
||||
return &self->bounds;
|
||||
}
|
||||
|
||||
static void animate(void)
|
||||
{
|
||||
if (tankCommander->dx != 0)
|
||||
|
|
|
@ -24,7 +24,6 @@ static void applyDamage(int damage);
|
|||
static void walk(void);
|
||||
static void die(void);
|
||||
static void animate(void);
|
||||
static SDL_Rect *getBounds(void);
|
||||
static int canFire(Entity *target);
|
||||
static void preFire(void);
|
||||
|
||||
|
@ -56,7 +55,6 @@ void initCannon(void)
|
|||
u->applyDamage = applyDamage;
|
||||
u->walk = walk;
|
||||
u->die = die;
|
||||
u->getBounds= getBounds;
|
||||
u->canFire = canFire;
|
||||
}
|
||||
|
||||
|
@ -189,16 +187,6 @@ static void animate(void)
|
|||
|
||||
}
|
||||
|
||||
static SDL_Rect *getBounds(void)
|
||||
{
|
||||
self->bounds.x = self->x + 36;
|
||||
self->bounds.y = self->y;
|
||||
self->bounds.w = 36;
|
||||
self->bounds.h = self->h;
|
||||
|
||||
return &self->bounds;
|
||||
}
|
||||
|
||||
static int canFire(Entity *target)
|
||||
{
|
||||
return abs(target->y - self->y) <= MAP_TILE_SIZE;
|
||||
|
|
|
@ -25,7 +25,6 @@ static void reset(void);
|
|||
static void action(void);
|
||||
static void applyDamage(int damage);
|
||||
static float bounce(float x);
|
||||
static SDL_Rect *getBounds(void);
|
||||
static void tick(void);
|
||||
static void touch(Entity *other);
|
||||
static void animate(void);
|
||||
|
@ -64,7 +63,6 @@ void initEntity(Entity *e)
|
|||
e->touch = touch;
|
||||
e->applyDamage = applyDamage;
|
||||
e->bounce = bounce;
|
||||
e->getBounds = getBounds;
|
||||
e->getCurrentSprite = getCurrentSprite;
|
||||
|
||||
e->load = load;
|
||||
|
@ -88,44 +86,30 @@ static void action(void)
|
|||
{
|
||||
}
|
||||
|
||||
static SDL_Rect *getBounds(void)
|
||||
{
|
||||
self->bounds.x = self->x;
|
||||
self->bounds.y = self->y;
|
||||
self->bounds.w = self->w;
|
||||
self->bounds.h = self->h;
|
||||
|
||||
return &self->bounds;
|
||||
}
|
||||
|
||||
static void animate(void)
|
||||
{
|
||||
Sprite *s;
|
||||
SDL_Rect *r;
|
||||
|
||||
s = self->sprite[self->facing];
|
||||
|
||||
if (self->spriteTime != -1)
|
||||
{
|
||||
self->spriteTime--;
|
||||
|
||||
if (self->spriteTime <= 0)
|
||||
if (--self->spriteTime <= 0)
|
||||
{
|
||||
s = self->sprite[self->facing];
|
||||
|
||||
self->spriteFrame++;
|
||||
|
||||
if (self->spriteFrame >= s->numFrames)
|
||||
if (++self->spriteFrame >= s->numFrames)
|
||||
{
|
||||
self->spriteFrame = 0;
|
||||
}
|
||||
|
||||
self->spriteTime = self->sprite[self->facing]->times[self->spriteFrame];
|
||||
self->w = s->w;
|
||||
self->h = s->h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setEntitySize(Entity *e)
|
||||
{
|
||||
r = &self->sprite[self->facing]->frames[self->spriteFrame]->rect;
|
||||
|
||||
self->w = r->w;
|
||||
self->h = r->h;
|
||||
}
|
||||
|
||||
static float bounce(float x)
|
||||
|
|
|
@ -46,8 +46,6 @@ void initWeaponPickup(Entity *e)
|
|||
i->spriteFrame = i->weaponType;
|
||||
i->spriteTime = -1;
|
||||
|
||||
setEntitySize(e);
|
||||
|
||||
if (i->provided)
|
||||
{
|
||||
i->health = 9999;
|
||||
|
|
|
@ -25,7 +25,6 @@ extern void setGameplayMessage(int type, char *format, ...);
|
|||
extern void initConsumable(Entity *e);
|
||||
extern Sprite *getSprite(char *name);
|
||||
extern void pickupItem(void);
|
||||
extern void setEntitySize(Entity *e);
|
||||
extern int touchedPlayer(Entity *e);
|
||||
|
||||
extern Entity *self;
|
||||
|
|
|
@ -52,12 +52,6 @@ Entity *initDoor(void)
|
|||
|
||||
s->sprite[0] = s->sprite[1] = s->sprite[2] = getSprite("Door");
|
||||
|
||||
if (s->closedX == -1 && s->closedY == -1)
|
||||
{
|
||||
s->closedX = (int) s->x;
|
||||
s->closedY = (int) s->y;
|
||||
}
|
||||
|
||||
s->init = init;
|
||||
s->tick = tick;
|
||||
s->touch = touch;
|
||||
|
@ -286,7 +280,7 @@ static void load(cJSON *root)
|
|||
s->tx = cJSON_GetObjectItem(root, "tx")->valueint;
|
||||
s->ty = cJSON_GetObjectItem(root, "ty")->valueint;
|
||||
s->speed = cJSON_GetObjectItem(root, "speed")->valueint;
|
||||
s->state = cJSON_GetObjectItem(root, "state")->valueint;
|
||||
s->state = lookup(cJSON_GetObjectItem(root, "state")->valuestring);
|
||||
}
|
||||
|
||||
static void save(cJSON *root)
|
||||
|
@ -300,7 +294,7 @@ static void save(cJSON *root)
|
|||
cJSON_AddNumberToObject(root, "tx", s->tx);
|
||||
cJSON_AddNumberToObject(root, "ty", s->ty);
|
||||
cJSON_AddNumberToObject(root, "speed", s->speed);
|
||||
cJSON_AddNumberToObject(root, "state", s->state);
|
||||
cJSON_AddStringToObject(root, "state", getLookupName("DOOR_", s->state));
|
||||
cJSON_AddStringToObject(root, "requiredKey", s->requiredItem);
|
||||
|
||||
if (strcmp(s->sprite[0]->name, "Door") != 0)
|
||||
|
|
|
@ -28,6 +28,8 @@ extern void setGameplayMessage(int type, char *format, ...);
|
|||
extern int hasItem(char *name);
|
||||
extern void removeItem(char *name);
|
||||
extern Structure *createStructure(void);
|
||||
extern char *getLookupName(const char *prefix, long num);
|
||||
extern long lookup(const char *name);
|
||||
|
||||
extern Entity *self;
|
||||
extern Dev dev;
|
||||
|
|
|
@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
static void tick(void);
|
||||
static void action(void);
|
||||
static void touch(Entity *other);
|
||||
static SDL_Rect *getBounds(void);
|
||||
|
||||
Entity *initExit(void)
|
||||
{
|
||||
|
@ -55,7 +54,6 @@ Entity *initExit(void)
|
|||
s->tick = tick;
|
||||
s->action = action;
|
||||
s->touch = touch;
|
||||
s->getBounds = getBounds;
|
||||
|
||||
return (Entity*)s;
|
||||
}
|
||||
|
@ -127,13 +125,3 @@ static void touch(Entity *other)
|
|||
s->bobTouching = 2;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Rect *getBounds(void)
|
||||
{
|
||||
self->bounds.x = self->x + 64;
|
||||
self->bounds.y = self->y;
|
||||
self->bounds.w = 2;
|
||||
self->bounds.h = self->h;
|
||||
|
||||
return &self->bounds;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ static void load(cJSON *root)
|
|||
s->tx = cJSON_GetObjectItem(root, "tx")->valueint;
|
||||
s->ty = cJSON_GetObjectItem(root, "ty")->valueint;
|
||||
s->speed = cJSON_GetObjectItem(root, "speed")->valueint;
|
||||
s->state = cJSON_GetObjectItem(root, "state")->valueint;
|
||||
s->state = lookup(cJSON_GetObjectItem(root, "state")->valuestring);
|
||||
s->startX = cJSON_GetObjectItem(root, "startX")->valueint;
|
||||
s->startY = cJSON_GetObjectItem(root, "startY")->valueint;
|
||||
s->waitTime = cJSON_GetObjectItem(root, "waitTime")->valueint;
|
||||
|
@ -157,7 +157,7 @@ static void save(cJSON *root)
|
|||
cJSON_AddNumberToObject(root, "tx", s->tx);
|
||||
cJSON_AddNumberToObject(root, "ty", s->ty);
|
||||
cJSON_AddNumberToObject(root, "speed", s->speed);
|
||||
cJSON_AddNumberToObject(root, "state", s->state);
|
||||
cJSON_AddStringToObject(root, "state", getLookupName("LIFT_", s->state));
|
||||
cJSON_AddNumberToObject(root, "startX", s->startX);
|
||||
cJSON_AddNumberToObject(root, "startY", s->startY);
|
||||
cJSON_AddNumberToObject(root, "waitTime", s->waitTime);
|
||||
|
|
|
@ -27,5 +27,7 @@ extern void observeActivation(Entity *e);
|
|||
extern int isOnScreen(Entity *e);
|
||||
extern void setGameplayMessage(int type, char *format, ...);
|
||||
extern Structure *createStructure(void);
|
||||
extern char *getLookupName(const char *prefix, long num);
|
||||
extern long lookup(const char *name);
|
||||
|
||||
extern Entity *self;
|
||||
|
|
|
@ -133,7 +133,6 @@ struct Entity {
|
|||
int isOnScreen;
|
||||
int isMissionTarget;
|
||||
int observationTime;
|
||||
SDL_Rect bounds;
|
||||
Entity *riding;
|
||||
Entity *owner;
|
||||
unsigned long flags;
|
||||
|
@ -145,7 +144,6 @@ struct Entity {
|
|||
void (*die)(void);
|
||||
void (*animate)(void);
|
||||
void (*walk)(void);
|
||||
void (*setSize)(void);
|
||||
float (*bounce)(float x);
|
||||
void (*teleport)(float tx, float ty);
|
||||
void (*activate)(int active);
|
||||
|
@ -154,7 +152,6 @@ struct Entity {
|
|||
SDL_Rect *(*getCurrentSprite)(void);
|
||||
void (*load)(cJSON *root);
|
||||
void (*save)(cJSON *root);
|
||||
SDL_Rect *(*getBounds)(void);
|
||||
Entity *next;
|
||||
};
|
||||
|
||||
|
|
|
@ -32,6 +32,12 @@ void initLookups(void)
|
|||
|
||||
addLookup("FACING_LEFT", FACING_LEFT);
|
||||
addLookup("FACING_RIGHT", FACING_RIGHT);
|
||||
|
||||
addLookup("LIFT_GOTO_FINISH", LIFT_GOTO_FINISH);
|
||||
addLookup("LIFT_GOTO_START", LIFT_GOTO_START);
|
||||
|
||||
addLookup("DOOR_OPEN", DOOR_OPEN);
|
||||
addLookup("DOOR_CLOSED", DOOR_CLOSED);
|
||||
}
|
||||
|
||||
static void addLookup(const char *name, long value)
|
||||
|
|
|
@ -97,11 +97,6 @@ float wrap(float value, float low, float high)
|
|||
return value;
|
||||
}
|
||||
|
||||
int lineIntersectsRect(SDL_Rect r, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long hashcode(const char *str)
|
||||
{
|
||||
unsigned long hash = 5381;
|
||||
|
|
|
@ -94,11 +94,9 @@ void doEntities(void)
|
|||
self->alive = ALIVE_DEAD;
|
||||
}
|
||||
|
||||
self->setSize();
|
||||
|
||||
self->riding = NULL;
|
||||
|
||||
if (self->w != 0 && self->h != 0 && (!(self->flags & (EF_TELEPORTING | EF_GONE))))
|
||||
if (!(self->flags & (EF_TELEPORTING | EF_GONE)))
|
||||
{
|
||||
addToQuadtree(self, &world.quadtree);
|
||||
}
|
||||
|
@ -141,11 +139,11 @@ void doEntities(void)
|
|||
if (touched[i])
|
||||
{
|
||||
self->touch(touched[i]);
|
||||
}
|
||||
|
||||
if (touched[i]->isStatic)
|
||||
{
|
||||
touched[i]->touch(self); /* for objects that never move */
|
||||
if (touched[i]->isStatic)
|
||||
{
|
||||
touched[i]->touch(self); /* for objects that never move */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +160,7 @@ void doEntities(void)
|
|||
}
|
||||
}
|
||||
|
||||
if ((!(self->flags & EF_FLICKER)) && flicker)
|
||||
if ((self->flags & EF_FLICKER) && flicker)
|
||||
{
|
||||
self->isOnScreen = 0;
|
||||
}
|
||||
|
@ -196,8 +194,6 @@ void drawEntities(int plane)
|
|||
|
||||
for (self = world.entityHead.next ; self != NULL ; self = self->next)
|
||||
{
|
||||
self->isOnScreen = 1;
|
||||
|
||||
draw = self->isOnScreen && !(self->flags & EF_GONE) && self->plane == plane;
|
||||
|
||||
if (draw)
|
||||
|
@ -249,7 +245,7 @@ static void moveEntity(void)
|
|||
if (!(self->flags & EF_WEIGHTLESS))
|
||||
{
|
||||
self->dy += GRAVITY_POWER;
|
||||
self->dy =limit(self->dy, -25, 25);
|
||||
self->dy = limit(self->dy, -25, 25);
|
||||
|
||||
if (self->dy > 0 && self->dy < 1)
|
||||
{
|
||||
|
@ -260,7 +256,7 @@ static void moveEntity(void)
|
|||
|
||||
case ENV_WATER:
|
||||
self->flags &= ~EF_BOUNCES;
|
||||
if ((self->flags & EF_SWIMS) == 0)
|
||||
if (!(self->flags & EF_SWIMS))
|
||||
{
|
||||
self->dy += GRAVITY_POWER;
|
||||
self->dy = limit(self->dy, -2, 2);
|
||||
|
@ -282,7 +278,7 @@ static void moveEntity(void)
|
|||
|
||||
// Deal with x movement
|
||||
position.x = self->x;
|
||||
position.y = self->x;
|
||||
position.y = self->y;
|
||||
position.x += self->dx;
|
||||
moveToOthers(self->dx, 0, &position);
|
||||
moveToMap(self->dx, 0, &position);
|
||||
|
@ -844,12 +840,9 @@ Entity *getRandomObjectiveEntity(void)
|
|||
|
||||
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
if (e->isMissionTarget)
|
||||
if (e->isMissionTarget && rand() % 4 == 0)
|
||||
{
|
||||
if (rand() % 4 == 0)
|
||||
{
|
||||
rtn = e;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -362,7 +362,6 @@ static void spawnEnemies(void)
|
|||
u = (Unit*) createEntity(name);
|
||||
|
||||
u->animate();
|
||||
u->setSize();
|
||||
|
||||
x /= MAP_TILE_SIZE;
|
||||
y /= MAP_TILE_SIZE;
|
||||
|
|
Loading…
Reference in New Issue