Wednesday, October 20, 2010

Shield System UML Diagrams, Iteration 1

The shield system for the Space Invaders project is somewhat hierarchical in nature; not just through inheritance, but through the system of instantiated objects as well.  The class diagram below shows the classes that make up this subsystem.



Both the shield class and the individual bricks that comprise it derive from the basic sprite class because they have similar needs -- rendering, collisions, changes in state, etc.  The shield itself maintains an array of brick objects so that each brick can have its own state and damage effects.

The damage effect is accomplished by the dynamic creation of a separate image object.  When a brick is destroyed, it generates a "damageEffect" image.  The appearance of crumbling is attained by randomly drawing ovals onto the "damageEffect" image, which is then superimposed over the normal shield brick image.  So the bricks don't actually go away.  Instead, they change state which changes their collision response (nothing counts as a collision) and their rendering behavior (the damage effect is drawn over the brick image).

Collision detection and response happens in the game's update phase.  The game screen calls to the collision processor to process all relevant collisions.  Part of that process involves checking the shields for collisions with projectiles, and another part checks for collisions with the invaders.  Here's a rough, highly generalized form of the sequence diagram.

No comments:

Post a Comment