How to display health above a player?

Posted By: PeterM

How to display health above a player? - 06/28/07 11:01

How can i display players health or damage above his head?

i mean like this:


this image shows damage that has been done to the monster...
Posted By: tompo

Re: How to display health above a player? - 06/28/07 11:43

Try something like this: (not tested)
while(1)
{
vec_set(temp,monster.pos);
vec_to_screen(temp,camera);
panel.pos_x = temp.x - (panel.size_x /2); //to be at center
panel.pos_y = temp.y - 50; //play with this value to place panel above entity
wait(1);
}
Posted By: PeterM

Re: How to display health above a player? - 06/28/07 13:40

not exactly what i wanted but tnx anyway it works nice.

New question.
how can i copy my pannel?
i drew a picture so i can explain easier what i want.



screen has ICON 1, ICON 2 and so on.
now i want that this icons are icon_enemy panels.
So when I click on icon 1 or icon 2 I call SUM_ENEMY();


I hope you understand what i mean

Thank you.
Posted By: vlau

Re: How to display health above a player? - 06/28/07 14:37

For your 2nd question, you can write the code like this :

Code:

panel icon1
{
pos_x = 5;
pos_y = 10;
bmap = enemyBmap;
on_click = sum_enenmy;
}




I don't understand what you mean "copy panel", maybe you can write
your code like this :

PANEL* icon2;

panel icon1
{
//... define elements of icon1
}

icon2 = icon1;

EDIT
----
I've modified some codes.


Posted By: PeterM

Re: How to display health above a player? - 06/28/07 17:51

yes thats what i mean but it doesnt work.
This is what I did...
Code:
 

PANEL* icon1;
PANEL* icon2;

panel icon_enemy
{
bmap=i_enemy;
pos_x=10;
pos_y=10;
layer=11;
on_click=summon_enemy;
flags = overlay, refresh;

}




then I copyed icon_enemy panel in icon1 and 2 like this.
Code:
  

if (i==0)
{
icon1=icon_enemy;

icon1.pos_x=main_slot2_pan.pos_x+16;
icon1.pos_y=main_slot2_pan.pos_y+17;
icon1.visible=on;
icons[i]=1;
}

if (i==1)
{
icon2=icon_enemy;

icon2.pos_x=main_slot3_pan.pos_x+16;
icon2.pos_y=main_slot3_pan.pos_y+17;
icon2.visible=on;
icons[i]=1;
}




So now first i=0 so it copys panel to icon1 and sets icon1 position.
Then i=1 and copys panel to icon2 and sets icon2 position and suddenly
icon1 dissaperes. which i dont want i want both icon1 and icon2
to be visible, and when i click on them they both have to call the same function.

Tnx for your help.
Posted By: tompo

Re: How to display health above a player? - 06/28/07 18:35

You want to have panel over each entity? or what?
if yes... not easyer is do this by pan_create in every entity's action?
Posted By: dennis

Re: How to display health above a player? - 06/28/07 18:38

Hi PeterM!

For positioning the health above the player you can also use the position near the head of tht player instead of his origin...

(Using vec_for_vertex)

You will probably have to subtract a bit, too. However it will be more accurate.
Posted By: PeterM

Re: How to display health above a player? - 06/28/07 19:05

tompo yes i was thinking of something like that but pan_create
takes only bmap and layer like in example:

Splash = pan_create("bmap = splash.pcx;",1);

but i want the panel to have an on_click option to.

Oh never mind i just figured it out that i can do this...
icon1=pan_create("bmap=i_enemy; on_click=summon_enemy;",11);

tnx for your help tompo
© 2024 lite-C Forums