fkl;dsnak;l gjmbsdfjlabgscajmg njl,.bfnelkjqbgmf
This commit is contained in:
@@ -5,19 +5,21 @@ extends CharacterBody2D
|
||||
@export var FRICTION = 1500.0;
|
||||
@export var HP = 100;
|
||||
@export var DAMAGE = 10;
|
||||
@export var COOLDOWN = 2;
|
||||
@export var COOLDOWN = 1;
|
||||
|
||||
@onready var raycast = $RayCast2D;
|
||||
@onready var cooldown_timer = $CooldownTimer;
|
||||
@onready var sprite = $AnimatedSprite2D;
|
||||
|
||||
var player = null;
|
||||
var is_on_cooldown = false;
|
||||
var attacking = false;
|
||||
|
||||
func _ready():
|
||||
add_to_group("enemies");
|
||||
|
||||
func _physics_process(delta):
|
||||
if player == null:
|
||||
if player == null || !attacking:
|
||||
return
|
||||
|
||||
var vec_to_player = player.global_position - global_position;
|
||||
@@ -43,6 +45,7 @@ func take_damage(damage):
|
||||
kill();
|
||||
|
||||
func kill():
|
||||
emit_signal("is_killed");
|
||||
queue_free();
|
||||
|
||||
func set_player(p):
|
||||
@@ -50,3 +53,9 @@ func set_player(p):
|
||||
|
||||
func _on_cooldown_timer_timeout():
|
||||
is_on_cooldown = false;
|
||||
|
||||
func _on_area_2d_body_entered(body):
|
||||
if body.name == "Player":
|
||||
attacking = true;
|
||||
|
||||
signal is_killed()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c661br4lh30r8"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://c661br4lh30r8"]
|
||||
|
||||
[ext_resource type="Script" path="res://Enemies/basic_enemy.gd" id="1_5vi5k"]
|
||||
[ext_resource type="Texture2D" uid="uid://ds4uvvrcxoay1" path="res://Sprites/placeholder_enemy.png" id="1_o8nfm"]
|
||||
@@ -17,6 +17,9 @@ animations = [{
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_47nt3"]
|
||||
size = Vector2(41, 64)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_237ox"]
|
||||
radius = 390.185
|
||||
|
||||
[node name="BasicEnemy" type="CharacterBody2D"]
|
||||
script = ExtResource("1_5vi5k")
|
||||
|
||||
@@ -38,4 +41,12 @@ default_color = Color(1, 0, 0, 0.392157)
|
||||
|
||||
[node name="CooldownTimer" type="Timer" parent="."]
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource("CircleShape2D_237ox")
|
||||
|
||||
[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
|
||||
Reference in New Issue
Block a user