settings, small fixes
This commit is contained in:
parent
b12c193636
commit
e08e3ebb13
174 changed files with 997 additions and 1040 deletions
62
scripts/enemy.gd
Normal file
62
scripts/enemy.gd
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class_name Enemy extends Entity
|
||||
|
||||
@export var attack_charge_time: float = 0.7
|
||||
@export var flee_range: float = 20.0
|
||||
@export var approach_range: float = 100.0
|
||||
|
||||
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
|
||||
@onready var sprite = $Anim
|
||||
|
||||
var current_charge: float = 0.0
|
||||
var target_node: Node2D
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("enemy")
|
||||
nav_agent.velocity_computed.connect(_on_velocity_computed)
|
||||
target_node = get_tree().get_first_node_in_group("player")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not target_node: return
|
||||
|
||||
nav_agent.target_position = target_node.global_position
|
||||
var dist = global_position.distance_to(target_node.global_position)
|
||||
var next_path_pos = nav_agent.get_next_path_position()
|
||||
var dir = global_position.direction_to(next_path_pos)
|
||||
|
||||
if dist > approach_range:
|
||||
velocity += dir * move_speed
|
||||
current_charge = 0
|
||||
elif dist < flee_range:
|
||||
velocity -= dir * move_speed
|
||||
current_charge = 0
|
||||
else:
|
||||
_handle_attack_charge(delta)
|
||||
|
||||
sprite.flip_h = target_node.global_position.x > global_position.x
|
||||
scale = Vector2.ONE * (1 + (current_charge * 0.2))
|
||||
|
||||
super._physics_process(delta)
|
||||
|
||||
func _handle_attack_charge(delta):
|
||||
current_charge += delta
|
||||
|
||||
if current_charge >= attack_charge_time:
|
||||
use_mask(target_node.global_position)
|
||||
current_charge = 0
|
||||
|
||||
func _on_velocity_computed(safe_vel: Vector2):
|
||||
velocity = safe_vel
|
||||
|
||||
func knockback():
|
||||
velocity += global_position.direction_to(nav_agent.target_position).normalized() * -2000
|
||||
|
||||
func die():
|
||||
var drop_scene := load("res://scenes/mask_drop.tscn")
|
||||
var drop : MaskDrop = drop_scene.instantiate()
|
||||
drop.mask_type = current_mask_data
|
||||
get_parent().add_child(drop)
|
||||
drop.global_position = global_position
|
||||
|
||||
EventBus.screenshake.emit(10)
|
||||
super.die()
|
||||
queue_free()
|
||||
Loading…
Add table
Add a link
Reference in a new issue