fx: prey-predator interactions
This commit is contained in:
@@ -83,12 +83,9 @@ func _on_attack_hit(body: Node2D) -> void:
|
||||
if body.has_method("handle_damage"):
|
||||
body.handle_damage(damage, self)
|
||||
hit_hittable = true
|
||||
elif body.is_in_group("resources"):
|
||||
pass
|
||||
if hit_hittable:
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
sprite.play("default")
|
||||
# TODO: resource handling logic
|
||||
|
||||
func _on_invulnerable_cooldown_timeout() -> void:
|
||||
hasiframes = false
|
||||
|
||||
@@ -31,7 +31,6 @@ animations = [{
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5hxmy"]
|
||||
radius = 10.999997
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4flbx"]
|
||||
radius = 5.999982
|
||||
@@ -51,7 +50,7 @@ rotation = -1.5732701
|
||||
collision_mask = 6
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="AttackArea" unique_id=1968501358]
|
||||
position = Vector2(55.984985, 6.138512)
|
||||
position = Vector2(55.977566, 9.138502)
|
||||
shape = SubResource("CircleShape2D_5hxmy")
|
||||
debug_color = Color(0.80813414, 0.3957308, 0.3356335, 0.41960785)
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ func attack(target: Node) -> void:
|
||||
var hit_hittable = false
|
||||
if target.is_in_group("prey") or target.is_in_group("player"):
|
||||
if target.has_method("handle_damage"):
|
||||
target.handle_damage(damage, self)
|
||||
target.handle_damage(damage, self.collision)
|
||||
hit_hittable = true
|
||||
elif target.is_in_group("resources"):
|
||||
# TODO: resource handling logic
|
||||
|
||||
@@ -92,12 +92,12 @@ animations = [{
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="HammerheadPredator" type="Node" unique_id=1312337720 groups=["predator"]]
|
||||
[node name="HammerheadPredator" type="Node" unique_id=1312337720]
|
||||
script = ExtResource("1_xp037")
|
||||
maxHealth = 50
|
||||
metadata/_custom_type_script = "uid://dgfimmq53whll"
|
||||
|
||||
[node name="Collision" type="CharacterBody2D" parent="." unique_id=76553184]
|
||||
[node name="Collision" type="CharacterBody2D" parent="." unique_id=76553184 groups=["predator"]]
|
||||
scale = Vector2(0.8, 0.8)
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
|
||||
@@ -11,16 +11,16 @@ func enter(previous_state_path: String, data := {}) -> void:
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
if target == null or GameManager.calc_distance(owner.position, target.position) > owner.sight_range:
|
||||
if target == null or GameManager.calc_distance(owner.collision.position, target.position) > owner.sight_range:
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
return
|
||||
|
||||
# alternatively, we could use a collision shape and inbuilt signals, but im not sure if that works better (mixing signals and custom fsm stuff i mean
|
||||
if GameManager.calc_distance(owner.position, target.position) > owner.attack_range:
|
||||
if GameManager.calc_distance(owner.collision.position, target.position) > owner.attack_range:
|
||||
owner.move(move_towards(target.position))
|
||||
else:
|
||||
owner.attack(target)
|
||||
|
||||
func move_towards(pos: Vector2) -> Vector3:
|
||||
var diff = target.position - owner.position
|
||||
var diff = target.position - owner.collision.position
|
||||
return Vector3(diff.x, diff.y ,0)
|
||||
|
||||
@@ -18,6 +18,10 @@ func move(motion: Vector3, mod: float) -> void:
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
|
||||
func handle_damage(dmg: int, src: Node) -> void:
|
||||
if owner:
|
||||
owner.handle_damage(dmg, src)
|
||||
|
||||
func duplicate_init() -> void:
|
||||
var sight = $Sight
|
||||
remove_child(sight)
|
||||
|
||||
@@ -55,7 +55,7 @@ animations = [{
|
||||
script = ExtResource("2_0227s")
|
||||
maxHealth = 20
|
||||
|
||||
[node name="Collision" type="CharacterBody2D" parent="." index="0" unique_id=331517910]
|
||||
[node name="Collision" type="CharacterBody2D" parent="." index="0" unique_id=331517910 groups=["prey"]]
|
||||
scale = Vector2(0.2, 0.2)
|
||||
collision_layer = 2
|
||||
collision_mask = 5
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends State
|
||||
|
||||
var threat: Node2D
|
||||
var threat: Node
|
||||
var threshold: float = 100
|
||||
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
@@ -11,13 +11,12 @@ func enter(previous_state_path: String, data := {}) -> void:
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
if not is_instance_valid(threat) or GameManager.calc_distance(owner.position, threat.position) > threshold:
|
||||
if not is_instance_valid(threat) or GameManager.calc_distance(owner.collision.position, threat.position) > threshold:
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
return
|
||||
owner.move(flee_from(threat.position))
|
||||
|
||||
func flee_from(pos: Vector2) -> Vector3:
|
||||
# FIXME: What is the argument "pos" and why is it unused?
|
||||
var diff = threat.position - owner.position
|
||||
var diff = pos - owner.collision.position
|
||||
diff = diff.normalized() * -1
|
||||
return Vector3(diff.x, diff.y ,0)
|
||||
|
||||
Reference in New Issue
Block a user