Saturday, 4 September 2010

Collision Complication

Solid progress today, much better than I expected - I now have Meanies and the Fuelship moving around on the screen, tidying-up after themselves and not leaving little trails lying around. The Meanies move the right way, the Fuelship appears at the right sort of interval and descends gracefully, and suddenly the whole game is starting to look 'alive'. There's a fair way to go yet, but it's definitely getting there!

I dropped a little 'Vsync' wait into the main game loop to get rid of plotting flicker, so the main loop now runs once per screen refresh and then waits for the raster counter to reset before continuing. There's no point running the game faster than this, because although it actually can run about 50 'cycles' per frame, the player can't see the benefit of it because the screen isn't redrawn that quickly. Also, running faster than the refresh rate makes the updates a bit flickery, so it looks slightly rubbish. By waiting for Vsync, we only update the screen once per frame, just before the VIC chip draws it, which looks super-smooth. As it happens, the game is running much faster than the original BASIC version (hardly surprising, since it's 100% assembler) so I've also had to put a sizable delay loop around Vsync to make it wait for around 50 or so frames to pass, just to slow things down and make it playable!

The problem I'm grappling with now is that of collision detection - figuring-out whether a moving thing has hit something else, and doing something appropriate if it did. The difficulty is that the logic is structured so that we check to see if something will collide before it actually does, as when the Fuelship lands - we want to know that it is about to hit the floor, not that it has hit (and sunk into) the floor. This is working fine - the ship lands and I get a flag set to tell me so, and I can then both deactivate it (which removes it from the playfield) and increment the current fuel level.

However, Meanies have to actually smack into something before they explode, so checking to see if a Meanie will hit a wall (for example) is no good - I don't want to do the collision processing until it actually impacts. Unfortunately, when the Meanie does hit a wall, it overwrites the wall character with itself - which means that if I try to alter the check to see if the Meanie did just hit something, all I see at that position is the Meanie.

I may have to stash the character the Meanie just overwrote when it moves, just so I can look to see what was there before the Meanie arrived. Not a huge issue, but since the VIC doesn't support hardware sprites and masks, I'll have to do it myself...

0 comments:

Post a Comment