The spaceship is not a sprite, it’s a 3D model using realtime perspective rendering and shading, lovingly drawn pixel by pixel every frame
If you’re curious, check out the ShipModel class in main.ts
which has the 3D coordinates of the corners and the faces connecting them. The actual drawing happens in the renderer code in triangle.ts
. In short:
- sort the drawn objects (spaceships and asteroids) and handle them in far-to-near order
- for the spaceship model, determine the correct order in which to draw its parts. It’s a BSP tree where planes split it into convex sub-models.
- for each part, use a transform matrix for orientation/position and a perspective transform to get screen coordinates for each corner (vertex)
- use clipping to cut away any parts of faces that extend beyond the screen edges
- convert the face polygons to trapezoids with vertical edges
- add the trapezoids to a list sorted by X (horizontal) starting position
- once all parts have been added, go through the trapezoid list and draw vertical lines for each X position of each trapezoid, in back-to-front order