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 selectWeapon(void);
|
||||
static void moveTowardsPlayer(void);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
|
||||
static Entity *tankTrack;
|
||||
static int brakingTimer;
|
||||
|
@ -60,6 +61,7 @@ Entity *initTankCommander(void)
|
|||
b->tick = tick;
|
||||
b->die = die1;
|
||||
b->applyDamage = applyDamage;
|
||||
b->getCollisionBounds = getCollisionBounds;
|
||||
|
||||
brakingTimer = 0;
|
||||
|
||||
|
@ -358,3 +360,11 @@ static void applyDamage(int amount)
|
|||
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 (*superAnimate)(void);
|
||||
static void applyDamage(int amount);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
|
||||
Entity *initTankTrack(Boss *owner)
|
||||
{
|
||||
|
@ -47,6 +48,7 @@ Entity *initTankTrack(Boss *owner)
|
|||
b->touch = touch;
|
||||
b->animate = animate;
|
||||
b->applyDamage = applyDamage;
|
||||
b->getCollisionBounds = getCollisionBounds;
|
||||
|
||||
tankCommander = owner;
|
||||
|
||||
|
@ -104,3 +106,11 @@ static void animate(void)
|
|||
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 int canFire(Entity *target);
|
||||
static void preFire(void);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
|
||||
Entity *initCannon(void)
|
||||
{
|
||||
|
@ -60,6 +61,7 @@ Entity *initCannon(void)
|
|||
u->walk = walk;
|
||||
u->die = die;
|
||||
u->canFire = canFire;
|
||||
u->getCollisionBounds = getCollisionBounds;
|
||||
|
||||
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)
|
||||
{
|
||||
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 animate(void);
|
||||
static void changeEnvironment(void);
|
||||
static SDL_Rect *getCurrentSprite(void);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
static void load(cJSON *root);
|
||||
static void save(cJSON *root);
|
||||
static SDL_Rect *getCurrentSprite(void);
|
||||
|
||||
void initEntity(Entity *e)
|
||||
{
|
||||
|
@ -70,6 +71,7 @@ void initEntity(Entity *e)
|
|||
e->getCurrentSprite = getCurrentSprite;
|
||||
e->die = die;
|
||||
e->changeEnvironment = changeEnvironment;
|
||||
e->getCollisionBounds = getCollisionBounds;
|
||||
|
||||
e->load = load;
|
||||
e->save = save;
|
||||
|
@ -179,6 +181,14 @@ static SDL_Rect *getCurrentSprite(void)
|
|||
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)
|
||||
{
|
||||
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 action(void);
|
||||
static void touch(Entity *other);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
static void load(cJSON *root);
|
||||
static void save(cJSON *root);
|
||||
|
||||
|
@ -49,6 +50,7 @@ Entity *initExit(void)
|
|||
s->tick = tick;
|
||||
s->action = action;
|
||||
s->touch = touch;
|
||||
s->getCollisionBounds = getCollisionBounds;
|
||||
s->load = load;
|
||||
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)
|
||||
{
|
||||
Structure *s;
|
||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
static void init(void);
|
||||
static void tick(void);
|
||||
static void touch(Entity *other);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
static void load(cJSON *root);
|
||||
static void save(cJSON *root);
|
||||
|
||||
|
@ -43,6 +44,7 @@ Entity *initItemPad(void)
|
|||
s->init = init;
|
||||
s->tick = tick;
|
||||
s->touch = touch;
|
||||
s->getCollisionBounds = getCollisionBounds;
|
||||
s->load = load;
|
||||
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)
|
||||
{
|
||||
Structure *s;
|
||||
|
|
|
@ -24,6 +24,7 @@ static void init(void);
|
|||
static void action(void);
|
||||
static void touch(Entity *other);
|
||||
static void activate(int active);
|
||||
static void getCollisionBounds(SDL_Rect *r);
|
||||
static void load(cJSON *root);
|
||||
static void save(cJSON *root);
|
||||
|
||||
|
@ -49,6 +50,7 @@ Entity *initTeleporter(void)
|
|||
s->action = action;
|
||||
s->touch = touch;
|
||||
s->activate = activate;
|
||||
s->getCollisionBounds = getCollisionBounds;
|
||||
s->load = load;
|
||||
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)
|
||||
{
|
||||
Structure *s;
|
||||
|
|
|
@ -44,7 +44,6 @@ extern int isControl(int type);
|
|||
extern void clearControl(int type);
|
||||
extern void doWidgets(void);
|
||||
extern char *timeToDate(long millis);
|
||||
extern void playSound(int snd, int ch);
|
||||
|
||||
extern App app;
|
||||
extern Colors colors;
|
||||
|
|
|
@ -152,6 +152,7 @@ struct Entity {
|
|||
void (*applyDamage)(int amount);
|
||||
void (*changeEnvironment)(void);
|
||||
SDL_Rect *(*getCurrentSprite)(void);
|
||||
void (*getCollisionBounds)(SDL_Rect *r);
|
||||
void (*load)(cJSON *root);
|
||||
void (*save)(cJSON *root);
|
||||
Entity *next;
|
||||
|
|
|
@ -26,7 +26,7 @@ void initAtlasTest(void)
|
|||
|
||||
dev.debug = 1;
|
||||
dev.cheatStatic = 0;
|
||||
dev.cheatBlind = 0;
|
||||
dev.cheatBlind = 1;
|
||||
dev.cheatNoEnemies = 0;
|
||||
dev.cheatKeys = 0;
|
||||
dev.cheatPower = 0;
|
||||
|
@ -46,7 +46,7 @@ void initAtlasTest(void)
|
|||
break;
|
||||
|
||||
case 1:
|
||||
STRNCPY(game.worldId, "greenlands1", MAX_NAME_LENGTH);
|
||||
STRNCPY(game.worldId, "outpost1", MAX_NAME_LENGTH);
|
||||
initWorld();
|
||||
break;
|
||||
|
||||
|
|
|
@ -554,15 +554,14 @@ static int canWalkOnEntity(float x, float y)
|
|||
|
||||
static void moveToOthers(float dx, float dy, PointF *position)
|
||||
{
|
||||
Entity *e;
|
||||
Entity *e, *oldSelf;
|
||||
Entity **candidates;
|
||||
int clearTouched, hit, dirX, dirY, solidLoopHits, i;
|
||||
SDL_Rect srcRect;
|
||||
SDL_Rect srcRect, destRect;
|
||||
|
||||
self->getCollisionBounds(&srcRect);
|
||||
srcRect.x = (int) position->x;
|
||||
srcRect.y = (int) position->y;
|
||||
srcRect.w = self->w;
|
||||
srcRect.h = self->h;
|
||||
|
||||
clearTouched = 0;
|
||||
hit = 0;
|
||||
|
@ -583,7 +582,12 @@ static void moveToOthers(float dx, float dy, PointF *position)
|
|||
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)
|
||||
{
|
||||
|
@ -652,10 +656,7 @@ static void moveToOthers(float dx, float dy, PointF *position)
|
|||
|
||||
clearTouched = 1;
|
||||
|
||||
srcRect.x = self->x;
|
||||
srcRect.y = self->y;
|
||||
srcRect.w = self->w;
|
||||
srcRect.h = self->h;
|
||||
self->getCollisionBounds(&srcRect);
|
||||
}
|
||||
while (hit);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue