This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-01-26 18:34:20

Rurigok
Scratcher
Registered: 2008-01-24
Posts: 93

How do you make a sprite take several hits to kill?

How do you make a sprite take several hits to kill without all giving them a seperate variable?


Creator of Imperion Online(a MMO)
ImperionOnline/Cyclone103's forums.

Offline

 

#2 2008-01-27 14:05:16

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How do you make a sprite take several hits to kill?

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

 

#3 2008-01-27 14:28:13

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How do you make a sprite take several hits to kill?

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2008-01-27 15:32:53

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How do you make a sprite take several hits to kill?

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

 

#5 2008-01-27 20:58:36

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How do you make a sprite take several hits to kill?

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-01-27 21:59:59

Vanslar
Scratcher
Registered: 2007-03-17
Posts: 100+

Re: How do you make a sprite take several hits to kill?

use a variable

http://kevan.org/brain.cgi?name=PenguinLove


  I am a royal pain in the butt, I am ~Vanslar~       
      Want better gravity? Go to
Realistic Gravity, By Vanslar 2-D
Want a better way to spend your spare time? CubeField

Offline

 

#7 2008-02-27 08:38:08

Rurigok
Scratcher
Registered: 2008-01-24
Posts: 93

Re: How do you make a sprite take several hits to kill?

Thanks everyone, i wasnt very good at scratch when i posted that


Creator of Imperion Online(a MMO)
ImperionOnline/Cyclone103's forums.

Offline

 

Board footer