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

#1 2012-05-31 23:34:40

asmemark
New Scratcher
Registered: 2012-05-31
Posts: 3

HP and player

Hi guys new to the forum,
I need help on my project which is a battle, I need help on how to set up my hp using variables and also how to make my spirte from changing to a costume of him being hurt when trying to attack the other sprite.

Offline

 

#2 2012-06-01 00:14:35

silvershine
Scratcher
Registered: 2010-11-21
Posts: 500+

Re: HP and player

Hi asmemark, welcome to the forums!

To give your sprite hp, it must have a variable that stores its remaining life, and events that trigger a loss of life (like being touched by an enemy). I also incorporated the costume changes that you want to happen.

In the main characters scripts:

when gf clicked
set [life v] to (100) //you can have the variable name and amount of life be anything
forever if <touching [enemy sprite v]?>
change [life v] by (-10)
switch to costume [hurt v] //Change costume when hurt
wait (0.5) secs
switch to costume [normal v] 
when gf clicked
forever if <[life v] < (10)> //again, these can be whatever you want ;)
stop all //game is over if life is 0

Last edited by silvershine (2012-06-01 00:15:02)

Offline

 

#3 2012-06-01 01:52:55

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: HP and player

Yes, silvershines script will work just fine!


Why are the secret organizations getting all the attention?  mad

Offline

 

#4 2012-06-01 07:43:21

asmemark
New Scratcher
Registered: 2012-05-31
Posts: 3

Re: HP and player

Thanks Guys

Offline

 

#5 2012-06-02 20:13:10

asmemark
New Scratcher
Registered: 2012-05-31
Posts: 3

Re: HP and player

Okay now another problem, the sprite that is trying to attack the other sprite seems to loose health when it touches the sprite it's attacking any suggestions.

Offline

 

#6 2012-06-02 23:28:51

silvershine
Scratcher
Registered: 2010-11-21
Posts: 500+

Re: HP and player

asmemark wrote:

Okay now another problem, the sprite that is trying to attack the other sprite seems to loose health when it touches the sprite it's attacking any suggestions.

Hi again! In the future, post a new topic when you have another question. That keeps the forums clean and organized.  smile

On to your question: I would suggest creating a sort of "attack mode" for the enemy so that if it's attacking the player, it wont take damage.

To do this, create a variable (I called it "attack") and set it to "no" when the green flag is clicked.

when gf clicked
set [attack v] to [no]
Now in the enemies health script, add this:
when gf clicked
forever if <touching [human player v]?>
if <(attack) = [no]> //if the enemy isn't in attack mode
do attack scripts I showed you earlier
I don't know when your enemy sprite attacks, so for the purpose of demonstration, I'm going to assume that the enemy attacks after random periods of time. To make the enemy go into attack mode, do something like this:
when gf clicked
forever
wait <pick random (1) to (5)> secs
set [attack mode v] to [yes] //this will make it so that it doesn't take damage
attack scripts
set [attack mode v] to [no] //enemy can take damage again

Offline

 

Board footer