| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- function enemy_flying_ai()
- {
- // 索敌
- var _target = noone;
- if instance_exists(oPlayer)
- if distance_to_object(oPlayer) < chase_range
- _target = oPlayer;
- // 行为逻辑
- if _target != noone
- {
- state = "CHASE";
- var _dir = point_direction(x, y, _target.x, _target.y);
-
- // 施加加速度
- x_spd += lengthdir_x(accel, _dir) * global.time_scale;
- y_spd += lengthdir_y(accel, _dir) * global.time_scale;
-
- // 面向处理
- facing = (x < _target.x) ? 1 : -1;
- }
- else
- {
- state = "IDLE";
- var _dist_to_spawn = point_distance(x, y, spawn_x, spawn_y);
-
- if (_dist_to_spawn > 5) {
- var _dir_home = point_direction(x, y, spawn_x, spawn_y);
- x_spd += lengthdir_x(accel * 0.5, _dir_home) * global.time_scale;
- y_spd += lengthdir_y(accel * 0.5, _dir_home) * global.time_scale;
- } else {
- // 接近出生点时,应用空气阻力让它停下
- x_spd = lerp(x_spd, 0, air_friction);
- y_spd = lerp(y_spd, 0, air_friction);
- }
- }
- // 3. 速度限制 (Clamp)
- var _current_spd = point_distance(0, 0, x_spd, y_spd);
- if (_current_spd > max_spd) {
- var _scale = max_spd / _current_spd;
- x_spd *= _scale;
- y_spd *= _scale;
- }
-
- // 4. 动画更新 (之前讨论的手动控制)
- set_sprite(sEnemyFlying_Fly);
- }
|