Ah, I see. The problem here is that the collision_line -function takes the following arguments:
Code:
collision_line( x1, y1, x2, y2, obj, prec, notme );
However your x2, y2 aren't exactly what they are supposed to be. To make a line to 300px in front of the ship (i.e. pointing at the direction of the ship) you should do something like this:
Code:
var forward_look_distance = 300;
var forward_x = x + lengthdir_x(forward_look_distance, direction);
var forward_y = y + lengthdir_y(forward_look_distance, direction);
forwardCollisionLine = collision_line(x, y, forward_x, forward_y, obj_boundary, false, false);
if(forwardCollisionLine != noone){
state = scr_ship_turn_left;
}
else if(forwardCollisionLine == noone){
state = scr_ship_fly;
}
The lengthdir_x/y -functions are pretty well explained in the manual, I suggest that you look them up. They are very useful in a lot of things.
Also, when debugging something like this, it usually is a good idea to visualize the problem. If you would have drawn a line using the values you put into your original collision_line(x1, y1, x2, y2) call, and had a similar draw_line(x1, y1, x2, y2) call in the draw event, you would have spotted that the line isn't where it is supposed to be.