[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Natto-Cat



andrew baker wrote:

Well, there's always your next project.  Still, people will probably be
interested in at least seeing snippets of code, like the blood effects.

The blood effects were actually easy.

Every item's image or animation frame has a transparency colorkey (I
used (0,0,255)) for when it's blitted to the screen.  There is also a 2
color mask version of every image.  In this mask version, the
nontransparent portions of the original image are made up of a single
other color (I used (0,255,0) which is ALSO the colorkey.  Everything
else is (0,0,255), the colorkey of the original image.

So a blood sprite is blitted onto the original image.  Then, the mask is
blitted onto the image, chopping off whatever bit of the blood is
"hanging in space" where the image should be transparent.  (It covers up
the blood with the original image's transparent color.)

I programmed Natto-Cat to allow for "chunks" - sprites that would stick
to objects.  So if a rabbit exploded, a chunk of it could stick out of a
wall, and then afterwards blood or custard could splatter on that chunk,
too.  That meant updating the image's mask version when a chunk was
blitted onto the image, which was just a little more complicated, but
easily done.  However in the game it didn't look as cool as I had hoped,
and it also meant more sprites had to be part of an OrderedUpdates
sprite group, otherwise overlapping sprites would flicker... so I
decided it wasn't worth it.    Now only the cat's explosion releases
"chunks" - gears and springs - well, that's what they're supposed to be,
anyway, which can later be splattered onto like whatever they're stuck
to.  Sometimes I've been amused when the cat exploded and a gear struck
a nearby custard, which ran away with a panicked face and a gear
sticking out of its head.  ;)

Aaron