Placing your main character

12-23-2017
While looking at the code example within the FASE demo, I came across these lines of code.

x = 0x3000;
y = 0x1000;

I don’t know what to think about this line, so I have to call out the big guns – Antonio.

It’s the position of the main character. The high byte is the real coordinate on the screen. But the whole 16 bits is the fine tune coordinate. It’s like fixed point maths. 0x30 represent 48 in decimal, so X initial coordinate is 48.00. If for example in the game the coordinate is 0x1240, the decimal correspondence is 18.25

Hmm, it appears that the mystery is solved.

Which gets me to thinking.

Our game will have different levels and as such should have different starting positions.

We might also be able to use this particular bit of info for in level warping, i.e. touch it and transport to a different area of the screen.

Let’s give it a try.

Open up our tiled program and place a blue moon graphic at 13,2, which calculates at x = 186 to 215 and y from 9 to 39.

In our collision detection routine, we will place the following code.

if (playerX > 186 && playerX  9 && playerY < 39)
{
    zx_border(6);
    x = 0x3000;
    y = 0x1000;
}

Compile and run and it works just like advertised. When you touch 13,2 you are warped right back to the start. Sounds like we have another type of obstacle, a transporter.

So, if 0x3000 is the same as x = 48, then would it not be just as easy to have x = 48 instead of using hex. No, apparently not!

When I try

//x = 0x3000;
//y = 0x1000;
x = 48;
y = 10;

FAIL!

Darn thing starts at 0,0

if I try

x = 48;
y = 0x1000;

Y is correct and X still fails.
Let’s go back to Antonio’s message.

The high byte is the real coordinate on the screen. But the whole 16 bits is the fine tune coordinate. It’s like fixed point maths. 0x30 represent 48 in decimal, so X initial coordinate is 48.00.

I’m not quite sure if I am interested in the fine tune bit, as it seems odd to me, perhaps it will come in useful later.

Knowing that for now, we have to stick with using Hex. Did I mention that I dislike hex (it’s not intuitive for me)?

Since we know that 0x3000 equates to 48, just to ease my mind, let’s try 0x3100

x = 0x3100;
y = 0x1000;

And that equates to x starting off at 49.

That solves that mystery, except for the use of hexadecimal. Don’t think about sending me anything that hex is superior and hex is good for you. I know that liver is good for me also, but you won’t see me eating it.

Advertisements

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