Added Map; Added Spawners; Changed Decorations; Cleaned up Code and some Settings; Added Enemy
This commit is contained in:
parent
e82438139f
commit
e18beb6c4c
160 changed files with 4674 additions and 182 deletions
98
scenes/game/entities/Enemy/enemy.gd
Normal file
98
scenes/game/entities/Enemy/enemy.gd
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
extends "res://scenes/game/entities/entity.gd"
|
||||
|
||||
@export_range(1,10) var damage = 1
|
||||
@export_range(0.1,1) var attackCooldown = 1
|
||||
|
||||
@onready var navigationAgent = $NavigationAgent
|
||||
@onready var targetRaycast = $Radius/RayCast2D
|
||||
@onready var attackCooldownTimer = $AttackCooldown
|
||||
|
||||
@onready var damageArea = $DamageArea
|
||||
|
||||
@onready var focusedPlayer = null
|
||||
|
||||
func focusPlayer(player):
|
||||
focusedPlayer = player
|
||||
|
||||
func unfocusPlayer():
|
||||
focusedPlayer = null
|
||||
|
||||
func _ready() -> void:
|
||||
navigationAgent.velocity_computed.connect(Callable(_on_navigation_agent_velocity_computed))
|
||||
|
||||
func set_movement_target(movement_target: Vector2):
|
||||
navigationAgent.set_target_position(movement_target)
|
||||
|
||||
func moveTowardsPlayer():
|
||||
if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
|
||||
navigationAgent.target_position = focusedPlayer.global_position
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if focusedPlayer != null:
|
||||
#targetRaycast.target_position = focusedPlayer.global_position - global_position
|
||||
if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
|
||||
navigationAgent.target_position = focusedPlayer.global_position
|
||||
if focusedPlayer != null:
|
||||
targetRaycast.target_position = focusedPlayer.global_position - global_position
|
||||
else:
|
||||
targetRaycast.target_position = Vector2(global_position.x-1000,global_position.y-1000)
|
||||
#if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
|
||||
# navigationAgent.target_position = focusedPlayer.global_position
|
||||
#if global_position.distance_squared_to(focusedPlayer.global_position) > speed *10:
|
||||
|
||||
#moveTowardsPlayer()
|
||||
var currentAgentPosition = global_position
|
||||
|
||||
|
||||
if NavigationServer2D.map_get_iteration_id(navigationAgent.get_navigation_map()) == 0:
|
||||
return
|
||||
if navigationAgent.is_navigation_finished():
|
||||
return
|
||||
|
||||
var nextPathPosition = navigationAgent.get_next_path_position()
|
||||
var newVelocity = currentAgentPosition.direction_to(nextPathPosition)
|
||||
if navigationAgent.avoidance_enabled:
|
||||
navigationAgent.set_velocity(newVelocity * speed)
|
||||
else:
|
||||
_on_navigation_agent_velocity_computed(newVelocity)
|
||||
|
||||
|
||||
func _on_navigation_agent_velocity_computed(safe_velocity: Vector2) -> void:
|
||||
|
||||
velocity = safe_velocity
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func _on_radius_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("Player"):
|
||||
focusPlayer(body)
|
||||
|
||||
|
||||
func _on_radius_body_exited(body: Node2D) -> void:
|
||||
|
||||
if body.is_in_group("Player"):
|
||||
unfocusPlayer()
|
||||
|
||||
func attack():
|
||||
damageArea.attack(damage)
|
||||
|
||||
|
||||
func _on_damage_area_area_entered(area: Area2D) -> void:
|
||||
attackCooldownTimer.start(attackCooldown)
|
||||
|
||||
|
||||
|
||||
func _on_attack_cooldown_timeout() -> void:
|
||||
attack()
|
||||
attackCooldownTimer.start(attackCooldown)
|
||||
|
||||
|
||||
func _on_damage_area_area_exited(area: Area2D) -> void:
|
||||
#attackCooldownTimer.time_left = attackCooldown
|
||||
attackCooldownTimer.stop()
|
||||
|
||||
#func _on_ray_cast_2d_draw() -> void:
|
||||
#if focusedPlayer != null:
|
||||
##targetRaycast.target_position = focusedPlayer.global_position - global_position
|
||||
#if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
|
||||
#navigationAgent.target_position = focusedPlayer.global_position
|
||||
91
scenes/game/entities/Enemy/enemy.tscn
Normal file
91
scenes/game/entities/Enemy/enemy.tscn
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://bnxx7nnifjica"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b18cf4i8v6a1" path="res://scenes/game/entities/entity.tscn" id="1_bf5v6"]
|
||||
[ext_resource type="Script" path="res://scenes/game/entities/Enemy/enemy.gd" id="2_4vapd"]
|
||||
[ext_resource type="Texture2D" uid="uid://dh14dje1066et" path="res://icon.svg" id="3_jenk6"]
|
||||
[ext_resource type="PackedScene" uid="uid://cwirujaquehfc" path="res://scenes/game/Hitbox/damage_area.tscn" id="4_mr72k"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_xq7op"]
|
||||
radius = 8.0
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_c882v"]
|
||||
light_mode = 2
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rdbks"]
|
||||
atlas = ExtResource("3_jenk6")
|
||||
region = Rect2(0, 0, 128, 128)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_i6h2x"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_rdbks")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_w20ih"]
|
||||
radius = 128.0
|
||||
height = 384.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_eto3a"]
|
||||
radius = 16.0
|
||||
|
||||
[node name="Enemy" groups=["Enemy"] instance=ExtResource("1_bf5v6")]
|
||||
collision_layer = 2560
|
||||
script = ExtResource("2_4vapd")
|
||||
damage = 1
|
||||
attackCooldown = 1
|
||||
normalSpeed = 80
|
||||
|
||||
[node name="CollisionShape2D" parent="." index="0"]
|
||||
shape = SubResource("CircleShape2D_xq7op")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="1"]
|
||||
material = SubResource("CanvasItemMaterial_c882v")
|
||||
position = Vector2(2.38419e-07, 2.38419e-07)
|
||||
scale = Vector2(0.125, 0.125)
|
||||
sprite_frames = SubResource("SpriteFrames_i6h2x")
|
||||
|
||||
[node name="NavigationAgent" type="NavigationAgent2D" parent="." index="2"]
|
||||
path_postprocessing = 1
|
||||
simplify_path = true
|
||||
avoidance_enabled = true
|
||||
avoidance_layers = 2560
|
||||
avoidance_mask = 3630
|
||||
debug_enabled = true
|
||||
debug_use_custom = true
|
||||
debug_path_custom_color = Color(1, 0, 0, 1)
|
||||
|
||||
[node name="Radius" type="Area2D" parent="." index="3" groups=["Enemy"]]
|
||||
collision_layer = 3687
|
||||
collision_mask = 1024
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Radius" index="0"]
|
||||
rotation = -1.57079
|
||||
shape = SubResource("CapsuleShape2D_w20ih")
|
||||
|
||||
[node name="RayCast2D" type="RayCast2D" parent="Radius" index="1"]
|
||||
target_position = Vector2(-12.48, 16)
|
||||
collision_mask = 14
|
||||
hit_from_inside = true
|
||||
|
||||
[node name="DamageArea" parent="." index="4" instance=ExtResource("4_mr72k")]
|
||||
|
||||
[node name="CollisionShape2D" parent="DamageArea" index="0"]
|
||||
shape = SubResource("CircleShape2D_eto3a")
|
||||
|
||||
[node name="AttackCooldown" type="Timer" parent="." index="5"]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="velocity_computed" from="NavigationAgent" to="." method="_on_navigation_agent_velocity_computed"]
|
||||
[connection signal="body_entered" from="Radius" to="." method="_on_radius_body_entered"]
|
||||
[connection signal="body_exited" from="Radius" to="." method="_on_radius_body_exited"]
|
||||
[connection signal="draw" from="Radius/RayCast2D" to="." method="_on_ray_cast_2d_draw"]
|
||||
[connection signal="area_entered" from="DamageArea" to="." method="_on_damage_area_area_entered"]
|
||||
[connection signal="area_exited" from="DamageArea" to="." method="_on_damage_area_area_exited"]
|
||||
[connection signal="timeout" from="AttackCooldown" to="." method="_on_attack_cooldown_timeout"]
|
||||
|
||||
[editable path="DamageArea"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue