function enemy_hex_ai()
{	
	roll_spd = clamp(roll_spd, -20, 20);
	switch(state)
	{
		case "IDLE":
			enemy_roll_init();
			break;
			
		case "ROLL":
		
			rebounce_timer--;
			
			var _roll_spd;
			roll_angle *= global.time_scale;
			
			if abs(roll_angle + roll_spd) >= 60
				_roll_spd = (60 - abs(roll_angle)) * sign(roll_angle);
				
			else if sign(roll_angle) == -sign(roll_angle + roll_spd)
				_roll_spd = -roll_angle;
				
			else
				_roll_spd = roll_spd;
			
			if collision_line(x, y, x + 40 * sign(-_roll_spd), y, oParentSolid, false, false) != noone
			&& rebounce_timer <= 0
			{
				roll_spd *= -1;
				rebounce_timer = 10;
				
				roll_acc *= -1;
			}
			roll_spd += roll_acc;
			
			if abs(roll_angle) == 60 || roll_angle == 0
			{
				roll_angle = 0;
				y = base_y;
					
				var _base_angle = (roll_spd > 0) ? 240 : 300;
				pivot_x = x + lengthdir_x(side_len, _base_angle);
				pivot_y = y + lengthdir_y(side_len, _base_angle);
			}
			
			roll_angle += _roll_spd;
			image_angle += _roll_spd;
			
			var _current_angle = point_direction(pivot_x, pivot_y, x, y);
			var _new_angle = _current_angle + _roll_spd;
	
			x = pivot_x + lengthdir_x(side_len, _new_angle);
			y = pivot_y + lengthdir_y(side_len, _new_angle);
			
			break;
			
		case "SPAWN":
		
			image_angle += abs(y_spd) * global.time_scale;
			x += x_spd * global.time_scale;
			y += y_spd * global.time_scale;
			
			if y_spd == 15
			{
				x_spd = 0;
				y_spd = 0;
				y_acc = 0;
				state = "IDLE";
			}
			y_spd += y_acc;
			break;
	}
}
function enemy_roll_init()
{
    state = "ROLL";
	roll_spd = 5 * choose(-1, 1);
	roll_acc = -0.1 * sign(roll_spd);

    var _base_angle = (roll_spd > 0) ? 240 : 300;
    pivot_x = x + lengthdir_x(side_len, _base_angle);
    pivot_y = y + lengthdir_y(side_len, _base_angle);
}
function enemy_spawn_init()
{
	y_spd = -15;
	x_spd = sign(global.player.x - x) * random_range(10, 15);
	
	y_acc = 0.6;
	
	state = "SPAWN";
}