Use specific collision bounds for certain objects.
This commit is contained in:
parent
5282345dc6
commit
bf9ab57e2f
|
@ -32,6 +32,7 @@ static void applyDamage(int amount);
|
||||||
static void preFire(void);
|
static void preFire(void);
|
||||||
static void selectWeapon(void);
|
static void selectWeapon(void);
|
||||||
static void moveTowardsPlayer(void);
|
static void moveTowardsPlayer(void);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
|
|
||||||
static Entity *tankTrack;
|
static Entity *tankTrack;
|
||||||
static int brakingTimer;
|
static int brakingTimer;
|
||||||
|
@ -60,6 +61,7 @@ Entity *initTankCommander(void)
|
||||||
b->tick = tick;
|
b->tick = tick;
|
||||||
b->die = die1;
|
b->die = die1;
|
||||||
b->applyDamage = applyDamage;
|
b->applyDamage = applyDamage;
|
||||||
|
b->getCollisionBounds = getCollisionBounds;
|
||||||
|
|
||||||
brakingTimer = 0;
|
brakingTimer = 0;
|
||||||
|
|
||||||
|
@ -358,3 +360,11 @@ static void applyDamage(int amount)
|
||||||
addExplosion(self->x + self->w / 2, self->y + self->h / 2, 50, self);
|
addExplosion(self->x + self->w / 2, self->y + self->h / 2, 50, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->facing == FACING_LEFT ? self->x + 98 : self->x;
|
||||||
|
r->y = self->y;
|
||||||
|
r->w = 140;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ static void touch(Entity *other);
|
||||||
static void animate(void);
|
static void animate(void);
|
||||||
static void (*superAnimate)(void);
|
static void (*superAnimate)(void);
|
||||||
static void applyDamage(int amount);
|
static void applyDamage(int amount);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
|
|
||||||
Entity *initTankTrack(Boss *owner)
|
Entity *initTankTrack(Boss *owner)
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,7 @@ Entity *initTankTrack(Boss *owner)
|
||||||
b->touch = touch;
|
b->touch = touch;
|
||||||
b->animate = animate;
|
b->animate = animate;
|
||||||
b->applyDamage = applyDamage;
|
b->applyDamage = applyDamage;
|
||||||
|
b->getCollisionBounds = getCollisionBounds;
|
||||||
|
|
||||||
tankCommander = owner;
|
tankCommander = owner;
|
||||||
|
|
||||||
|
@ -104,3 +106,11 @@ static void animate(void)
|
||||||
superAnimate();
|
superAnimate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->x + 16;
|
||||||
|
r->y = self->y;
|
||||||
|
r->w = self->w - 32;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ static void die2(void);
|
||||||
static void animate(void);
|
static void animate(void);
|
||||||
static int canFire(Entity *target);
|
static int canFire(Entity *target);
|
||||||
static void preFire(void);
|
static void preFire(void);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
|
|
||||||
Entity *initCannon(void)
|
Entity *initCannon(void)
|
||||||
{
|
{
|
||||||
|
@ -60,6 +61,7 @@ Entity *initCannon(void)
|
||||||
u->walk = walk;
|
u->walk = walk;
|
||||||
u->die = die;
|
u->die = die;
|
||||||
u->canFire = canFire;
|
u->canFire = canFire;
|
||||||
|
u->getCollisionBounds = getCollisionBounds;
|
||||||
|
|
||||||
return (Entity*)u;
|
return (Entity*)u;
|
||||||
}
|
}
|
||||||
|
@ -214,6 +216,14 @@ static void animate(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->x + 36;
|
||||||
|
r->y = self->y;
|
||||||
|
r->w = 36;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
||||||
static int canFire(Entity *target)
|
static int canFire(Entity *target)
|
||||||
{
|
{
|
||||||
return abs(target->y - self->y) <= MAP_TILE_SIZE;
|
return abs(target->y - self->y) <= MAP_TILE_SIZE;
|
||||||
|
|
|
@ -31,9 +31,10 @@ static void activate(int active);
|
||||||
static void touch(Entity *other);
|
static void touch(Entity *other);
|
||||||
static void animate(void);
|
static void animate(void);
|
||||||
static void changeEnvironment(void);
|
static void changeEnvironment(void);
|
||||||
|
static SDL_Rect *getCurrentSprite(void);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
static SDL_Rect *getCurrentSprite(void);
|
|
||||||
|
|
||||||
void initEntity(Entity *e)
|
void initEntity(Entity *e)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +71,7 @@ void initEntity(Entity *e)
|
||||||
e->getCurrentSprite = getCurrentSprite;
|
e->getCurrentSprite = getCurrentSprite;
|
||||||
e->die = die;
|
e->die = die;
|
||||||
e->changeEnvironment = changeEnvironment;
|
e->changeEnvironment = changeEnvironment;
|
||||||
|
e->getCollisionBounds = getCollisionBounds;
|
||||||
|
|
||||||
e->load = load;
|
e->load = load;
|
||||||
e->save = save;
|
e->save = save;
|
||||||
|
@ -179,6 +181,14 @@ static SDL_Rect *getCurrentSprite(void)
|
||||||
return &s->frames[self->spriteFrame]->rect;
|
return &s->frames[self->spriteFrame]->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->x;
|
||||||
|
r->y = self->y;
|
||||||
|
r->w = self->w;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Entity [name=%s, type=%d, x=%d, y=%d] cannot be loaded", self->name, self->type, (int)self->x, (int)self->y);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Entity [name=%s, type=%d, x=%d, y=%d] cannot be loaded", self->name, self->type, (int)self->x, (int)self->y);
|
||||||
|
|
|
@ -24,6 +24,7 @@ static void init(void);
|
||||||
static void tick(void);
|
static void tick(void);
|
||||||
static void action(void);
|
static void action(void);
|
||||||
static void touch(Entity *other);
|
static void touch(Entity *other);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ Entity *initExit(void)
|
||||||
s->tick = tick;
|
s->tick = tick;
|
||||||
s->action = action;
|
s->action = action;
|
||||||
s->touch = touch;
|
s->touch = touch;
|
||||||
|
s->getCollisionBounds = getCollisionBounds;
|
||||||
s->load = load;
|
s->load = load;
|
||||||
s->save = save;
|
s->save = save;
|
||||||
|
|
||||||
|
@ -137,6 +139,14 @@ static void touch(Entity *other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->x + 64;
|
||||||
|
r->y = self->y;
|
||||||
|
r->w = 2;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
Structure *s;
|
Structure *s;
|
||||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
static void init(void);
|
static void init(void);
|
||||||
static void tick(void);
|
static void tick(void);
|
||||||
static void touch(Entity *other);
|
static void touch(Entity *other);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ Entity *initItemPad(void)
|
||||||
s->init = init;
|
s->init = init;
|
||||||
s->tick = tick;
|
s->tick = tick;
|
||||||
s->touch = touch;
|
s->touch = touch;
|
||||||
|
s->getCollisionBounds = getCollisionBounds;
|
||||||
s->load = load;
|
s->load = load;
|
||||||
s->save = save;
|
s->save = save;
|
||||||
|
|
||||||
|
@ -111,6 +113,14 @@ static void touch(Entity *other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->x;
|
||||||
|
r->y = self->y - 4;
|
||||||
|
r->w = self->w;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
Structure *s;
|
Structure *s;
|
||||||
|
|
|
@ -24,6 +24,7 @@ static void init(void);
|
||||||
static void action(void);
|
static void action(void);
|
||||||
static void touch(Entity *other);
|
static void touch(Entity *other);
|
||||||
static void activate(int active);
|
static void activate(int active);
|
||||||
|
static void getCollisionBounds(SDL_Rect *r);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ Entity *initTeleporter(void)
|
||||||
s->action = action;
|
s->action = action;
|
||||||
s->touch = touch;
|
s->touch = touch;
|
||||||
s->activate = activate;
|
s->activate = activate;
|
||||||
|
s->getCollisionBounds = getCollisionBounds;
|
||||||
s->load = load;
|
s->load = load;
|
||||||
s->save = save;
|
s->save = save;
|
||||||
|
|
||||||
|
@ -118,6 +120,14 @@ static void activate(int active)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getCollisionBounds(SDL_Rect *r)
|
||||||
|
{
|
||||||
|
r->x = self->x + 16;
|
||||||
|
r->y = self->y - 4;
|
||||||
|
r->w = 64;
|
||||||
|
r->h = self->h;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
Structure *s;
|
Structure *s;
|
||||||
|
|
|
@ -44,7 +44,6 @@ extern int isControl(int type);
|
||||||
extern void clearControl(int type);
|
extern void clearControl(int type);
|
||||||
extern void doWidgets(void);
|
extern void doWidgets(void);
|
||||||
extern char *timeToDate(long millis);
|
extern char *timeToDate(long millis);
|
||||||
extern void playSound(int snd, int ch);
|
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
|
@ -152,6 +152,7 @@ struct Entity {
|
||||||
void (*applyDamage)(int amount);
|
void (*applyDamage)(int amount);
|
||||||
void (*changeEnvironment)(void);
|
void (*changeEnvironment)(void);
|
||||||
SDL_Rect *(*getCurrentSprite)(void);
|
SDL_Rect *(*getCurrentSprite)(void);
|
||||||
|
void (*getCollisionBounds)(SDL_Rect *r);
|
||||||
void (*load)(cJSON *root);
|
void (*load)(cJSON *root);
|
||||||
void (*save)(cJSON *root);
|
void (*save)(cJSON *root);
|
||||||
Entity *next;
|
Entity *next;
|
||||||
|
|
|
@ -26,7 +26,7 @@ void initAtlasTest(void)
|
||||||
|
|
||||||
dev.debug = 1;
|
dev.debug = 1;
|
||||||
dev.cheatStatic = 0;
|
dev.cheatStatic = 0;
|
||||||
dev.cheatBlind = 0;
|
dev.cheatBlind = 1;
|
||||||
dev.cheatNoEnemies = 0;
|
dev.cheatNoEnemies = 0;
|
||||||
dev.cheatKeys = 0;
|
dev.cheatKeys = 0;
|
||||||
dev.cheatPower = 0;
|
dev.cheatPower = 0;
|
||||||
|
@ -46,7 +46,7 @@ void initAtlasTest(void)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
STRNCPY(game.worldId, "greenlands1", MAX_NAME_LENGTH);
|
STRNCPY(game.worldId, "outpost1", MAX_NAME_LENGTH);
|
||||||
initWorld();
|
initWorld();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -554,15 +554,14 @@ static int canWalkOnEntity(float x, float y)
|
||||||
|
|
||||||
static void moveToOthers(float dx, float dy, PointF *position)
|
static void moveToOthers(float dx, float dy, PointF *position)
|
||||||
{
|
{
|
||||||
Entity *e;
|
Entity *e, *oldSelf;
|
||||||
Entity **candidates;
|
Entity **candidates;
|
||||||
int clearTouched, hit, dirX, dirY, solidLoopHits, i;
|
int clearTouched, hit, dirX, dirY, solidLoopHits, i;
|
||||||
SDL_Rect srcRect;
|
SDL_Rect srcRect, destRect;
|
||||||
|
|
||||||
|
self->getCollisionBounds(&srcRect);
|
||||||
srcRect.x = (int) position->x;
|
srcRect.x = (int) position->x;
|
||||||
srcRect.y = (int) position->y;
|
srcRect.y = (int) position->y;
|
||||||
srcRect.w = self->w;
|
|
||||||
srcRect.h = self->h;
|
|
||||||
|
|
||||||
clearTouched = 0;
|
clearTouched = 0;
|
||||||
hit = 0;
|
hit = 0;
|
||||||
|
@ -583,7 +582,12 @@ static void moveToOthers(float dx, float dy, PointF *position)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collision(srcRect.x, srcRect.y, srcRect.w, srcRect.h, e->x, e->y, e->w, e->h))
|
oldSelf = self;
|
||||||
|
self = e;
|
||||||
|
e->getCollisionBounds(&destRect);
|
||||||
|
self = oldSelf;
|
||||||
|
|
||||||
|
if (collision(srcRect.x, srcRect.y, srcRect.w, srcRect.h, destRect.x, destRect.y, destRect.w, destRect.h))
|
||||||
{
|
{
|
||||||
if (clearTouched)
|
if (clearTouched)
|
||||||
{
|
{
|
||||||
|
@ -652,10 +656,7 @@ static void moveToOthers(float dx, float dy, PointF *position)
|
||||||
|
|
||||||
clearTouched = 1;
|
clearTouched = 1;
|
||||||
|
|
||||||
srcRect.x = self->x;
|
self->getCollisionBounds(&srcRect);
|
||||||
srcRect.y = self->y;
|
|
||||||
srcRect.w = self->w;
|
|
||||||
srcRect.h = self->h;
|
|
||||||
}
|
}
|
||||||
while (hit);
|
while (hit);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue