Quick setting Tiles

12-7-2017
How do we get tiles to stick on the game screen? By using some Quickset, you can try use mastic, no not really. What we might discover is that the process is much easier than trying to lay actual tile.

if we pay attention to the demo, when you hit an enemy with a bullet, the enemy changes into a little blue coffin, indicated its death. All we have to do now is find that little bit of code.

So, I look over the code a little and find something that looks suspiciously like a tile setting.

tiles[tmpy * scrw + tmpx]= 68;

let’s give that a little change and recompile to see if it’s the case

tiles[tmpy * scrw + tmpx]= 66;

Boingo, zoingo, yup that’s where it is.

Time to make a quick comment

tiles[tmpy * scrw + tmpx]= 66;//where enemy dies

That does not work on its own though if you comment out the next line.

tilepaint(tmpx, tmpy, tmpx, tmpy);

You will notice that the enemies will simply disappear when you kill them. So they both work in conjunction. You set the tile and must paint the screen with the tiles you set.

So armed with that bit of knowledge, one can generate an entire screen with some settings. Perhaps it could be an array set with the x,y and tile number. We will explore this another day since it will be the basis for the game.

Let’s now open your tile graphics, found in the /GFX folder. Using your favorite graphics editor, open up the file tiles.png

As you can see, the tileset is pretty large, 96 tiles, in fact, more tiles than I need for the game, which I’m pretty sure is eating up the memory. I’ll leave them in place for now, but as memory gets scarce, this will be the first thing I’ll look at.

The Tile numbering scheme starts at 0 and continues on to 95. Below find a nice little numbering scheme…..

I shouldn’t have to say this, but it has happened to me before, the Spectrum has a limited color display and you can have 1 foreground color and 1 background color per 8×8 square. If you accidentally place a 3rd color, the compilation process will look almost ok but will error out.

I happen to be using Paint Shop Pro (use GIMP if you don’t own PSP or Photoshop) and I have made a quick edit to the tileset to define the graphics for the border only.

Here are my new tiles. Notice that I created 4 tiles for top, bottom, left and right as well as 4 tiles for the corners. That’s 8 tiles right away!

Save the tileset and then open your MAP.TMX file to see the new graphics. If you left the TILED program open, just close it and reopen it to observe your new tiles.

For now, that’s all we need, we will modify additional tiles as needed.

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.

One thought on “Quick setting Tiles”

  1. Hi Andrew
    The tilepaint(tmpx, tmpy, tmpx, tmpy) is the rectangle area you want to repaint. It’s not a function. It’s a macro that only set a byte and the engine recognize.

    #define tilepaint(from_x, from_y, to_x, to_y) *repaint= from_x|from_y<<4|to_x<<8|to_y<<12

    Of course tilepaint(0, 0, 14, 9); also works but it's very slow because repaint the entire screen (and only changed 1 of 150 tiles).

    Liked by 1 person

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