]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/trains.cpp
Added .gitignore to ignore certain files + fixed access rights on Makefile* as
[quix0rs-blobwars.git] / src / trains.cpp
index 4cc865666bc3aff373565af70318185b4210aa4a..03575210703e2c305bc1e4dce2375b662928aa7f 100644 (file)
@@ -1,5 +1,6 @@
 /*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -62,7 +63,7 @@ void openDoor(Train *train)
 
        train->active = true;
 
-       audio.playSound(SND_OPENDOOR, CH_TOUCH);
+       audio.playSound(SND_OPENDOOR, CH_TOUCH, train->x);
 }
 
 /**
@@ -80,20 +81,20 @@ void trainBlockEntity(Entity *ent, const char *message, Train *train, int dir)
                if ((train->isReady()) && (!train->active))
                {
                        engine.setInfoMessage(message, 1, INFO_NORMAL);
-                       audio.playSound(SND_LOCKEDDOOR, CH_TOUCH);
+                       audio.playSound(SND_LOCKEDDOOR, CH_TOUCH, train->x);
                }
        }
        
        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))
                {
@@ -103,6 +104,22 @@ void trainBlockEntity(Entity *ent, const char *message, Train *train, int dir)
        }
 }
 
+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
@@ -121,14 +138,18 @@ bool checkTrainContact(Entity *ent, int dir)
        {
                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)
                {
@@ -184,7 +205,7 @@ bool checkTrainContact(Entity *ent, int dir)
                                                openDoor(train);
                                        }
                                        
-                                       if (dir == 1)
+                                       if (dir & DIR_Y)
                                        {
                                                ent->dy = 0;
                                                ent->falling = false;
@@ -340,7 +361,6 @@ void doTrains()
                {
                        oldX = (int)train->x;
                        oldY = (int)train->y;
-                       playSound = false;
                        
                        playSound = train->openClose();
                        
@@ -354,7 +374,7 @@ void doTrains()
                                }
                                else if (playSound)
                                {
-                                       audio.playSound(SND_DOOROPENED, CH_TOUCH);
+                                       audio.playSound(SND_DOOROPENED, CH_TOUCH, train->x);
                                }
                        }
                }
@@ -364,7 +384,7 @@ void doTrains()
                        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);
                }