From acf6c1044be2667ee799327e350f0d890bd55fb8 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 9 Aug 2015 20:19:31 +0200 Subject: [PATCH] Fix grenades going backwards when the player is moving. Most weapon bullets have a speed which is much higher than the player can move, but grenades are relatively slow. Since Bob started moving faster many versions ago, grenades were actually slower than Bob himself. Since there was no concept of bullets inheriting the speed of the entity shooting them, that meant that when Bob was moving forward and tried to throw a grenade, the grenade would actually move backwards relative to Bob. We fix that now by making grenades inherit the velocity of the entity throwing them. Unfortunately, a player that is on a moving platform is considered not to have any velocity, even if the platform is moving. In stead of rewriting everything to track the actual velocity of entities on platforms, we just check if the grenade throwing entity is on a platform, and if so add the platform's velocity to the grenade. With the old starting velocity of grenades plus Bob's own speed, grenades could actually be thrown very fast. Compensate that by making the starting velocity of grenades much lower. It might make some puzzles involving grenades a bit harder. --- data/weapons | 2 +- src/bullets.cpp | 10 ++++++++++ src/bullets.h | 1 + src/trains.cpp | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/data/weapons b/data/weapons index 829bfec..ccf9a32 100644 --- a/data/weapons +++ b/data/weapons @@ -1,7 +1,7 @@ 0 "Pistol" 0 1 60 10 0 15 FlameBulletRight FlameBulletLeft 3 ENT_WEIGHTLESS 1 "Machine Gun" 1 1 60 10 0 4 FlameBulletRight FlameBulletLeft 6 ENT_WEIGHTLESS 2 "Laser Cannon" 2 1 120 13 0 40 LaserBolt LaserBolt 19 ENT_WEIGHTLESS+ENT_BOUNCES -3 "Grenades" 3 50 240 3 -2 20 Grenade Grenade 31 ENT_BOUNCES+ENT_EXPLODES +3 "Grenades" 3 50 240 1 -2 20 Grenade Grenade 31 ENT_BOUNCES+ENT_EXPLODES 4 "Spread Gun" 4 1 240 15 0 15 PlasmaBolt PlasmaBolt 34 ENT_WEIGHTLESS+ENT_PARTICLETRAIL 5 "Rocket Launcher" 5 75 240 8 8 45 FlameBulletRight FlameBulletLeft 11 ENT_WEIGHTLESS+ENT_FIRETRAIL+ENT_EXPLODES diff --git a/src/bullets.cpp b/src/bullets.cpp index fb84642..b8a416f 100644 --- a/src/bullets.cpp +++ b/src/bullets.cpp @@ -49,6 +49,16 @@ void addBullet(Entity *owner, float dx, float dy) bullet->id = owner->currentWeapon->id; bullet->dx = dx; bullet->dy = owner->currentWeapon->dy + dy; + + // Add motion of the player and any platform he/she is on to grenades + if (owner->currentWeapon->dy) + { + int tdx, tdy; + getTrainMotion(owner, tdx, tdy); + bullet->dx += owner->dx - tdx; + bullet->dy += -tdy; + } + bullet->next = NULL; bullet->health = owner->currentWeapon->health; bullet->damage = owner->currentWeapon->damage; diff --git a/src/bullets.h b/src/bullets.h index 7605734..653c1c9 100644 --- a/src/bullets.h +++ b/src/bullets.h @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "headers.h" extern bool checkTrainContact(Entity *ent, int dir); +extern void getTrainMotion(Entity *ent, int &dx, int &dy); extern bool checkObstacleContact(Entity *ent, int dir); extern void enemyBulletCollisions(Entity *bullet); extern void checkPlayerBulletCollisions(Entity *bullet); diff --git a/src/trains.cpp b/src/trains.cpp index 9853123..d2a43cb 100644 --- a/src/trains.cpp +++ b/src/trains.cpp @@ -104,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 -- 2.39.5