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
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
Yes, silvershines script will work just fine!
Offline
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.
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 earlierI 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