ikbensiep / lofigame

A 2D game without canvas, only html vibes. SVG is used not only for artwork but to annotate as much world/level data as possible, simply by drawing shapes accoring to a few rules. Exploring wether it's worthwile to make it into an open source 2d world game engine.
https://ikbensiep.github.io/lofigame/
GNU General Public License v3.0
1 stars 0 forks source link

Sh/laptimer #37

Closed ikbensiep closed 5 months ago

ikbensiep commented 5 months ago

Closes #36 with a better, cleaner timing solution.

Also

updates Waypoint behavior slightly + some misc cleanups :soap: :sponge:

Laptimer deetz

Instead of calculating 3 sectors from the #racetrack waypoints, a track.svg file now needs a root level #timing layer, containing 3 <path> elements, in order. These <path>s should be at least 2 car lengths in size (in the driving direction of the track) and in width, cover the entire racetrack at their designated locations, extended to cover the distance to obstacle (guard rail) <path>s along the racetrack, creating a closed part which can not be skipped without triggering the sector timer.

See austin.svg for an example.

Note how the Inkscape Layers/Objects dialog stacks layers in reverse source order (creating a visually correct layering) but
:warning: In actual svg markup this is reversed; the last element will be the highest in the stacking order!

Make sure the sector timing blocks are in the correct source order:

<g id="timing">
  <path id="s1">
  <path id="s2">
  <path id="s3">
</g>

in other words, in Inkscape this layer should look like this:

#timing 
- #s3
- #s2
- #s1

Laptimer.js

now contains one update() function which is called every frame AFTER all paths have been completed (ie, warmup lap is done). It checks:

If so, it'll add a the time in the corresponding sector slot of currentLap. If the last sector was hit, the time is recorded and the entire lap object is pushed into the laps array. The currentLap object is cleaned and the current time is set as its start property.

This goes on infinitely.

:question: In a future update, when the pitlane path is hit (ie, enter pits), end the current lap.

ikbensiep commented 5 months ago

closed by #39