Friday, March 21, 2014

Sprite Sheets to the Wind...

The past few days have seen me dipping into other projects (i.e. paid work!), so my time on Citadel has been somewhat limited. However, I managed to use my time wisely, and dedicated my efforts to tweaking some of the graphics (now that my tile size is definitely 64x64... definitely... for now...).

One of the tasks on my list was to arrange all of the C64 sprites on a master sprite sheet, on a 64x64 pixel grid.This serves two purposes:

1. Although I import my sprites using strips, on a case-by-case basis, having all of the sprites laid out on one sheet in PhotoShop is extremely useful (not least because it allows me to see typically how much space the sprites use, and how much of each texture page remains). Plus, it means that I'm only ever updating one file - a huge pet peeve of mine is having a lot of clutter in my working folders.

2.  Currently, sprites can be any size, which can cause issues given that a) everything moves on a tile-by-tile basis, and b) things can move at different speeds. Plus, if I want a sprite to appear in the center of a tile, I have to add additional code to calculate the sprite's width and height, divide by two, and add this to the sprite's co-ordinates. Messy, and unnecessary. By ensuring that all sprites are 64x64, all sprites can have their origin set to the top-left of the sprite and everything will work perfectly.

The downside, of course, is that smaller sprites will contain a certain amount of empty space around the outer edges, but the wasted memory, at this point in time, is minimal.

* * *

In the process of laying out the sprite sheet, I needed to flip back and forth from the C64 version to ensure that my sprites were sitting in the right spot inside each 64x64 tile. Basically, C64 sprites are 24x21 pixels in size. In Citadel, everything is based around 32x32 pixel background tiles, and thus, the sprites are positioned roughly at the center of each 32x32 tile (4 pixels in from the left, and 7 pixels from the top, in case you were really desperate to know!).

On a couple of occasions, I had to do a little bit of detective work to understand why some of my ripped sprites didn't look the same as they do on the C64 (and in the process, I discovered that Martin Walker is doing an awful lot of neat stuff behind the scenes that the player will never know about or truly appreciate).

One of these tricks involves plotting a different background tile behind each trap, depending on the trap's contents. In the case of switches and weapons pods, the C64 version plots a unique tile filled with one of the game's background colours; this effectively allows the switches and weapon pods to use four colours (three sprite colours + background) instead of just three. A really simple idea, but extremely effective.

* * *

After a few sessions, the updated graphics were imported, and after tweaking (and simplifying) some of the logic code, all of my 64x64 sprites were in and working perfectly; everything aligns/snaps to the grid, and my trap animations now align perfectly with the background tiles (something which simply wasn't possible using smaller sprites and approximate positioning).

I rounded off tonight's session by tinkering with the force-field doors that will litter the cities (aside: I really need to produce a task list and start getting at least one task per day off my plate). It didn't take long to create an animated object which I can place in the levels, and after adding a couple of lines of code, I was able to stop the enemies passing through them (which now means I can out run the little blighters - at least, until I put in the player/force-field collision!).