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.

DarkBASIC Professional Discussion / need help for my health bar

Author
Message
miss shasha
14
Years of Service
User Offline
Joined: 29th Sep 2011
Location:
Posted: 12th Nov 2011 17:35
Good day! i need help for my health bar. i got a source code for it and i have a health bar now that appears as i want it. but my problem is i dont know how to make it decrease when my character is hit by mobs. what would be the possible ways for it to decrease when hit by mobs and increase when my character used potions? thanks

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 12th Nov 2011 19:52
Exp:
character hit a mob --> player loose 10 point
if the health bar is 100 pixels long, every time the character hit a mob the helth bar will decrease by 10 pixels.

if the health bar is a sprite resize the sprite 90,100. then move it lafet by 5 pixels.

or, put 10 sprites next to each ohter each one has x=10 pixels.
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 12th Nov 2011 21:22
Another way of doing this is to have a single sprite for the health bar and then scale it using the STRETCH SPRITE command as used in the demo below.



In the demo I'm using the down key to reduce the "current_health" variable.

What you will need to do is give each mob (I had to look that up to see what it meant ) a "current_health" variable.

Then you will need to work out how the mob's health is reduced and this will depend on what type of game you are making. If you're firing bullets / arrows then you need to work out if the bullet / arrow has hit the mob (have a look at the SPRITE HIT and SPRITE COLLISION commands).

If it's more of a sword fighting / fisticuffs kind of game then you need to determine if the player is close enough to the mob when the player is pressing the attack buttom (what ever that button is).

Quote: "...increase when my character used potions"


You will need to have a "current_health" variable for the player but after than it's going to depend on what kind of game mechanics you want. For instance:

1) The player's health is immediately increased by 5 (for example) when the player moves onto a health potion bottle.

In this case, again you can use the SPRITE HIT or SPRITE COLLISION command to determine if the player has hit the potion bottle and increase the player's health if a collision has occured. The bit you will need to decide is does the bottle disapear once it has been used? If the player is at maximum health do you want to stop the potion being used so it is available for later?

2) The player picks up a potion, adds it to some kind if inventory (this doesn't have to be a complicated inventory system)and then can use the potion whenever they want.

Use the same process as the first example to detect if the potion has been hit and then picked up. You could then have a variable called "number_of_health_potions" that is increased by 1 when the player collects a potion. If "number_of_health_potions" is greater than zero then the player is able to press a key (lets so P for potion) which will then increase their health. You will then need to decrease "number_of_health_potions" by 1 as one health potion has been used.

Anyway, I didn't mean for this to be so long and rambling but I hope it helps.

Login to post a reply

Server time is: 2026-07-10 05:45:35
Your offset time is: 2026-07-10 05:45:35