function hex_ai()
{	
	switch(state)
	{
		case "IDLE":
			if oMain._up
				roll_init();
			break;
			
		case "ROLL":
		
			rebounce_timer--;
			roll_spd += roll_acc;
			
			var _roll_spd;
			
			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;
				
			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);
			
			if collision_line(x, y, x + 128 * sign(-roll_spd), y, oParentSolid, false, false) != noone
			&& rebounce_timer <= 0
			{
				roll_acc *= -1;
				roll_spd *= -1;
				rebounce_timer = 60;
				//state = "RETRACE";
			}
			else if abs(roll_angle) >= 60 || roll_angle == 0
			{
				roll_angle = 0;
					
				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);
			}
			break;
			
		case "RETRACE":
			//roll_spd += roll_acc;
			
			break;
	}
}
function roll_init()
{
    state = "ROLL";
	roll_spd = 5;
	roll_acc = -0.1;

    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);
}