if ((ent->flags & ENT_BULLET) && (!(ent->flags & ENT_BOUNCES)))
{
- if (dir == 0)
+ if (dir & DIR_X)
{
if (ent->dx < 0) ent->x = train->x + train->sprite->image[0]->w;
if (ent->dx > 0) ent->x = train->x - ent->width;
}
}
- if (dir == 1)
+ if (dir & DIR_Y)
{
if ((ent->dy >= 0) && (train->type >= TR_SLIDEDOOR))
{
}
}
+void getTrainMotion(Entity *ent, int &dx, int &dy)
+{
+ dx = 0;
+ dy = 0;
+ Train *train = (Train*)map.trainList.getHead();
+ while (train->next != NULL) {
+ train = (Train*)train->next;
+ bool collision = (Collision::collision(ent->x, ent->y + ent->dy, ent->width, ent->height - 1, train->x, train->y, train->width, train->height));
+ if(collision) {
+ dx = train->getDX();
+ dy = train->getDY();
+ break;
+ }
+ }
+}
+
/**
* Checks to see if an entity has touched this train. Depending on
* the trains status certain other functions will be invoked
{
train = (Train*)train->next;
- if (dir == 0)
+ if (dir == DIR_X)
{
collision = (Collision::collision(ent->x + ent->dx, ent->y, ent->width, ent->height - 1, train->x, train->y, train->width, train->height));
}
- else
+ else if (dir == DIR_Y)
{
collision = (Collision::collision(ent->x, ent->y + ent->dy, ent->width, ent->height - 1, train->x, train->y, train->width, train->height));
}
+ else
+ {
+ collision = (Collision::collision(ent->x + ent->dx, ent->y + ent->dy, ent->width, ent->height - 1, train->x, train->y, train->width, train->height));
+ }
if (collision)
{
openDoor(train);
}
- if (dir == 1)
+ if (dir & DIR_Y)
{
ent->dy = 0;
ent->falling = false;
{
oldX = (int)train->x;
oldY = (int)train->y;
- playSound = false;
playSound = train->openClose();
setTrainSprite(train);
}
- if ((abs(x) <= 800) && (abs(y) <= 600))
+ if (train->sprite && (abs(x) <= 800) && (abs(y) <= 600))
{
graphics.blit(train->sprite->getCurrentFrame(), x, y, graphics.screen, false);
}