Jump to content


Photo

Help with a Certain Healthbar engine


  • Please log in to reply
2 replies to this topic

#1 Vison

Vison

    GMC Member

  • New Member
  • 4 posts

Posted 28 November 2011 - 01:18 AM

Okay. So I used an idea for a healthbar from one of the resources available on the site. I got this thing for a script

/*
    draw_percentage_bar by alpha ex
    
    usage,
    
    draw_set_color(c_blue);
    draw_percentage_bar(10,10,100,15,value,value_max,true);
    
    use this on a draw event
    you first have to set the drawing color
    then, call this script to draw a bar in the previously set color
    
    also, if you use this on an object, in the draw event make sure you have this line,
    
        draw_sprite(sprite_index,image_index,x,y);
    
    this will redraw the sprite for the object removed by the draw event
*/

draw_sprite(sprite_index,image_index,x,y);

var x1, y1, x2, y2;
var width, height;
var value, value_max;
var color, backing;

//get arugments
x1 = argument0;
y1 = argument1;
width = argument2;
height = argument3;
value = argument4;
value_max = argument5;
backing = argument6;        //boolean

//get set draw color, should be set before calling function
color = draw_get_color();

//draw the backing
if (backing)
{
    draw_set_color(c_black);
    draw_rectangle(x1-1,y1-1,x1+width+1,y1+height+1,false);
}

//set values
x2 = x1 + (value/value_max * width);
y2 = y1 + height;

//main fill color
draw_set_color(color);
draw_rectangle(x1,y1,x2,y2,false);


Then I have this in the draw event of the player

//redraw the object's sprite
draw_sprite(sprite_index,image_index,x,y);

//draw a health bar
draw_set_color(c_aqua);
draw_percentage_bar(10,10,100,15,sheild,sheild_max,true);

//health highlights
draw_set_color(c_white);
draw_percentage_bar(10,10,100,2,sheild,sheild_max,false);
draw_set_color(c_blue);
draw_percentage_bar(10,23,100,2,sheild,sheild_max,false);

//draw a health bar
draw_set_color(c_lime);
draw_percentage_bar(10,30,100,15,hp,hp_max,true);

//health highlights
draw_set_color(c_white);
draw_percentage_bar(10,30,100,2,hp,hp_max,false);
draw_set_color(c_green);
draw_percentage_bar(10,43,100,2,hp,hp_max,false);

//draw an ammo bar
draw_set_color(c_red);
draw_percentage_bar(10,50,100,15,ammo,ammo_max,true);

//ammo highlights
draw_set_color(c_white);
draw_percentage_bar(10,50,100,2,ammo,ammo_max,false);
draw_set_color(c_maroon);
draw_percentage_bar(10,63,100,2,ammo,ammo_max,false);

What I'm trying to do is get the health,ammo,and armor bars to stay on screen but I don't know where to add the view_xview[0] and view_yview[0] thingies. I've only been using game maker for a little over a month and have barely any understanding of script/code so please be as clear as possible.
  • 0

#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5383 posts
  • Version:GM:Studio

Posted 28 November 2011 - 01:33 AM

since you use the script everywhere there, then you can simply put it in there so it affects all of them without having to change anything else .. I hope you see what part of the script this is:
// I removed draw_sprite that were here .. no reason to draw the thing that draw this every time you call the script

var x1, y1, x2, y2;
var width, height;
var value, value_max;
var color, backing;

//get arugments
x1 = view_xview[0]+argument0; // I added the view_xview here
y1 = view_yview[0]+argument1;
and that should be all you need to change

put this in the draw event before all the other
draw_sprite(sprite_index,image_index,x,y);

but, if you were using draw_healthbar or something like that, that didn't have any script, then you would have to do it something like this:
draw_percentage_bar(view_xview[0]+10,view_yview[0]+10,view_xview[0]+100,view_yview[0]+15,sheild,sheild_max, true);
to most of the lines .. adding view_x to both x cordinates and view_y to the y cordinate
  • 0

#3 Vison

Vison

    GMC Member

  • New Member
  • 4 posts

Posted 28 November 2011 - 02:08 AM

since you use the script everywhere there, then you can simply put it in there so it affects all of them without having to change anything else .. I hope you see what part of the script this is:

// I removed draw_sprite that were here .. no reason to draw the thing that draw this every time you call the script

var x1, y1, x2, y2;
var width, height;
var value, value_max;
var color, backing;

//get arugments
x1 = view_xview[0]+argument0; // I added the view_xview here
y1 = view_yview[0]+argument1;
and that should be all you need to change

put this in the draw event before all the other
draw_sprite(sprite_index,image_index,x,y);

but, if you were using draw_healthbar or something like that, that didn't have any script, then you would have to do it something like this:
draw_percentage_bar(view_xview[0]+10,view_yview[0]+10,view_xview[0]+100,view_yview[0]+15,sheild,sheild_max, true);
to most of the lines .. adding view_x to both x cordinates and view_y to the y cordinate



Thanks that worked perfectly.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users