MakeCode Kart

Here’s a new version. It has trees, drifting, a lap timer, and other major changes.

(For historical interest, there’s also the earlier version 1.8.3 which I had tried to post on Friday but it hadn’t made it to the forum. That one had similar features but was slower due to using floating point math.)

Gameplay and user-visible changes:

  • Some basic car physics with inertia and drifting. It’s not at all realistic, but I think it’s kind of fun. Press A to boost, and B to drift. There’s a drift practice track in the northeast corner of the map.
  • Terrain slowdown/collisions
  • A lap timer triggered by crossing the finish line. (Yes, it’s possible to cheat. It would need check points to avoid that.) The score display is based on the lap time.
  • Improved performance on hardware compared to version 1.8.3 - I’m getting about 14fps on the PyGamer with trees enabled.

Internals changes:

  • Blocks support! The new Renderer category has “place image”. There’s two versions that both do the same thing, the “placed image is visible” one is useful if you need to change logic depending on if the image is in view or not. See version 1.8.3 for a demo of that.
  • The object drawing is now based on blitting images directly instead of scaling sprites, this should be a lot more efficient. It does its own visibility checks and Z sorting. I think you shouldn’t need the 100-pixel range limit anymore. (If it’s still an issue, use renderer.setZClipFar(distance) to adjust the render distance.) By default the images are attached at the bottom center, you can change that with the optional anchor parameter. The code is a bit less readable due to using fixed-point math, but that’s a lot more efficient.
  • Updated the background renderer to scale the image to match the field of view - this isn’t pretty but helps avoid motion sickness. You can use renderer.setBackgroundSolidColor(col) instead of renderer.setBackgroundImage if you prefer. I had added lots of comments about this, but the Blocks conversion deleted them. Sigh.
  • The renderer and maths code now live in separate files to de-clutter the Blocks view. To import this, use JavaScript mode, open Explorer at the left, and copy the renderer.ts and fx14.ts files to your own project. (This would be nicer as an extension, but I haven’t had time to package it yet.) I hope this will make it easier to import future changes.
  • Some fixes to the projection code to better attach objects to the ground. This slightly changes the visible view, you may need to tweak zNear and zFar to compensate.
  • The coordinate system is now based on texture pixel centers, not edges. This way, you don’t need to add 0.5 to center objects on pixels.

There’s also a few possible regressions where things work differently:

  • The player car is now always drawn in front of the 3d images. If that’s an issue, let me know - it’s fixable but I’m not sure if people care.
  • I removed the pixel-accurate attachX/attachY, let me know if you need this back. The new anchor (default is bottom center attachment) seemed simpler.
6 Likes