diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/vehicles/railloco.cpp | 30 | ||||
-rw-r--r-- | game/vehicles/railloco.h | 14 | ||||
-rw-r--r-- | game/vehicles/vehicle.cpp | 6 | ||||
-rw-r--r-- | game/vehicles/vehicle.h | 19 |
4 files changed, 69 insertions, 0 deletions
diff --git a/game/vehicles/railloco.cpp b/game/vehicles/railloco.cpp new file mode 100644 index 0000000..baa9b81 --- /dev/null +++ b/game/vehicles/railloco.cpp @@ -0,0 +1,30 @@ +#include "railloco.h" +#include "game/vehicles/vehicle.h" +#include "gfx/gl/transform.h" +#include <glm/glm.hpp> +#include <maths.h> + +void +RailLoco::tick(TickDuration dur) +{ + linkDist += dur.count() * speed; + while (linkDist > link->length) { + location = link->positionAt(link->length, linkDir); + const auto & nexts {link->nexts[1 - linkDir]}; + const auto next = std::find_if(nexts.begin(), nexts.end(), [ang = location.GetRot().y](const Link::Next & n) { + return std::abs(normalize(n.first->ends[n.second].second - ang)) < 0.1F; + }); + if (next != nexts.end()) { + linkDist -= link->length; + link = next->first; + linkDir = next->second; + } + else { + linkDist = link->length; + speed = 0; + } + } + location = link->positionAt(linkDist, linkDir); +} + +Brush47::Brush47(LinkPtr l) : RailLoco(l, "brush47.obj", "brush47.png") { } diff --git a/game/vehicles/railloco.h b/game/vehicles/railloco.h new file mode 100644 index 0000000..05e3e48 --- /dev/null +++ b/game/vehicles/railloco.h @@ -0,0 +1,14 @@ +#include "game/worldobject.h" +#include "vehicle.h" +#include <string> + +class RailLoco : public Vehicle { +public: + using Vehicle::Vehicle; + void tick(TickDuration elapsed) override; +}; + +class Brush47 : public RailLoco { +public: + Brush47(LinkPtr p); +}; diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp new file mode 100644 index 0000000..4c4ac71 --- /dev/null +++ b/game/vehicles/vehicle.cpp @@ -0,0 +1,6 @@ +#include "vehicle.h" + +Vehicle::Vehicle(LinkPtr l, const std::string & obj, const std::string & tex) : + Physical(l->ends.front().first->pos, obj, tex), link(l) +{ +} diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h new file mode 100644 index 0000000..01be6a6 --- /dev/null +++ b/game/vehicles/vehicle.h @@ -0,0 +1,19 @@ +#ifndef VEHICLE_H +#define VEHICLE_H + +#include "game/physical.h" +#include <game/network/link.h> +#include <game/worldobject.h> +#include <glm/glm.hpp> +#include <string> + +class Vehicle : public WorldObject, public Physical { +public: + Vehicle(LinkPtr link, const std::string & obj, const std::string & tex); + LinkPtr link; // Which link are we travelling along + unsigned char linkDir {0}; // Starting end e0->e1 or e1->e0 + float linkDist {0}; // distance long current link + float speed {50}; // speed in m/s (~75 km/h) +}; + +#endif |