Pages: 1
Topic closed
How do you make a sprite take several hits to kill without all giving them a seperate variable?
Offline
You give each sprite its own "hit points left" variable and decrement it every time it is hit.
If you want to avoid variables, you could give the sprite multiple costumes, and change the costume each time it is hit, having it die when it gets to it's last costume (using the costume# to determine its current status, instead of a separate variable). This wouldn't work for sprites that are animated, but would be fine for sprites that move around without changing costumes.
Offline
That's an interesting idea, using the costume # to record state of health. I suppose you could get inventive and use any of the internal state variables that weren't being used for their regular purposes. For instance, you could use sprite direction, if you were controlling motion with X and Y and the sprite costume was fixed to ignore direction. This would make for very hard-to-read code, however, probably more straightforward to use a variable.
It's not hard to make variables for a bunch of sprites if you make one sprite your template sprite, test it a lot to make sure it does what you want, then copy it a bunch of times and make any individual changes required. The variables will be created automatically when you copy from the template.
Offline
I agree that using internal state (like direction or costume#) can make code hard to read if it has nothing to do with attribute being represented. I like the idea of using costume # for health, though, because
1) you can change the appearance of characters as they get injured, making the health more integrally part of the game experience
2) you don't need to make a separate health bar or health display, reducing the screen clutter.
Offline
Those are very good points. The code readability issue can also easily be addressed if one is willing to define a non-displaying variable, to be treated as a constant, such as "Constant Death Costume" so that the code for detecting death would be something like
Wait Until <Costume # = Constant Death Costume>
There would be no question about what was going on there.
Offline
use a variable
http://kevan.org/brain.cgi?name=PenguinLove
Offline
Thanks everyone, i wasnt very good at scratch when i posted that
Offline
Topic closed
Pages: 1