Community
Message Board

Chat room - users
Game Over
( 394431 downloads)
Work In Progress
( 523201 downloads)
Links

Code Exchange
Downloads
Tutorials
Add to Favourites

Submit news

DIV ARENA FORUMS
Not logged in [Login - Register]
Go To Bottom

Printable Version  
 Pages:  1  2
Author: Subject: Accurate health bar
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 23-11-2016 at 05:01 PM


It has been a pleasure for me, I hope that you can finish the game, and I hope to see soon a new demo. :)
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 23-11-2016 at 06:37 PM


Uh-oh, there is a problem: I wrote your code, it works fine when your energy is at 100%, at 75%, etc.; but when your energy is at 50% or less the energy bar disappears, and it reappears when your life is bigger than 50%. I have adapted the same code for the magic bar, and the same problem occurs. The bar does not show any graphic when your health is less than a half.

View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 23-11-2016 at 06:48 PM


Mmmm yes, need another formula than, wait please.

[Edited on 23-11-2016 by CicTec]
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 23-11-2016 at 07:20 PM


I used your code changing only the words "energy_damage" to "daño"("damage" in spanish), the rest is the same, I think.

PROCESS barra_vida(x,y);

BEGIN graph=22;
z=-503;region=10;
LOOP

IF(daño>1)energy_bar=max_energy/daño;

IF(energy_bar<=0)energy_bar=1;END

define_region(10,2,3,100-(100/energy_bar),10);

ELSE

define_region(10,2,3,100,10);END

FRAME;END END

In the player process I wrote a line to control the "damage" variable, so it increases every time you are touched by an enemy, an it decreases when you touch a recovery heart or a Red Flower and you recover part of your life. (the Recovery Heart refills your health and a Red Flower recovers 10 health points). As I said, the only problem is that the energy bar disappears when your life is under 50%, the rest of the time it works well.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 23-11-2016 at 07:31 PM


You can use the formula of Mike, adapted for your 100 pixels bar:
Code:
real_unit = 100000 / max_health; health_unit = real_unit / 1000; if(health_unit <= 0) healt_unit = 1; end define_region(1, 0, 0, 100 - (health_unit * damage), 10);

But you'll have some inaccurate values, because the formula would require floating point currently not supported by DIV.

100000 is the value of your bar width (100 pixels) * 1000 (the decimal floating point conversion to INT).
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 24-11-2016 at 08:14 PM


It works, but it seems that when your energy/magic reaches 0, the bar still shows a little part of itself. I've used your second code for the health and the magic bar, and this is the only problem, I recorded a video to show how it looks.

https://www.youtube.com/watch?v=TFH9HGZPgts
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 24-11-2016 at 08:25 PM


in which the minute video is shown?

It should be easy to solve, try:
Code:
if(damage < max_health) real_unit = 100000 / max_health; health_unit = real_unit / 1000; if(health_unit <= 0) healt_unit = 1; end define_region(1, 0, 0, 100 - (health_unit * damage), 10); else region = -1; end

if damage> = max_health simply the graph does not appear in any region.

[Edited on 24-11-2016 by CicTec]
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 24-11-2016 at 08:41 PM


No, it is not showed in the video. (Well, in second 0:23 the magic reaches 1 point). The video has been recorded to show how the new life and magic bars work.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 24-11-2016 at 08:49 PM


From the video it seems to work well, the issue of when it reaches 0 should be corrected with the above code, try please.
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 24-11-2016 at 08:54 PM


I' ve tried and when the health/magic reaches 0, the bar shows the full width.

Now this is the process "life bar" from my game:

PROCESS barra_vida(x,y);
PRIVATE real_unit;health_unit;
BEGIN graph=22;
z=-503;region=10;
LOOP

IF(daño<1)daño=1;END
IF(daño<max_energy)real_unit=100000/max_energy;

health_unit=real_unit/1000;

IF(health_unit<=0)health_unit=1;END

define_region(10,2,3,100-(health_unit*daño),10);

ELSE region=-1;END

FRAME;END END
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 24-11-2016 at 09:15 PM


I can't test for now with a really example, try:
Code:
if(damage < max_health) real_unit = 100000 / max_health; health_unit = real_unit / 1000; if(health_unit <= 0) healt_unit = 1; end define_region(1, 0, 0, 100 - (health_unit * damage), 10); else define_region(1, 0, 0, 0, 0); end
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 25-11-2016 at 10:02 PM


The bar is not accurate, but don't worry. At least, it works. In fact, perhaps the game is not going to be finished anyway.
View user's profile View All Posts By User
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 25-11-2016 at 11:12 PM


Quote: Originally posted by Dani_Karmann  
The bar is not accurate, but don't worry. At least, it works. In fact, perhaps the game is not going to be finished anyway.


:(

We'd all like to see the game finished, Dani!!

If you're really struggling with it, would you like me to send the source code for the health bar from Cybercrisis? :)




~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 25-11-2016 at 11:31 PM


Quote: Originally posted by Dani_Karmann  
The bar is not accurate, but don't worry. At least, it works. In fact, perhaps the game is not going to be finished anyway.

Unfortunately it is a loss of accuracy problem for INT, when the floating point support will be added to the formula will be accurate.

I hope you can finish the game. :)
View user's profile View All Posts By User
Dani_Karmann
DIV Pro
******




Posts: 87
Registered: 4-8-2016
Member Is Offline


[*] posted on 26-11-2016 at 09:54 PM


I will continue this in the "WIPS" section. Breadcaster, this is the energy bar process:

PROCESS barra_vida(x,y);
PRIVATE real_unit;health_unit;
BEGIN graph=22;
z=-503;region=10;
LOOP

IF(daño<1)daño=1;END
IF(daño<max_energy)real_unit=100000/max_energy;

health_unit=real_unit/1000;

IF(health_unit<=0)health_unit=1;END

define_region(10,2,3,100-(health_unit*daño),10);
ELSE define_region(10,2,26,0,0);END

FRAME;END END
//---

(Note: "daño" means "damage" in Spanish)
View user's profile View All Posts By User
 Pages:  1  2

  Go To Top

Powered by XMB
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 18]