Pattern Designer

The gif has a jump for some reason!

Being as I am writing a shoot ’em’ up I needed some way to may pretty sprite patterns for all the bad guys, and my original plan was to make it using macros and data, but that would have been hard to visualise, so I broke out visual studio again and wrote a pattern designer.

Again I have shared the project on git hub, for those who wish to learn and or compile and use. I have tried to keep the data small and I have also used the same sin and cos tables from my going in circles code, you can see the that with a small modification, rewriting the circle function using vectors rather than circles and radiuses would be an easy task.

		private byte[]	sinTable =	{0x00,0x02,0x03,0x05,0x06,0x08,0x09,0x0b,0x0c,0x0e,
						0x10,0x11,0x13,0x14,0x16,0x17,0x18,0x1a,0x1b,0x1d,
						0x1e,0x20,0x21,0x22,0x24,0x25,0x26,0x27,0x29,0x2a,
						0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
						0x35,0x36,0x37,0x38,0x38,0x39,0x3a,0x3b,0x3b,0x3c,
						0x3c,0x3d,0x3d,0x3e,0x3e,0x3e,0x3f,0x3f,0x3f,0x40,
						0x40,0x40,0x40,0x40,0x40};

		private byte[]	cosTable = 	{0x40,0x40,0x40,0x40,0x40,0x40,0x3f,0x3f,0x3f,0x3e,
						0x3e,0x3e,0x3d,0x3d,0x3c,0x3c,0x3b,0x3b,0x3a,0x39,
						0x38,0x38,0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x30,
						0x2f,0x2e,0x2d,0x2c,0x2b,0x2a,0x29,0x27,0x26,0x25,
						0x24,0x22,0x21,0x20,0x1e,0x1d,0x1b,0x1a,0x18,0x17,
						0x16,0x14,0x13,0x11,0x10,0x0e,0x0c,0x0b,0x09,0x08,
						0x06,0x05,0x03,0x02,0x02};	

		private	void	addVector(int sprite)
		{
			byte	angle		=	sprites[sprite].direction;

			if(angle>=192 && angle <= 255)
			{
				angle			=	(byte)(angle - 192);
				sprites[sprite].x	+=	(short)-((sinTable[64-angle] * sprites[sprite].speed));
				sprites[sprite].y	+=	(short) ((cosTable[64-angle] * sprites[sprite].speed));
			}
			else if(angle>=128 && angle <= 191)
			{
				angle			=	(byte)(angle - 128);
				sprites[sprite].x	+=	(short)-((sinTable[angle] * sprites[sprite].speed));
				sprites[sprite].y	+=	(short)-((cosTable[angle] * sprites[sprite].speed));
			}
			else if(angle>=64 && angle <= 127)
			{
				angle			=	(byte)(angle - 64);
				sprites[sprite].x	+=	(short)((sinTable[64-angle]  * sprites[sprite].speed));
				sprites[sprite].y	+=	(short)-((cosTable[64-angle] * sprites[sprite].speed));
			}
			else //if(angle>=0 && angle <= 63)
			{
				sprites[sprite].x	+=	(short)((sinTable[angle] * sprites[sprite].speed));
				sprites[sprite].y	+=	(short)((cosTable[angle] * sprites[sprite].speed));
			}
		}

Programming Patterns

The way I see it is Each pattern element is made up of a few variables that can be chained together to create more complex patterns. Also with separate pattern elements we can group them and repeat them in a loop a fixed number of times before moving onto the next element.

Sort of like programming with loops

The ID is just the element number in in the sequence while the checkbox I use for selection when deleting, moving and looping, but more on that below .

Clicking the little plus collapses and expands the pattern.

The variables

Delay, because some patterns are made of multiple sprites and you don’t want them all on top of each other each subsequent sprite is delayed by this value.

Dir+, this is the direction that the sprites head as on this element, you will notice it has a + this is so you know its accumulative allowing you to make sharp turns, like bouncing off a wall.

Turn, this is the amount added to the direction every frame creating circles, using a negative number here turns it clockwise and positive anticlockwise (yes I know)

Speed+, another accumulative value that adds to the speed of the object, a negative number here slows the object down from previous speeds.

Time, the duration (how many frames) of the element before moving onto the next.

The spawn drop down, is basically a trigger that is fired for every sprite in the pattern, which you would have to program in your game.

And that leaves the colour dropdown which allows you to colour the elements and sprites so you can see what’s going on during playback.

How to use

Add a pattern element to the end of the pattern

Delete any element that is checked

Move the checked element up or down the pattern list

Open a saved pattern (XML file)

Save this pattern (XML file)

Link this links the elements between and including two checked elements into a loop, and allows you to repeat sections of your pattern.

Unlink as the name suggests this unlinks checked elements removing the loop.

Exports the pattern data as bytes in a ASM file with the option for binary or basic. (read the comments in the asm file)

// patterns { delay, direction, speed, turn, time, spawn (None,Shoot,Radial,Drop)}
// loops{negative byte offset, variable for count, count resetvalue}

Play, Pause and Step, controls for playback of your patter, stopping and starting again, starts the patter from element 0.

Various settings, like size of guide area, enabling a grid, sprite size, and initial location.

Simples.

As I say the code is on Git hub however I have not created binary versions as the source is there and you can compile it, also I am not giving you the player as I have not written it in z80 yet and as as I am not making your game for you, you can easily code the player from looking at the source code. You should have to put a little bit of effort in shouldn’t you?

Enjoy