Here is my todo list with some of the items already crossed off:
DONE:
- animate aliens back and forth across the screen until at least one alien hits the edge of the screen before changing direction and dropping down 1 tile row.. (This took me a long time to figure out.)
- draw shields on the screen
- controllable player cannon
- bullets (player shooting) - shoot event, bullet animation, clear bullet logic when bullet hits an invader or flies off the top of the screen.
- detect bullets colliding with aliens ( This was also very tricky to get right. See the post script of this post for a bug that kept me up at nights)
- delete aliens from the game area when bullets hit them.
- implement game-over detection (player has defeated all the aliens)
- alien death animation / explosion
- implement shield damage from player bullets
- implement shield defense and damage from alien bombs
- let aliens drop bombs - all code as per bullets but going down and with a different sprite pattern and colour.
- detect collision between bomb sprites and player sprite (player dies)
- implement 3 lives system
- implement scoring system and score display text
- implement ufo
- sound effects
- game music
- implement start menu - including ability to play again etc.
- implement high score system.
- implement game levels. Options include increased number of alien bombs at once, faster aliens etc.
Thanks for you patience
~ Dave
PS:
Bullet detection between sprites and aliens is a matter of finding the tile position on the screen under the bullet sprite. Then find the pattern byte of that tile that matches the bullet's Y position within the tile. Then use the bullet's X Position within the tile to bit test the pattern byte for a pixel. If a pixel is on (1) then we have hit the alien. If the pixel is off (0) we have not hit the alien. Maybe we are just under it's armpit or something. In this case, the bullet is moved up the screen by the number of pixels determined by it's speed. I was moving my bullets 4 pixels each frame.
The bug I was having trouble with was that for the bottom row of aliens, I would often be aligned with their eyes. I would not match a pixel on the first frame. Then the next frame would put the bullet directly over it's eyes (which are empty pixels) and, of course, not match. Then the bullet would move another 4 pixels and be above the alien.
The solution turned out to be quite simple. Just move the bullets 3 pixels each frame which (based on the alien tile-set I am using) will always guarantee a hit if the bullet is over the body of the alien within the tile. The bullets will never coincide with the eyes.
I am not over exaggerating when I say this took me a week to figure out. I was only able to solve it by stepping through the code using the Mame debug tools and a notepad and pen to validate all the calculations and bit matching.