Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 17,340 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
creating and modifying panels #238162
11/25/08 08:55
11/25/08 08:55
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
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.

Last edited by PrenceOfDarkness; 11/25/08 22:15.

"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
Re: creating and modifying panels [Re: PrenceOfDarkness] #238221
11/25/08 19:54
11/25/08 19:54
Joined: Nov 2008
Posts: 24
Nevada, USA
Kevinper Offline
Newbie
Kevinper  Offline
Newbie

Joined: Nov 2008
Posts: 24
Nevada, USA
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?


Kevin
Re: creating and modifying panels [Re: Kevinper] #238245
11/25/08 22:14
11/25/08 22:14
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
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.


"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
Re: creating and modifying panels [Re: PrenceOfDarkness] #238247
11/25/08 22:22
11/25/08 22:22
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
malloc is not needed, and probably the problem.


3333333333
Re: creating and modifying panels [Re: Quad] #238248
11/25/08 22:24
11/25/08 22:24
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
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.


"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
Re: creating and modifying panels [Re: PrenceOfDarkness] #238250
11/25/08 22:28
11/25/08 22:28
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Can you show the actual code without malloc?


Click and join the 3dgs irc community!
Room: #3dgs
Re: creating and modifying panels [Re: PrenceOfDarkness] #238258
11/25/08 23:38
11/25/08 23:38
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
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


I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: creating and modifying panels [Re: heinekenbottle] #238413
11/27/08 03:04
11/27/08 03:04
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
sounds good let me try it your way.


"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1