Health Bar Problem...

Started by DoorKnobHandle, Sat 29/01/2005 14:34:13

Previous topic - Next topic

DoorKnobHandle

Hey!

Like I said in my last thread, I am working on this strategy game kinda like MIA.
I have the controls perfectly now, but now I am woorking on  the health system.
Right now I am drawing the health over the current character/building with "Raw"
draw functions. First I draw a big white rectangle which goes from the left to the right
all the way, then I draw a green line that represents the health, just like in most of
the strategy games like C&C or StarCraft etc.
But those Raw functions are awfully slow in 800x600 resolution, and I need to do those
in repeatedly_execute, because they need to move with the character of course...
I dont think sprites could do this very well, could they?
Is there any way to solve this problem?
Anybody ever did something like this?

Here's my code in repeatedly_execute:

Code: ags

RawRestoreScreen (); 
RawSetColorRGB (255, 255, 255);	
RawDrawRectangle (
character[GetPlayerCharacter()].x - 18, 
character[GetPlayerCharacter()].y - 51,
character[GetPlayerCharacter()].x + 17, 
character[GetPlayerCharacter()].y - 49);
RawSetColorRGB (20, 230, 20);	
RawDrawLine ( 
character[GetPlayerCharacter()].x - 18, 
character[GetPlayerCharacter()].y - 50, 
36*(GetCharacterProperty(GetPlayerCharacter(), "Health")/99) + (character[GetPlayerCharacter()].x - 18), 
character[GetPlayerCharacter()].y - 50);


Like I said the positioning works fine, but it is awfully slow... What can I do?

strazer

See this thread.

You could use additional characters, have them follow the units with FOLLOW_EXACTLY, make a view with 100 health bar sprites and set their frame according to the health of the unit they're following.

You might also be interested in this real-time strategy demo I made (no health bars yet).

DoorKnobHandle

Thanks for pointing that thread out for me ( I must have overseen it when I used the search button - because I used it!)

But you must be bulls**ting me with those 100 sprites. Hell no! If 100 sprites would follow the character it would prolly slow down as well anyways.

hmm...

I have another problem:

Something must be wrong with the way how AGS does mathcalculations, check this out:

in rep_ex:

Code: ags

// Mix Green/Red Color for second line according to the health level!
		int RedValue;
		int GreenValue;
		int SupportingBlueValue = 20;
		int CharacterHealth = GetCharacterProperty (GetPlayerCharacter (), "Health");
		
		GreenValue = (2.55)*CharacterHealth;	// I also tried 255/100 or 51/20 what equals the same - 2.55 - still doesnot work!
		RedValue = (-2.55)*CharacterHealth) + 255;
		
		if (GreenValue < 0)
			GreenValue = 0;
		if (GreenValue > 255)
			GreenValue = 255;
			
		if (RedValue < 0)
			RedValue = 0;
		if (RedValue > 255)
			RedValue = 255;


Now when I plugin a value of 100 for the chars health in the properties, ags tells me, that GreenValue = 200 and Red = 0... It does strange things with the other values for Health and I had to build those boundaries in the last eight lines in to get it to work at all because other wise it would have returned me values over or under 0 or 255 for the RGB func.

What in the world is wrong?

monkey0506

Quote from: mamarulez on Sat 29/01/2005 17:13:46
Thanks for pointing that thread out for me ( I must have overseen it when I used the search button - because I used it!)

But you must be bulls**ting me

hmm... Bullsting. What a great new made up word.

Quote from: mamarulez on Sat 29/01/2005 17:13:46with those 100 sprites. Hell no! If 100 sprites would follow the character it would prolly slow down as well anyways.

hmm...

I have another problem:

Something must be wrong with the way how AGS does mathcalculations, check this out:

Hmm... Nice accusation. I've made some of those before. Chances are that you're wrong...

Quote from: mamarulez on Sat 29/01/2005 17:13:46in rep_ex:

Code: ags

