A programming exercise that became a racing game engine written in Processing
Play as a rediculously fast tank in a vast empty universe that only contains you and a track.
The tank always knows which face it rests on (or will rest on when it falls). This is implemented by loading the environment from a wavefront (.obj) file and converting the list of triangles into a doubly connected graph, which is used as a large state machine. The tank starts in the center of the face of the first index, and it's assigned to that face.
The tank knows which triangle to align with (which triangle is below it) with these steps:
- Flatten the world into two dimensions by ignoring the y (up/down) axis.
- Take the area of the triangle below the tank.
- Take the sum of the areas of all three triangles formed by the player's position and any two of the triangle's vertices.
- If the area from (3) is significantly (>1.001x) greater than the the area from (2), the tank is outside the plane.
- If (4) is true, repeat (2) and (3) on all adjacent faces to minimize the difference between the two values. The faces with the lowest difference is closest to being directly beneath the player.
- If the current "below" face is the closest one, but (4) is still true, then the player has fallen from the map.
- Otherwise, now pretend the closest face is "below" the tank, and start over at (2) until (5) is false.
Now the face "below" the tank is guaranteed to be beneath the tank.
Limitations of this method:
- it assumes the tank cannot jump between discontiguous sections of tracks
- it assumes gravity is always down
- it assumes the tank can drive over everything connected to the track
Standard WASD controls are implemented with some bonus controls:
- Q: Let the computer play for you
- 1: Highlight the face you are on
- 2: Show the target that the computer would follow if it were playing
- 0: Hide all debug data shown with 1 and 2
- left mouse click: Jump. Hold for longer jumps
Also, try editing "data/Assets.txt" for more levels and skins