Some things come from nothing

There’s something rather absurd about coding games on obsolete platforms. They’re limited in weird ways – number of colours, sprites, controls, speed, you name it, it comes with limitations.

Life would be much easier with a copy of Unity of whatever, I could bring my ideas to life in moments rather than the weeks it takes to get a small NGPC sketch to the point where it can legitimately be called a game (months, or, lets be frank, years is probably more accurate). Hell, I might even be able to bung it up on one of these new-fangled stores and make a few pennies.

But where would be the fun in that?

You see, one of the things I find most enjoyable about coding on the NGPC are the limitations. It’s as though the machine is sitting there saying “Come on then, I have two limited colour planes for backgrounds, 64 tiny sprites, a joystick with two and a half buttons, a squawky buzzer and a 6.144MHz CPU. Go on then, make that do something amazing. I dare you.”

You know what little machine. Challenge accepted.

So, what’s the ultimate course of action with this approach? You’ve guessed it, why not take that already limited palette and try and use it for something that it patently is not suited for?

Enter – Bitmap mode. This was something I did for the C Framework library more than ten years ago now, because I wanted nice swoopy backgrounds for my Juno First game. It grew out of the times when you had to build tiles manually in hex editors and after I rolled my own very basic tile editor, I realised I could build tiles in engine just as easily.

I’m not going to go into details about how it works (basically applying boolean logic directly into the tilespace to set/reset the individual bits of an 8 byte tile, I’ll leave it as a challenge for the reader to work that out). Most of my games have some form of bitmap support – from the bootup “rug” pattern in Joust and Defender or the star background in Juno First, but generally all the heavy lifting is done with Sprites and Tiles as SNK intended, so I thought it would be “fun” to try and write a game entirely in bitmap mode.

Now, cards on the table, I tried this several years ago by trying to write a version of Qix but I got myself thoroughly tied up in knots doing that and couldn’t face going back to the code again, so this time I’m starting from scratch.

Buckle up, this is going to be a long one…

So far, all I really have is a name “Defenderoids” – which I came up with simply because I couldn’t decide whether to do a Defender clone or an Asteroids one. I have little to no idea how this might play at the moment, it is “just” a name*.

Bitmaps on the NGPC are created within a tileset which then gets echoed to the screen as an array. The basic approach is as follows :

void Defenderoids()
{
	u16 bmpPlayField[252][8];
	CreateBitmap((u16*)bmpPlayField, 144, 112);
	CopyBitmap((u16*)bmpPlayField, bgTileBase);
	//Copy the bitmap to SCR_1_PLANE
	// Watch the order...
	for (iLoopY=0;iLoopY<14;iLoopY++)
	{
		for (iLoopX=0;iLoopX<18;iLoopX++)
		{
			PutTile(SCR_1_PLANE, 0, 2 + iLoopX, 1 + iLoopY, bgTileBase+iTile);
			iTile++;
		}
	}
}

That won’t look like much – since we’re not actually putting anything into the bitmap. But that’s essentially the blank canvas that we can then use.

We can then use SetPixel() to write individual pixels to the screen. We’ll start with a star field…

void Defenderoids()
{
	// Variable declarations
	u8 iTile;
	u8 iLoopX;
	u8 iLoopY;
	u8 iLoopStar;
	u16 bmpPlayField[252][8];

	// Create a "bitmap" array
	CreateBitmap((u16*)bmpPlayField, 144, 112);
	// Copy the bitmap array into the tilespace
	CopyBitmap((u16*)bmpPlayField, bgTileBase);
	//Copy the bitmap to SCR_1_PLANE
	iTile = 0;
	for (iLoopY=0;iLoopY<14;iLoopY++)
	{
		for (iLoopX=0;iLoopX<18;iLoopX++)
		{
			PutTile(SCR_1_PLANE, 0, 2 + iLoopX, 1 + iLoopY, bgTileBase+iTile);
			iTile++;
		}
	}

	// Draw a "random" star  field
	for (iLoopStar=0;iLoopStar<25;iLoopStar++)
	{
        	iLoopY = QRandom()>>1;
	        iLoopX = QRandom()>>1;
        	SetPixel((u16*)bmpLogo,(u8)(iLoopX),(u8)(iLoopY),QRandom()>>7);
	}
}

I’ll leave this post here, next time I’ll dig into how to create and use some simple vector objects.

* Although names are important…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s