Circular Healthbar

Credit: Gizmo199

function draw_healthbar_circular(_x, _y, _radius, _amount, _backcol, _mincol, _maxcol, _direction, _showback, _thickness)
{
	// Get our color
	var _r1, _r2, _g1, _g2, _b1, _b2;
	
	_r1 = color_get_red(_maxcol);
	_g1 = color_get_green(_maxcol);
	_b1 = color_get_blue(_maxcol);
	
	_r2 = color_get_red(_mincol);
	_g2 = color_get_green(_mincol);
	_b2 = color_get_blue(_mincol);
	
	// Calculate the difference between each color channel
	var _rVal = _r2 + (((_r1 - _r2) * _amount) / 100);
	var _gVal = _g2 + (((_g1 - _g2) * _amount) / 100);
	var _bVal = _b2 + (((_b1 - _b2) * _amount) / 100);
	
	var _col = make_color_rgb(_rVal, _gVal, _bVal);
	
	// Draw our circular healtbar
	draw_set_color(_backcol);
	
	for(var i = 0; i < 360; i++)
	{
		// get rotation
		var _ldx = lengthdir_x(_radius, _direction + i);
		var _ldy = lengthdir_y(_radius, _direction + i);
		
		var _ldx2 = lengthdir_x(_radius + _thickness, _direction + i);
		var _ldy2 = lengthdir_y(_radius + _thickness, _direction + i);
		
		// Back ring
		if (_showback)
		{
			draw_line(_x + _ldx, _y + _ldy, _x + _ldx2, _y + _ldy2);
		}
		
		// Default is set to 100 as the maximum percentage to calculate
		var _percent = 100;
		var _val = ( _amount * 360 ) / _percent;
		
		// health ring
		if ((360 - _val) <= i)
		{
			draw_set_color(_col);
			draw_line(_x + _ldx, _y + _ldy, _x + _ldx2, _y + _ldy2);
		}
	}
}

Usage

draw_healthbar_circular(x, y, radius, amount, backcol, mincol, maxcol, direction, showback, showborder, thickness)


For drawing general circular healthbars, meters, etc.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s