Rather than start with a game design, I began to code up a library of vertex-based primitives such as points, circles, and lines, all of which inherit from a base Primitive object. While in most scenarios composition or non-OO principles would be preferable, in this explicit scenario, I want these objects to be interchangeable at a fundamental level, so I can construct the game world effortlessly.
I also decided to utilised bézier curves, as all mobile train-based games I've seen are grid-based, which I felt made them feel rather constrained.

- Wikipedia

- Wikipedia
Béziers are incredibly powerful parametric curves, first popularised in the 1960s by Pierre Bézier when he was designing Renault automobiles. They are easy for humans to define (many CAD applications like Photoshop and 3D Studio Max use them), and they are easy for computers to interpret (game engines use them for plotting camera routes for example).
Bézier curves are essentially a collection of two or more control points, which represent a line. This line can be curved through n-dimensional space with manipulation of control points between the start and end point.
A cubic bézier curve is commonly utilised for game development, as higher order curves become more difficult to compute. Curves of n points can be generalised, but it is generally less expensive to split a higher order curve into multiple cubic or quadratic curves.
Finding a point on the curve for t is the easy bit...
...but points are not uniformly distributed when the curve is stretched towards the middle control points.
To deal with this, I plotted a first pass, drew lines between each point, then walked the curve, dropping new points based on its length. Effectively this replaces the control points with a number of small lines, of equidistant length, but the original curve makes organic track design very straightforward, and easy to tweak.
I chose to represent trains as circles initially (textures will be added later) and then plot them along the lines programatically. Here's an example, with a test train in the bottom right hand corner...


No comments:
Post a Comment