Game Maker: Studio - Ship AI

///Movement AI //Misc image_angle = direction; //Set speed speed = moveSpeed + accel; //animation if (accel > 0){ image_index = 1; }else{ image_index = 0; } //random presses if (left==0 && right==0 && canTurn){ if (irandom_range(0,6)==2){ left = 1; //Trigger Left alarm[0] = random_range(10,30); //unTrigger } else if (irandom_range(0,6)==3){ right = 1; //Trigger Right alarm[0] = random_range(10,30); //unTrigger } } if (up==0 && down==0){ if (irandom_range(0,6)==2){ up = 1; //Trigger speedup audio_play_sound_at(snd_launch, ((view_xview + view_wview/2)-x), ((view_yview + view_hview/2)-y), 0, 100, 300, 1, false, 7); alarm[1] = random_range(20,90); } else if (irandom_range(0,6)==3){ down = 1; //Trigger slowdown alarm[1] = random_range(5,20); } } //Control functions (if triggered) if (up){ //UP if (accel < topSpeed - moveSpeed) accel += accelSpeed / 10; } else if (down){ //DOWN if (accel > -topSpeed / 5) accel -= accelSpeed / 20; } else{ //ELSE accel = 0; } if (left){ //LEFT if (turn < 3) turn += turnSpeed / 50; direction += turnSpeed + turn; } else if (right){ //RIGHT if (turn < 3) turn += turnSpeed / 50; direction -= turnSpeed + turn; } else{ //ELSE turn = 0; } ///Turret AI dir += random_range(-8, 10); image_angle = direction; //aim if (instance_exists(obj_playership) && distance_to_object(obj_playership) < 200){ closeFoe = obj_playership; } else { closeFoe = collision_circle(x, y, 500, obj_CPturret1, false, true); } if (distance_to_object(closeFoe) < 300 && closeFoe!=parentShip.id){ direction = point_direction(x, y, closeFoe.x, closeFoe.y) + random_range(-10/difLevel, 10/difLevel); if (irandom_range(0, 24/difLevel)==2){ event_user(0); //Shoot } }else{ direction = dir + random_range(-2, 5); }
There you go.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.