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 / Health Sprite (ketchupguitarra)

Author
Message
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 19th May 2009 02:46
howdy, i looked and looked but could not find a post that would help me with making an HP Bar Sprite thingamajig.

I have created a simple full-green sprite bar. I deduct an oriented float variable called "damage". Damage is any amount and is then subtracted from 100. I have used dbStretchSprite () where dbStretchSprite ( 10, 100 - (damage++), 100 ); 100 is the regular size of the sprite of X and Y.



CheckSpace() is supposed to represent a boolean check whether or not any damage was dealt. I will change the function later when i have created a running damage class.

My main problem is it will only perform the block of code once, and only calculate the X length shrinking operations once. So the green bar only shrinks by that amount of code once even when i press the space bar multiple times, or even hold it. Which brings me to another problem:

My checkSpace() function is of bool type and it is supposed to check to see if the space bar has been pressed without holding it. Take like a pseudocode where dbKeyOld or something like that... Say if I tapped the A button on a game controller it may shoot a bullet once for every click. (I know this is extensive but im just trying to explain myself)



That is an example of the shooting function i got from DGDK Dark Invaders.

So y'all, thank you so much.

Don't Clap, Just Throw Money!
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 19th May 2009 03:09
It doesn't do anything after the first time you press the space key because you keep on reassigning damage to be 0.5f every time the space key is pressed. Then, it adds 1. So every time the program reaches ->
, damage will always have a value of 1.5f. Just get rid of this line and it should solve the problem.
->

Also, this will achieve what you said you wanted in CheckSpace():

That should generate the desired result, but I haven't tested it.

#ifdef _DEBUG
FixBugs(All);
#endif
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 19th May 2009 03:21 Edited at: 19th May 2009 03:23
dude i cant tell u how awesome u r, that was so quick and it worked completely thx man

p.s. wat is this "static" u speak of?


Don't Clap, Just Throw Money!
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 19th May 2009 03:50
It causes a variable defined within a function to remember it's state between calls of said function.

------------------------------------
Currently 1500+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.

Login to post a reply

Server time is: 2024-11-05 18:48:41
Your offset time is: 2024-11-05 18:48:41