Thursday, January 6, 2005

Thursday 6th

After more than a little noggin scratching, yesterday I managed to resolve the problem with Monitor's erratic screen position, so today I could plough ahead and write the collision routine. While collision may seem to be rather complex, map collisions are relatively simple to check for.

I started off by creating a routine that tracked the mouse position (purely to make the routine easier to test), and made it highlight the tile beneath the pointer. Once this was done, I added the tweaks to ensure the highlight aligned itself properly to tiles even when the screen was being scrolled.

Next, the routine was adapted to highlight the tiles directly adjacent to the main tile (apart from diagonals - Monitor can only move in four directions). Finally, I added a tweak to check these adjacent tiles to see if they are solid walls and, if so, change the highlight colour from green to red.

Once the routine was complete, I tweaked the routine to get its X and Y information from Monitor, as opposed to the mouse, and tweaked the movement routine to utilise the collision data. The upshot of all this tinkering is that the tiles directly adjacent to Monitor are now checked to see if they are solid and, if so, the player is prevented from moving to them.

I now have the bulk of the background collision system in place - this will require a few tweaks tomorrow when I finalise the movement routine to make Monitor move a whole tile at a time, as opposed to pixel-by-pixel.

The collision system in action, with wall tiles highlighted in red...