0 registered members (),
17,416
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
creating and modifying panels
#238162
11/25/08 08:55
11/25/08 08:55
|
Joined: Aug 2004
Posts: 1,305 New York
PrenceOfDarkness
OP
Serious User
|
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.
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
Newbie
|
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
OP
Serious User
|
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: Quad]
#238248
11/25/08 22:24
11/25/08 22:24
|
Joined: Aug 2004
Posts: 1,305 New York
PrenceOfDarkness
OP
Serious User
|
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]
#238258
11/25/08 23:38
11/25/08 23:38
|
Joined: Oct 2008
Posts: 218 Nashua NH
heinekenbottle
Member
|
Member
Joined: Oct 2008
Posts: 218
Nashua NH
|
You want a health bar over a monster? You don't need malloc.
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
|
|
|
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
OP
Serious User
|
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.
|
|
|
|