// Mix Green/Red Color for second line according to the health level!
		int RedValue;
		int GreenValue;
		int SupportingBlueValue = 20;
		int CharacterHealth = GetCharacterProperty (GetPlayerCharacter (), "Health");
		
		GreenValue = (2.55)*CharacterHealth;	// I also tried 255/100 or 51/20 what equals the same - 2.55 - still doesnot work!
		RedValue = (-2.55)*CharacterHealth) + 255;

Hmm... Let's see here: -2.55 * 100 = -255, -255 + 255 = 0.
      
Quote from: mamarulez on Sat 29/01/2005 17:13:46
Code: ags
		if (GreenValue < 0)
			GreenValue = 0;
		if (GreenValue > 255)
			GreenValue = 255;
			
		if (RedValue < 0)
			RedValue = 0;
		if (RedValue > 255)
			RedValue = 255;


Now when I plugin a value of 100 for the chars health in the properties, ags tells me, that GreenValue = 200 and Red = 0... It does strange things with the other values for Health and I had to build those boundaries in the last eight lines in to get it to work at all because other wise it would have returned me values over or under 0 or 255 for the RGB func.

What in the world is wrong?

Well, 2.55 * 100 does equal 255, so I don't know why it's saying that it's 200. But "Red = 0" is not a problem (unless you scripted it incorrectly). Also, try else-ifs:

Code: ags
if (GreenValue < 0) GreenValue = 0;
else if (GreenValue > 255) GreenValue = 255;
else {}

if (RedValue < 0) RedValue = 0;
else if (RedValue > 255) RedValue = 255;
else {}


I don't know if that would help, but it makes the code cleaner. But please, post your script and wait for reply before accusing AGS of being at fault...

strazer

#4
QuoteBut you must be bulls**ting me with those 100 sprites. Hell no! If 100 sprites would follow the character it would prolly slow down as well anyways.

What I meant was making a view consisting of 100 frames, one frame for each health bar percentage (1-100), then use additional characters using this view, setting them to the frame of this view based on the health of the character they're following.

But you're right, since you can only have 50 characters on the screen at the same time, it's probably not the best approach. Well, it was just an idea.

DoorKnobHandle

Thanks strazer, good work with that strategy game, too.

To monkey0506:
I'm sorry if I accused your holy AGS. No, seriously I was just trying to be funny, of course I am wrong I know that. I just cant mess with AGS' logic. But you shouldnt post yourself if you cannot give me any help except telling me not to do this dumb joke...
What your help is is "Well, 2.55 * 100 does equal 255, so I don't know why it's saying that it's 200.". Thank you.

Oh and the word is not bullsting. Keep on guessing if you have the time...

Pumaman

Woah woah, calm down people.

Anyway, your calculation problem is because (in 2.62 and earlier) AGS only supports integers. Therefore what you're actually getting is 2 * 100 which is 200.

Presuming you're trying to convert the health from a number out of 100 to a number out of 255, the solution is this:

GreenValue = (255 * CharacterHealth) / 100;



mystazsea

Yeah Strazer is right..the easiest way to do exactly what you wanted to do is what he said...USE A CHARACTER and a view or just

for example

1- make a new character and name it 'Playerhealth' or whatnot  and assign an animation view
2- also a Global Variable to it to keep track of the Health

3- make it follow the main unit...    eg:      cPlayerhealth.FollowCharacter("your unit here", FOLLOW_EXACTLY, 0);
(The eagerness value of either 0 or 1 will draw it in front or behind of your unit)

4- Then set its view or normal graphic to the starting full health bar
5-  On your Global variable change set the normal graphic of the "Playerhealth" character either by using          cPlayerhealth.Frame....this will change the frame of the view you made directly...
OR
use a separate view or LOOP of a view for each state change of your Global Variable


The principles are always the same...

Stop trying to look for shortcuts...
try to figure out what you need first ..
then PLAN IT ON PAPER...
then code it
and dont take shortcuts....
a robust syetem is always far better than a patch job

So PLAN it all out before you do any work on the engine..

take your time...

a good game is worth the work...
:)
Trousers on then put on shoes...

Atelier

^ This is over 7 years old.

Khris


SMF spam blocked by CleanTalk