What approaches could you use to implement the the gradual destructions of bases/shields in a top down shooter type game similar to Space Invaders?

The simplest approach could be to use a series of sprites that are replaced to show increasing deterioration after each missile hit.

A more advanced approach might be to randomize the deterioration pixel by pixel after each hit, but I'm not sure how to implement an approach like this. Does anyone have any suggestions for how to approach something like this?

  • 3
    \$\begingroup\$ I'm voting to close this question as off-topic because knowing how this has been implemented in the original version is not possible because we don't have access to the source code, and that how you could achieve it depends on your current implementation. \$\endgroup\$ – Vaillancourt Mar 5 '16 at 6:34
  • \$\begingroup\$ Do you have suggestions for how this could be implemented to imitate the original? I'm curious what developers with more game development experience would suggest. I'm guessing it's unlikely it was implemented with randomized removal of pixels in the original, but I'm interested in suggestions. \$\endgroup\$ – Kevin Hooke Mar 5 '16 at 6:36
  • 2
    \$\begingroup\$ You already have 2 ways to do it. Implement one, if it works for you, keep it, if it does not, go with the other; if it works for you keep it, otherwise, try something else. That's what experienced developers do. Just do it; that's game dev, you will not get it perfect on the first time, no one does :) \$\endgroup\$ – Vaillancourt Mar 5 '16 at 6:39
  • \$\begingroup\$ Also, be seeking to replicate the original code as much as you do, you are not creating a clone. Think of a way to do this, yourself, and come back to use if you run into any problems localised to your game. Remember, if your copying somebody elses method, your opening yourself up to severe legal prosecution. If Nintendo cant copy the code from Donkey Kong, you cant copy the code from Space Invaders. \$\endgroup\$ – Gnemlock Mar 5 '16 at 15:44
  • \$\begingroup\$ @Timelord64, good points. I'm doing this for a learning exercise. I'm more interested in the technique that was used. Nowdays it would be more common to implement it as a destructible environment, but my reason for asking the question is that I'm guessing the hardware of the original machine was not capable of implementing something this complex, so I was curious if anyone could suggest how it was done? \$\endgroup\$ – Kevin Hooke Mar 5 '16 at 17:56

A series of pre-defined sprites, per base, is a reasonable and simple approach.

A more dynamic approach that reflects the damage to each base on a per-pixel can be accomplished via a mask. The mask is a simple bit map corresponding to the base sprite. 0 for an invisible pixel, 1 for a visible one. Initially the mask would look like a blacked-out version of the base. For example, with crude ASCII art:

  mask         sprite
  ----          ----
00111100        ####
01111110       ######
11100111      ###  ###

When you render, you use both the mask and the real sprite and you skip drawing any pixels of the sprite where the mask is 0. In the old days we'd do this with bitwise magic prior to blitting the sprite; on modern platforms you'd probably accomplish this by multiplying the mask's color with the sprite's color.

Whenever a base takes a hit, you update the mask by:

  • determine which horizontal column of the base was hit
  • set the first non-zero bit in that column to 0 (starting from the top)

This will give you a per-pixel degradation of the base as it takes damage.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.