Skip to content
Martin B edited this page Feb 6, 2025 · 7 revisions

The Air Attack game is a port from Scratch Air Attack. The game re-uses a lot of code from PacMan-ishU, which has a Wiki. I did however learn something while doing this game.

The coreinit/time.h can be used to access the internal time. OSTicksToMicroseconds(OSGetTick()) can be used to get the time in microseconds. Using these APIs I was able to measure the time my processing was taking, to adjust the time delay passed in to OSSleepTicks(OSMillisecondsToTicks(del)).

I set the delay to be 68ms (4 times the period of the 60Hz TV update). I reduced the delay by the screen draw processing time; which gave smooth operation, despite the varying time to process the display. There are likely better ways to schedule the software, but this is simple and works in this case.

The game uses the OSScreen interfaces, which are limited. To do anything more ambitious will need gx2. The approach of adding images as header files is also limited. I had to load the source code to GitHub a few files at a time due to the file size.

I have extended Draw.c and .h to add a scrolling background function (drawBackground). I have also added a scaleImage function, which allows images to be drawn between 0% and 100% of full-size.

The draw functions have been updated so that the image sizes are pass parameters. This has the advantage that different size images can be processed. WARNING, however this approach means it is possible to write code to go off the end of the image data.

Clone this wiki locally