]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Fix throwing grenades from moving platforms.
authorGuus Sliepen <guus@debian.org>
Sun, 9 Aug 2015 16:28:26 +0000 (18:28 +0200)
committerGuus Sliepen <guus@debian.org>
Sun, 9 Aug 2015 16:28:26 +0000 (18:28 +0200)
The train and obstacle collision code made a distinction between
horizontally moving entities (which covers bullets and lasers), and
vertically moving entities (falling items?), but didn't handle
diagonally moving entities correctly, like grenades.

src/bullets.cpp
src/defs.h
src/entities.cpp
src/obstacles.cpp
src/trains.cpp

index 88e288c8c91675d93e0fb842724c8cb70d7e2f6d..fb846423619f294222b60db9f06f273947c22413 100644 (file)
@@ -264,7 +264,7 @@ bool bulletHasCollided(Entity *bullet, float dx, float dy)
        
        checkSwitchContact(bullet);
 
-       if ((checkTrainContact(bullet, 0)) || (checkObstacleContact(bullet, 0)))
+       if ((checkTrainContact(bullet, DIR_XY)) || (checkObstacleContact(bullet, DIR_XY)))
        {
                if (bullet->flags & ENT_BOUNCES)
                        bounceBullet(bullet, dx, dy);
index d358d3effa040a052c76eab08ab98d130fc2a81d..5c598324904cfb642a846a2f6e8e3723af2ea24e 100644 (file)
@@ -378,6 +378,12 @@ enum {
        PAK_TAGS
 };
 
+/* ######### miscellaneous ############## */
+
+#define DIR_X 1
+#define DIR_Y 2
+#define DIR_XY 3
+
 /* ############# debug ################## */
 
 #if DEBUG
index 25ae95409fb1951cb9f70a1597106eac7e5d626f..4a48160802cec4ca21b79452753907a4798a1040 100644 (file)
@@ -321,7 +321,7 @@ void moveEntity(Entity *ent)
 
        if (ent->dx != 0)
        {               
-               if ((checkBrickContactX(ent)) || (checkObstacleContact(ent, 0)) || (checkTrainContact(ent, 0)))
+               if ((checkBrickContactX(ent)) || (checkObstacleContact(ent, DIR_X)) || (checkTrainContact(ent, DIR_X)))
                {
                        ent->dx = 0;
                }
@@ -336,7 +336,7 @@ void moveEntity(Entity *ent)
 
        if (ent->dy != 0)
        {
-               if ((checkBrickContactY(ent)) || (checkObstacleContact(ent, 1)) || (checkTrainContact(ent, 1)))
+               if ((checkBrickContactY(ent)) || (checkObstacleContact(ent, DIR_Y)) || (checkTrainContact(ent, DIR_Y)))
                {
                        if ((ent->flags & ENT_BOUNCES) && (ent->dy >= 3))
                        {
index dc1ddfe0993501c750d9f4d677ad7031aa959cda..a919e52a5473b31c98e571769f77630fd2763215 100644 (file)
@@ -57,18 +57,22 @@ bool checkObstacleContact(Entity *ent, int dir)
                        continue;
                }
                        
-               if (dir == 0)
+               if (dir == DIR_X)
                {
                        collision = Collision::collision(ent->x + ent->dx, ent->y, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
                }
-               else
+               else if (dir == DIR_Y)
                {
                        collision = Collision::collision(ent->x, ent->y + ent->dy, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
                }
+               else
+               {
+                       collision = Collision::collision(ent->x + ent->dx, ent->y + ent->dy, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
+               }
 
                if (collision)
                {
-                       if (dir == 0)
+                       if (dir & DIR_X)
                        {
                                if ((ent->y + ent->height == obstacle->y + obstacle->height) || ((ent->flags & ENT_BULLET) && (ent->owner == &player)))
                                {
@@ -79,7 +83,7 @@ bool checkObstacleContact(Entity *ent, int dir)
                                }
                        }
 
-                       if (dir == 1)
+                       if (dir & DIR_Y)
                        {
                                ent->falling = false;
                                ent->dy = 0;
index 2c7585f21157293c278188a7e5b79214ef8f2857..9853123fd9ca1c418dc8aa5faa06ec5e79ab4bf8 100644 (file)
@@ -87,14 +87,14 @@ void trainBlockEntity(Entity *ent, const char *message, Train *train, int dir)
        
        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))
                {
@@ -122,14 +122,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)
                {
@@ -185,7 +189,7 @@ bool checkTrainContact(Entity *ent, int dir)
                                                openDoor(train);
                                        }
                                        
-                                       if (dir == 1)
+                                       if (dir & DIR_Y)
                                        {
                                                ent->dy = 0;
                                                ent->falling = false;