External Exam Download Resources Web Applications Games Recycle Bin

AI2


Patrol

^^three objects, place each object in room once only. following GML code uses the word "points" in a location sense, not a scoring sense:

enemy Create:

globalvar points;

points[0,0] = marker0.x;
points[0,1] = marker0.y + 50;
points[1,0] = marker0.x + 50;
points[1,1] = marker0.y;
points[2,0] = marker1.x;
points[2,1] = marker1.y - 50;
points[3,0] = marker1.x - 50;
points[3,1] = marker1.y;

globalvar currentPoint;
currentPoint = 0;

image_angle = point_direction( x, y, points[currentPoint,0], points[currentPoint,1] );
move_towards_point( points[currentPoint,0], points[currentPoint,1], 3 );

enemy Step:

if (points[currentPoint,0] > x-10 and points[currentPoint,0] < x+10) {
  if (points[currentPoint,1] > y-10 and points[currentPoint,1] < y+10) {
    if (currentPoint == 3) {
      currentPoint = 0
    }
    else
    {
      currentPoint = currentPoint + 1
    }
    
    image_angle = point_direction( x, y, points[currentPoint,0], points[currentPoint,1] );
    move_towards_point( points[currentPoint,0], points[currentPoint,1], 3 );
    
  }  
}