When one is not enough


Now that we have the game print 1 set of numbers at the top, what will we do to have a second set of numbers?  Pretty much the same thing, but different.

I am using my little utility routine to display only either X or Y, but not both.  That’s fine and dandy if you want just one set of numbers, but we don’t, we need both sets of numbers x and y to show simultaneously.

Well, we need to define another global

Remember bob from earlier, let’s give him a friend. 

unsigned char bob = 0;//used to print to screen
unsigned char sue = 0;//used to print to screen also

Both Bob and Sue are going to work together to give us the numbers we desire, our X & Y.  Deeply held inside that last sentence is a chromosome joke, please give a courtesy laugh now.

Let’s go back to our print function

void printtester(unsigned char info)
	char text[10];
	PrintStr("    ", 321);
	sprintf(text, "%d", info);
	PrintStr(text, 321);	

well it’s a bicycle built for one, we need a bicycle built for two. Still, the 1 number function is still good, let’s create a second function to print two numbers.

void printtester2(unsigned char info, unsigned char info2)

All that’s different here, other than the unimaginative name I just gave our function, is that we have added our second input to the function. Now, I don’t know if I explained this before, but on your functions, you do not have to use the same name as you are sending it, but it does have the be the same type, in this case, unsigned char. info will be substituted for bob and info2 will be substituted for sue when the program calls the function.

Now, we just change up our sprintf function and that’s really about it.

sprintf(text, "%d:%d", info,info2);

We just combined our variables into 1 longer screen, kinda neat.

Here’s the entire function:

void printtester2(unsigned char info, unsigned char info2)
	char text[10];
	PrintStr("          ", 321);	
	sprintf(text, "%d:%d", info,info2);
	PrintStr(text, 321);

Notice, the array for text didn’t change from the last function, truth is the last function’s array was too large to begin with, but who’s counting at the moment. Pretty simple code

Here we go, showing off the function in action.

We are going to be using this info and function for our next article (hopefully) collision detection (static object).


Author: andydansby

I'm a hobbyist coder working with the ZX Spectrum. Living in New York state near the Syracuse area. I grew up in Virgina. The first computer my parents bought for me was a Timex Sinclair 2068.

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