creating and modifying panels

Posted By: PrenceOfDarkness

creating and modifying panels - 11/25/08 08:55

I'm trying to create healthbars for everything in my game. Here is the basic code below and it's simply not working. I added the malloc line because I wasn't sure if I needed to allocate memory for the panel. It didn't help the problem so I'm guessing the answer is no.

Code:
	var pHealthBar1 = 50;
	PANEL* myHPpanel = malloc(sizeof(HPpanel));
	myHPpanel = pan_create("flags = VISIBLE;window (0, 0, 100, 10, healthbar_bmp, pHealthBar1, 0);",4);
//	pan_setvar(myHPpanel,5,1.0,&pHealthBar1);
	pHealthBar1 = (100*(player.hplvl-pHealth)/player.hplvl);


I just thinking having health bars over every monster will look cool and it's killing me that I can't get this to work. Anyone have any ideas what's going on? The formula for the player health is right because when I define a panel in SED everything works right. Obviously I can't define 1000 health bars for every single possible monster, And I don't feel like just making 20 and having them all share. As a last resort I'll do that.
Posted By: Kevinper

Re: creating and modifying panels - 11/25/08 19:54

I am but a Newbie waiting for answers but I thought I would ask about a couple of things. Is that a comment line left of pan_setvar (//) and also is there supposed to be two semi-colons at the end?
Posted By: PrenceOfDarkness

Re: creating and modifying panels - 11/25/08 22:14

Yes that is a comment line and no thank you for catching that... but that wont solve the problem that was just bad pasting on my part.
Posted By: Quad

Re: creating and modifying panels - 11/25/08 22:22

malloc is not needed, and probably the problem.
Posted By: PrenceOfDarkness

Re: creating and modifying panels - 11/25/08 22:24

No I kind of thought it wasn't needed, and no it's not the problem. I tried the code with and without it before posting. The problem goes away when I assign a global variable to the panel being declayered. Anyone have any ideas.
Posted By: Joozey

Re: creating and modifying panels - 11/25/08 22:28

Can you show the actual code without malloc?
Posted By: heinekenbottle

Re: creating and modifying panels - 11/25/08 23:38

You want a health bar over a monster? You don't need malloc.

Code:
action eTank()
{
	PANEL* hPan;			//declare a panel pointer for the health bar
	VECTOR test;			//declare a vector to test if the smoke vector is visible
	VECTOR hSpot;			//declare a vector for the healthbar position
        ....//bunch of parameters and such that has nothing to do with the healthbar
	hPan = pan_create(NULL,9999);						//create a panel for the healthbar
	set(hPan,VISIBLE | LIGHT | TRANSLUCENT);		//set the panel's flags, visible, light and translucent
	hPan.alpha = 50;										//set its transparency to 50
	hPan.size_y = 10;	 												//make the y component a constant ten
	while(my.health > 0)
	{
		vec_set(hSpot,my.x);											//set hSpot to my position
		vec_to_screen(hSpot,camera);								//convert hSpot to screen coordinates
		hPan.pos_x = hSpot.x - (0.5 * (hPan.size_x));		//place the health panel so it is centered on the tank
		hPan.pos_y = hSpot.y - 40;
		hPan.size_x = 100 * (my.health / my.maxHealth);		//make the size dependant on the tank's % of health											
		vec_set(hPan.blue,vector(0,200,0));

                //the rest of the code
      }
 
}	



Simple explanation, I declared a local PANEL pointer called "hPan." This will be our panel. Then I declared a local vector called "hSpot" and this is the position of the panel.

Next, I set hPan to a pan_create instruction with no bmap and 9999 layer so it'd be on top, I'm going to use a color vector rather than a bitmap. Since I'm using color, I set LIGHT. I also want TRANSLUCENT and VISIBLE. I set alpha and y, before the while() loop as these two are constants.

Then, using vec_set, I copy the tank's position into hSpot. Using vec_to_screen, I convert hSpot to screen coordinates. Then I can use hSpot to position hPan and I set size_x to 100 * the tank's percentage of health.

The last line defines the color of the panel, making it green. (.blue can also be used to store a vector, it doesn't necessarily indicate blue color).

When the tank dies, I use reset to turn of the visible flag and then remove the panel with ptr_remove.

This works with multiple enemies
Posted By: PrenceOfDarkness

Re: creating and modifying panels - 11/27/08 03:04

sounds good let me try it your way.
© 2023 lite-C Forums