Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to Make Enemy Die with Certain HP HELP!

Author
Message
elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 21st Feb 2010 05:05
I was trying to create a simple program wherein an enemy had an HP and after it reaches 0 it will die. I made a simple code



The enemy had 5 HP. so for certain loops it should be hit 5 times by the arrow. But unfortunately when it was hit by the arrow it dies instantly. Any problem with my codes?
Carlos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 21st Feb 2010 06:07
Once the two sprites collides, HP is decremented in every loop...
elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 21st Feb 2010 06:48
yeah it is decremented but i want it decremented 1 by 1 as the arrow hits it. Since it has 5 HP it should be hit 5 times also by the arrow. but on my code it was only hit once and then it dies.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 21st Feb 2010 07:59
you want it to go to starting posisiton when it hits the other?:


elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 21st Feb 2010 08:54 Edited at: 21st Feb 2010 09:55
@Hassan

Actually what i mean is that the enemy from the right side will just walk having a 5HP. Then the arrow will just shoot and if it hits the enemy it will reduce its HP by 1. After hitting the enemy the arrow will disappear and goes back to the first position and try to hit the enemy again. When the HP of the enemy turns to 0 then it will be deleted. I just tried to make it hide and output the value if my code is correct.But it isn't since the value gets negative even for the first arrow. Don't have any clue on how to make those shots decrement the value of the HP only by 1 once it hits the target.Hope you could help me.
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 21st Feb 2010 09:56
Well, I don't really know how to explain it, but you sync your game at 60. So lets say that are 60 FPS. That means that in a second you imp gets hit 60 times. So you need to only let your arrow appear when you press something, because now its appearing 60 times per second ( ofc. this is not exact ) and the hp decreases so fast that it looks like as if it automaticly skiped from 5 to zero. So what I would do is something like this:



Isocadia

elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 21st Feb 2010 11:29 Edited at: 21st Feb 2010 12:03
@Isocadia

I can Fire the Arrow but the only thing I can't make up my mind is how to precisely decrease the HP by 1 per hit. I'm thinking ways to do it but still same thing happened.

Thanks for the reply btw.

EDIT: Btw I already solved the problem thanks for all your help.
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 21st Feb 2010 12:04 Edited at: 21st Feb 2010 12:07
Well, I think this might work:



Then shoot is defined true when you pres the button to shoot, it decreases HP with 1 and resets the sprite position to the original position ( players position )then sets shoot to false so it does not decrease HP again until you repress shoot button.

Isocadia

Login to post a reply

Server time is: 2024-11-19 15:11:50
Your offset time is: 2024-11-19 15:11:50