mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-23 20:12:30 +08:00
refactor: 替换PresetAIs为PresetBulletAI,优化子弹AI逻辑
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
class_name PresetAIs
|
||||
class_name PresetBulletAI
|
||||
|
||||
static func lockLauncher(bullet: BulletBase, launcher: EntityBase, onTexture: bool = false):
|
||||
bullet.position = launcher.texture.global_position if onTexture else launcher.position
|
||||
@@ -0,0 +1,10 @@
|
||||
class_name PresetEntityAI
|
||||
|
||||
static func follow(entity: EntityBase, target: EntityBase, minDistance: float = 100):
|
||||
var delta = target.position - entity.position
|
||||
var distanceOffset = abs(delta.length() - minDistance)
|
||||
if distanceOffset > entity.fields[FieldStore.Entity.MOVEMENT_SPEED] * 10:
|
||||
if delta.length() < minDistance:
|
||||
entity.move(-delta)
|
||||
else:
|
||||
entity.move(delta)
|
||||
@@ -5,4 +5,4 @@ func register():
|
||||
penerate = 1
|
||||
func ai():
|
||||
rotation_degrees += 1
|
||||
PresetAIs.lockLauncher(self, launcher, true)
|
||||
PresetBulletAI.lockLauncher(self, launcher, true)
|
||||
|
||||
@@ -6,7 +6,7 @@ func register():
|
||||
damage = 20
|
||||
penerate = 1
|
||||
func ai():
|
||||
PresetAIs.lockLauncher(self, launcher, true)
|
||||
PresetBulletAI.lockLauncher(self, launcher, true)
|
||||
if !launcher.sprinting:
|
||||
tryDestroy()
|
||||
func destroy(beacuseMap: bool):
|
||||
|
||||
@@ -7,6 +7,6 @@ func register():
|
||||
damage = 2
|
||||
func ai():
|
||||
canDamageSelf = !(timeLived() >= traceTime)
|
||||
PresetAIs.forward(self, rotation)
|
||||
PresetBulletAI.forward(self, rotation)
|
||||
if timeLived() < traceTime:
|
||||
PresetAIs.trace(self, launcher.currentFocusedBoss.getTrackingAnchor(), 0.05)
|
||||
PresetBulletAI.trace(self, launcher.currentFocusedBoss.getTrackingAnchor(), 0.05)
|
||||
|
||||
@@ -6,4 +6,4 @@ func register():
|
||||
damage = 5
|
||||
|
||||
func ai():
|
||||
PresetAIs.forward(self, rotation)
|
||||
PresetBulletAI.forward(self, rotation)
|
||||
|
||||
@@ -11,7 +11,7 @@ func ai():
|
||||
speed *= 1.05
|
||||
speed = clamp(speed, 0, 20)
|
||||
if is_instance_valid(tracer) and timeLived() < maxTraceTime:
|
||||
PresetAIs.trace(self, tracer.getTrackingAnchor(), clamp(speed / 50 * tracePower, 0, 1))
|
||||
PresetAIs.forward(self, rotation)
|
||||
PresetBulletAI.trace(self, tracer.getTrackingAnchor(), clamp(speed / 50 * tracePower, 0, 1))
|
||||
PresetBulletAI.forward(self, rotation)
|
||||
func destroy(_b):
|
||||
EffectController.create(preload("res://components/Effects/LGBTBoom.tscn"), position).shot()
|
||||
|
||||
@@ -2,7 +2,7 @@ extends BulletBase
|
||||
class_name PurpleCrystal
|
||||
|
||||
func ai():
|
||||
PresetAIs.forward(self, rotation)
|
||||
PresetBulletAI.forward(self, rotation)
|
||||
func destroy(_beacuseMap: bool):
|
||||
var eff = EffectController.create(preload("res://components/Effects/PurpleCrystalExplosion.tscn"), global_position)
|
||||
eff.rotation = rotation
|
||||
|
||||
@@ -4,4 +4,4 @@ class_name Star
|
||||
func register():
|
||||
damage = 5
|
||||
func ai():
|
||||
PresetAIs.forward(self, rotation)
|
||||
PresetBulletAI.forward(self, rotation)
|
||||
|
||||
@@ -9,7 +9,7 @@ var rotateSpeed: float = 1
|
||||
func ai():
|
||||
texture.rotation_degrees += rotateSpeed
|
||||
rotateSpeed += 0.25
|
||||
PresetAIs.forward(self, rotation)
|
||||
PresetBulletAI.forward(self, rotation)
|
||||
if timeLived() <= forwardTime:
|
||||
speed = 10 * ((forwardTime - timeLived()) / forwardTime)
|
||||
elif forwarded:
|
||||
|
||||
@@ -17,7 +17,7 @@ func spawn():
|
||||
texture.play("walk")
|
||||
|
||||
func ai():
|
||||
move(currentFocusedBoss.position - position)
|
||||
PresetEntityAI.follow(self, currentFocusedBoss, 0)
|
||||
if currentFocusedBoss.position.distance_to(position) < 200:
|
||||
tryAttack(2)
|
||||
elif currentFocusedBoss.position.distance_to(position) < 700:
|
||||
|
||||
@@ -8,7 +8,7 @@ func register():
|
||||
|
||||
func ai():
|
||||
attackCooldownMap[0] = randi_range(1500, 4000)
|
||||
move(currentFocusedBoss.position - position)
|
||||
PresetEntityAI.follow(self, currentFocusedBoss, 300)
|
||||
tryAttack(0)
|
||||
func attack(type):
|
||||
if type == 0:
|
||||
|
||||
@@ -62,9 +62,9 @@ func _physics_process(_delta: float) -> void:
|
||||
var targetEntity = EntityTool.findClosetEntity(position, get_tree(),
|
||||
!launcher.isPlayer(),
|
||||
launcher.isPlayer(),
|
||||
[launcher] )
|
||||
[launcher])
|
||||
if is_instance_valid(targetEntity):
|
||||
PresetAIs.trace(
|
||||
PresetBulletAI.trace(
|
||||
self,
|
||||
targetEntity.getTrackingAnchor(),
|
||||
launcher.fields.get(FieldStore.Entity.BULLET_TRACE) / 10
|
||||
|
||||
@@ -15,3 +15,14 @@ static func percent(value: float):
|
||||
return value / 100
|
||||
static func shrimpRate(value: float):
|
||||
return floor(value) + int(rate(value - floor(value)))
|
||||
static func getClosestIntersection(a: Vector2, b: Vector2, r: float) -> Vector2:
|
||||
var ab = b - a
|
||||
var distance = ab.length()
|
||||
if distance < 0.00001:
|
||||
return a + Vector2.RIGHT * r
|
||||
var abNormalized = ab / distance
|
||||
var distanceB = distance
|
||||
if distanceB <= r:
|
||||
return b
|
||||
var intersection = a + abNormalized * r
|
||||
return intersection
|
||||
|
||||
Reference in New Issue
Block a user