This game writing business has taken a little more time that I had hoped! I lost time last weekend, after I decided to adjust my approach to the ray tracing.
Originally, I did a ray tracing search at the resolution of the board squares. This returned a list of square centre positions, so I could draw the ray. This is what I showed in previous screenshots.
This suffered subtle problems when the ray went off-screen, because the search terminated before the path stepped off-screen, so the user could not see where the ray ended up, it would just end at the final mirror!
Also, to make the screen repaint handling easier, I decided I wanted to XOR plot the ray. This meant writing a line-drawing routine. I initially started a Bresenham algorithm, but abandoned this when I realised that rolling the search and line-drawing into one would be a great idea.
Here’s what it looks like now:
The ray tracing search MkII is now high-resolution, and steps in units of 2 pixels, in the direction of travel. At each step we XOR plot the point on screen. When we intersect the centre-piece of a mirror, we re-direct the ray. Similarly, intersecting the centre of other objects allows their specific actions to take place. The ray tracing terminated when:
- The ray length exceeds the maximum allowed (overextension).
- The ray is directed off-screen.
- The ray hits a wall
- The ray hits a POD or an MINE.
This is currently wrapped in a Lynx BASIC program that calls two assembly language modules, and I have a playable demo!
Not everything is done yet – there are other objects I have yet to implement.
This then needs wrapping with a title screen, scoring, energy loss, and so forth.
… And I need some levels defining!