Various changes.
This commit is contained in:
parent
fe97f5e46b
commit
5edf4e654e
|
@ -1,23 +1,13 @@
|
||||||
[gd_resource type="Resource" script_class="Item" load_steps=6 format=3 uid="uid://ed64yksg1y6m"]
|
[gd_resource type="Resource" script_class="Item" load_steps=4 format=3 uid="uid://ed64yksg1y6m"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://kcdpck5ufgcc" path="res://scripts/item.gd" id="1_5qyf8"]
|
[ext_resource type="Script" uid="uid://kcdpck5ufgcc" path="res://scripts/item.gd" id="1_5qyf8"]
|
||||||
[ext_resource type="Texture2D" uid="uid://denfapnjlvmku" path="res://assets/images/bullet.png" id="1_ubihn"]
|
[ext_resource type="ArrayMesh" uid="uid://btvngn040dnbb" path="res://assets/models/Bullets.obj" id="1_ubihn"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5qyf8"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_5qyf8"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5qyf8"]
|
|
||||||
transparency = 2
|
|
||||||
alpha_scissor_threshold = 0.5
|
|
||||||
alpha_antialiasing_mode = 0
|
|
||||||
albedo_texture = ExtResource("1_ubihn")
|
|
||||||
billboard_mode = 2
|
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_ubihn"]
|
|
||||||
material = SubResource("StandardMaterial3D_5qyf8")
|
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_5qyf8")
|
script = ExtResource("1_5qyf8")
|
||||||
icon = SubResource("AtlasTexture_5qyf8")
|
icon = SubResource("AtlasTexture_5qyf8")
|
||||||
name = "Bullets"
|
name = "Bullets"
|
||||||
model = SubResource("QuadMesh_ubihn")
|
model = ExtResource("1_ubihn")
|
||||||
metadata/_custom_type_script = "uid://kcdpck5ufgcc"
|
metadata/_custom_type_script = "uid://kcdpck5ufgcc"
|
||||||
|
|
105
node_3d.tscn
105
node_3d.tscn
File diff suppressed because one or more lines are too long
|
@ -19,6 +19,8 @@ size = Vector2(2, 2)
|
||||||
orientation = 1
|
orientation = 1
|
||||||
|
|
||||||
[node name="Building" type="StaticBody3D"]
|
[node name="Building" type="StaticBody3D"]
|
||||||
|
collision_layer = 2
|
||||||
|
collision_mask = 15
|
||||||
script = ExtResource("1_k07no")
|
script = ExtResource("1_k07no")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
@ -28,6 +30,7 @@ mesh = SubResource("BoxMesh_cee1v")
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
shape = SubResource("BoxShape3D_k07no")
|
shape = SubResource("BoxShape3D_k07no")
|
||||||
|
disabled = true
|
||||||
|
|
||||||
[node name="NavObstacle" type="Node3D" parent="."]
|
[node name="NavObstacle" type="Node3D" parent="."]
|
||||||
script = ExtResource("2_0gk2u")
|
script = ExtResource("2_0gk2u")
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
[sub_resource type="Curve3D" id="Curve3D_r3fl7"]
|
[sub_resource type="Curve3D" id="Curve3D_r3fl7"]
|
||||||
_data = {
|
_data = {
|
||||||
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3),
|
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2),
|
||||||
"tilts": PackedFloat32Array(0, 0)
|
"tilts": PackedFloat32Array(0, 0)
|
||||||
}
|
}
|
||||||
point_count = 2
|
point_count = 2
|
||||||
|
|
|
@ -1,18 +1,51 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://cw3vtaevqx20y"]
|
[gd_scene load_steps=8 format=3 uid="uid://cw3vtaevqx20y"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://b1fnsl3k1mo5c" path="res://objects/buildings/building.tscn" id="1_cgb0l"]
|
[ext_resource type="PackedScene" uid="uid://b1fnsl3k1mo5c" path="res://objects/buildings/building.tscn" id="1_cgb0l"]
|
||||||
[ext_resource type="Script" uid="uid://bl78fqp1abxd6" path="res://scripts/buildings/turret.gd" id="2_brx0q"]
|
[ext_resource type="Script" uid="uid://bl78fqp1abxd6" path="res://scripts/buildings/turret.gd" id="2_brx0q"]
|
||||||
[ext_resource type="Script" uid="uid://bshiyw2k3op02" path="res://scripts/building_components/consumer.gd" id="2_wh3b5"]
|
[ext_resource type="Script" uid="uid://bshiyw2k3op02" path="res://scripts/building_components/consumer.gd" id="2_wh3b5"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cav22qho14o47" path="res://objects/bullet.tscn" id="3_kpsgq"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cgb0l"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cgb0l"]
|
||||||
albedo_color = Color(0, 0.00397563, 1, 1)
|
albedo_color = Color(0, 0.00397563, 1, 1)
|
||||||
|
|
||||||
|
[sub_resource type="CylinderMesh" id="CylinderMesh_kpsgq"]
|
||||||
|
material = SubResource("StandardMaterial3D_cgb0l")
|
||||||
|
top_radius = 1.0
|
||||||
|
bottom_radius = 1.0
|
||||||
|
height = 0.5
|
||||||
|
radial_segments = 16
|
||||||
|
rings = 0
|
||||||
|
|
||||||
|
[sub_resource type="CylinderMesh" id="CylinderMesh_vuktq"]
|
||||||
|
material = SubResource("StandardMaterial3D_cgb0l")
|
||||||
|
top_radius = 0.2
|
||||||
|
bottom_radius = 0.25
|
||||||
|
height = 1.0
|
||||||
|
rings = 0
|
||||||
|
|
||||||
[node name="Turret" instance=ExtResource("1_cgb0l")]
|
[node name="Turret" instance=ExtResource("1_cgb0l")]
|
||||||
script = ExtResource("2_brx0q")
|
script = ExtResource("2_brx0q")
|
||||||
|
ammo_cap = 10
|
||||||
|
fire_cooldown_time = 0.2
|
||||||
|
reload_time = 1.0
|
||||||
|
bullet_scene = ExtResource("3_kpsgq")
|
||||||
|
fire_position = Vector3(0, 1, 0)
|
||||||
|
shot_impulse = 100.0
|
||||||
|
lead_shot_factor = 0.01
|
||||||
|
|
||||||
[node name="MeshInstance3D" parent="." index="0"]
|
[node name="MeshInstance3D" parent="." index="0"]
|
||||||
material_override = SubResource("StandardMaterial3D_cgb0l")
|
material_override = SubResource("StandardMaterial3D_cgb0l")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="MeshInstance3D" index="0"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.25, 0)
|
||||||
|
mesh = SubResource("CylinderMesh_kpsgq")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="MeshInstance3D/MeshInstance3D" index="0"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 1)
|
||||||
|
mesh = SubResource("CylinderMesh_vuktq")
|
||||||
|
|
||||||
[node name="Consumer" type="Node" parent="." index="5"]
|
[node name="Consumer" type="Node" parent="." index="5"]
|
||||||
script = ExtResource("2_wh3b5")
|
script = ExtResource("2_wh3b5")
|
||||||
metadata/_custom_type_script = "uid://bshiyw2k3op02"
|
metadata/_custom_type_script = "uid://bshiyw2k3op02"
|
||||||
|
|
||||||
|
[connection signal="item_added" from="Consumer" to="." method="_on_consumer_item_added"]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[gd_scene load_steps=12 format=3 uid="uid://cav22qho14o47"]
|
[gd_scene load_steps=17 format=3 uid="uid://cav22qho14o47"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ca8i18spgok4i" path="res://scripts/bullet.gd" id="1_rsjgb"]
|
||||||
[ext_resource type="Shader" uid="uid://jtlad4viky6j" path="res://addons/GPUTrail/shaders/trail.gdshader" id="1_ucnj8"]
|
[ext_resource type="Shader" uid="uid://jtlad4viky6j" path="res://addons/GPUTrail/shaders/trail.gdshader" id="1_ucnj8"]
|
||||||
[ext_resource type="Shader" uid="uid://cxd8wfunwre2a" path="res://addons/GPUTrail/shaders/trail_draw_pass.gdshader" id="2_rsjgb"]
|
[ext_resource type="Shader" uid="uid://cxd8wfunwre2a" path="res://addons/GPUTrail/shaders/trail_draw_pass.gdshader" id="2_rsjgb"]
|
||||||
[ext_resource type="Script" uid="uid://cdubip3a6325r" path="res://addons/GPUTrail/GPUTrail3D.gd" id="4_pt3a8"]
|
[ext_resource type="Script" uid="uid://cdubip3a6325r" path="res://addons/GPUTrail/GPUTrail3D.gd" id="4_pt3a8"]
|
||||||
|
@ -12,35 +13,68 @@ height = 0.3
|
||||||
shader = ExtResource("1_ucnj8")
|
shader = ExtResource("1_ucnj8")
|
||||||
|
|
||||||
[sub_resource type="Gradient" id="Gradient_6sxjd"]
|
[sub_resource type="Gradient" id="Gradient_6sxjd"]
|
||||||
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
|
offsets = PackedFloat32Array(0, 0.150862, 0.642241, 1)
|
||||||
|
colors = PackedColorArray(1, 1, 1, 1, 1, 0.920817, 0, 0.849138, 0.695312, 0.044384, 0, 0.357759, 1, 1, 1, 0)
|
||||||
|
|
||||||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_od3fb"]
|
[sub_resource type="GradientTexture1D" id="GradientTexture1D_od3fb"]
|
||||||
gradient = SubResource("Gradient_6sxjd")
|
gradient = SubResource("Gradient_6sxjd")
|
||||||
|
|
||||||
[sub_resource type="Curve" id="Curve_tmmim"]
|
[sub_resource type="Curve" id="Curve_tmmim"]
|
||||||
|
_limits = [0.0, 0.1, 0.0, 1.0]
|
||||||
bake_resolution = 16
|
bake_resolution = 16
|
||||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0.1), 0.0, 0.0, 0, 0]
|
_data = [Vector2(0, 0.1), 0.0, -0.167493, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||||
point_count = 2
|
point_count = 2
|
||||||
|
|
||||||
[sub_resource type="CurveTexture" id="CurveTexture_7thed"]
|
[sub_resource type="CurveTexture" id="CurveTexture_7thed"]
|
||||||
curve = SubResource("Curve_tmmim")
|
curve = SubResource("Curve_tmmim")
|
||||||
|
|
||||||
|
[sub_resource type="Curve" id="Curve_ucnj8"]
|
||||||
|
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.511628, 1), -1.30273, -1.30273, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||||
|
point_count = 3
|
||||||
|
|
||||||
|
[sub_resource type="CurveTexture" id="CurveTexture_rsjgb"]
|
||||||
|
curve = SubResource("Curve_ucnj8")
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xbcx7"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xbcx7"]
|
||||||
render_priority = 0
|
render_priority = 0
|
||||||
shader = ExtResource("2_rsjgb")
|
shader = ExtResource("2_rsjgb")
|
||||||
|
shader_parameter/tex = SubResource("CurveTexture_rsjgb")
|
||||||
shader_parameter/uv_offset = Vector2(0, 0)
|
shader_parameter/uv_offset = Vector2(0, 0)
|
||||||
shader_parameter/color_ramp = SubResource("GradientTexture1D_od3fb")
|
shader_parameter/color_ramp = SubResource("GradientTexture1D_od3fb")
|
||||||
shader_parameter/curve = SubResource("CurveTexture_7thed")
|
shader_parameter/curve = SubResource("CurveTexture_7thed")
|
||||||
shader_parameter/emmission_transform = Projection(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
shader_parameter/emmission_transform = Projection(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
||||||
shader_parameter/flags = 44
|
shader_parameter/flags = 45
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_ucnj8"]
|
[sub_resource type="QuadMesh" id="QuadMesh_ucnj8"]
|
||||||
material = SubResource("ShaderMaterial_xbcx7")
|
material = SubResource("ShaderMaterial_xbcx7")
|
||||||
size = Vector2(10, 10)
|
size = Vector2(10, 10)
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_xbcx7"]
|
||||||
|
albedo_color = Color(0.79229, 0.800781, 0.372387, 1)
|
||||||
|
emission_enabled = true
|
||||||
|
emission = Color(1, 1, 0, 1)
|
||||||
|
emission_energy_multiplier = 2.5
|
||||||
|
|
||||||
|
[sub_resource type="CylinderMesh" id="CylinderMesh_xbcx7"]
|
||||||
|
material = SubResource("StandardMaterial3D_xbcx7")
|
||||||
|
top_radius = 0.1
|
||||||
|
bottom_radius = 0.1
|
||||||
|
height = 0.3
|
||||||
|
radial_segments = 6
|
||||||
|
rings = 0
|
||||||
|
|
||||||
[node name="Bullet" type="RigidBody3D"]
|
[node name="Bullet" type="RigidBody3D"]
|
||||||
|
collision_layer = 16
|
||||||
|
collision_mask = 5
|
||||||
|
continuous_cd = true
|
||||||
|
contact_monitor = true
|
||||||
|
max_contacts_reported = 1
|
||||||
|
script = ExtResource("1_rsjgb")
|
||||||
|
min_damage = 1.0
|
||||||
|
lifetime = 5.0
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1.31134e-07, 1, 0, -1, 1.31134e-07, 0, 0, 0)
|
||||||
shape = SubResource("CapsuleShape3D_3ndsa")
|
shape = SubResource("CapsuleShape3D_3ndsa")
|
||||||
|
|
||||||
[node name="GPUTrail3D" type="GPUParticles3D" parent="."]
|
[node name="GPUTrail3D" type="GPUParticles3D" parent="."]
|
||||||
|
@ -54,9 +88,20 @@ draw_pass_1 = SubResource("QuadMesh_ucnj8")
|
||||||
script = ExtResource("4_pt3a8")
|
script = ExtResource("4_pt3a8")
|
||||||
length = 19
|
length = 19
|
||||||
length_seconds = 0.322034
|
length_seconds = 0.322034
|
||||||
width = 10.0
|
texture = SubResource("CurveTexture_rsjgb")
|
||||||
color_ramp = SubResource("GradientTexture1D_od3fb")
|
color_ramp = SubResource("GradientTexture1D_od3fb")
|
||||||
curve = SubResource("CurveTexture_7thed")
|
curve = SubResource("CurveTexture_7thed")
|
||||||
|
vertical_texture = true
|
||||||
billboard = true
|
billboard = true
|
||||||
_defaults_have_been_set = true
|
_defaults_have_been_set = true
|
||||||
metadata/_custom_type_script = "uid://cdubip3a6325r"
|
metadata/_custom_type_script = "uid://cdubip3a6325r"
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 6.70552e-08, 1, 0, -1, 6.70552e-08, 0, 0, 0)
|
||||||
|
cast_shadow = 0
|
||||||
|
mesh = SubResource("CylinderMesh_xbcx7")
|
||||||
|
|
||||||
|
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]
|
||||||
|
max_polyphony = 2
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://q80xjurpsmjb"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://1gcj3gixy6hs" path="res://objects/units/unit.tscn" id="1_8hi5e"]
|
||||||
|
[ext_resource type="Script" uid="uid://cl0k7xolx5rf2" path="res://scripts/enemy.gd" id="2_14ipn"]
|
||||||
|
|
||||||
|
[node name="Enemy" groups=["Enemies"] instance=ExtResource("1_8hi5e")]
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 31
|
||||||
|
script = ExtResource("2_14ipn")
|
|
@ -20,7 +20,7 @@ billboard_mode = 1
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_i5arm"]
|
[sub_resource type="QuadMesh" id="QuadMesh_i5arm"]
|
||||||
material = SubResource("StandardMaterial3D_jka67")
|
material = SubResource("StandardMaterial3D_jka67")
|
||||||
|
|
||||||
[node name="Enemy" type="RigidBody3D"]
|
[node name="Unit" type="RigidBody3D"]
|
||||||
axis_lock_angular_x = true
|
axis_lock_angular_x = true
|
||||||
axis_lock_angular_y = true
|
axis_lock_angular_y = true
|
||||||
axis_lock_angular_z = true
|
axis_lock_angular_z = true
|
|
@ -45,6 +45,10 @@ version_control/autoload_on_startup=true
|
||||||
|
|
||||||
enabled=PackedStringArray("res://addons/GPUTrail/plugin.cfg", "res://addons/PathMesh3D/plugin.cfg", "res://addons/git_describe/plugin.cfg", "res://addons/resources_spreadsheet_view/plugin.cfg")
|
enabled=PackedStringArray("res://addons/GPUTrail/plugin.cfg", "res://addons/PathMesh3D/plugin.cfg", "res://addons/git_describe/plugin.cfg", "res://addons/resources_spreadsheet_view/plugin.cfg")
|
||||||
|
|
||||||
|
[global_group]
|
||||||
|
|
||||||
|
Enemies=""
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
3d_render/layer_1="Terrain"
|
3d_render/layer_1="Terrain"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
extends Node
|
extends Node3D
|
||||||
class_name Building
|
class_name Building
|
||||||
|
|
||||||
@export var max_hp: int = 100
|
@export var max_hp: int = 100
|
||||||
|
|
|
@ -22,7 +22,7 @@ func offer_item(item: Item) -> bool:
|
||||||
var old_count: int = storage.get(item, 0)
|
var old_count: int = storage.get(item, 0)
|
||||||
storage.set(item, old_count + 1)
|
storage.set(item, old_count + 1)
|
||||||
storage_total += 1
|
storage_total += 1
|
||||||
print("Added %s to %s storage; previously had %d, new total %d" % [item.name, get_parent().name, old_count, storage_total])
|
#print("Added %s to %s storage; previously had %d, new total %d" % [item.name, get_parent().name, old_count, storage_total])
|
||||||
item_added.emit(item)
|
item_added.emit(item)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
@ -35,6 +35,14 @@ func check_storage_for_items(items: Dictionary[Item, int]) -> bool:
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
func take_any_item_from_storage() -> Item:
|
||||||
|
for item in storage.keys():
|
||||||
|
if storage[item] >= 1:
|
||||||
|
storage[item] -= 1
|
||||||
|
storage_total -= 1
|
||||||
|
return item
|
||||||
|
return null
|
||||||
|
|
||||||
func take_item_from_storage(item: Item) -> bool:
|
func take_item_from_storage(item: Item) -> bool:
|
||||||
return take_items_from_storage({item: 1})
|
return take_items_from_storage({item: 1})
|
||||||
|
|
||||||
|
@ -45,5 +53,5 @@ func take_items_from_storage(items: Dictionary[Item, int]) -> bool:
|
||||||
var old_count: int = storage.get(item, 0)
|
var old_count: int = storage.get(item, 0)
|
||||||
storage.set(item, old_count - items[item])
|
storage.set(item, old_count - items[item])
|
||||||
storage_total -= items[item]
|
storage_total -= items[item]
|
||||||
print("Removed %s from %s storage; previously had %d, new total %d" % [item.name, get_parent().name, old_count, storage_total])
|
#print("Removed %s from %s storage; previously had %d, new total %d" % [item.name, get_parent().name, old_count, storage_total])
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -1 +1,86 @@
|
||||||
extends Building
|
extends Building
|
||||||
|
|
||||||
|
@export var ammo_cap: int = 10
|
||||||
|
@export var fire_cooldown_time: float = 0.2
|
||||||
|
@export var reload_time: float = 1.0
|
||||||
|
@export var bullet_scene: PackedScene = preload("res://objects/bullet.tscn")
|
||||||
|
@export var fire_position: Vector3 = Vector3(0,1,0)
|
||||||
|
@export var shot_impulse: float = 100
|
||||||
|
@export var lead_shot_factor: float = 0.01
|
||||||
|
|
||||||
|
@onready var consumer: Consumer = $Consumer
|
||||||
|
enum LoadState {UNLOADED, RELOADING, LOADED}
|
||||||
|
|
||||||
|
@onready var ammo: int = 0
|
||||||
|
var loaded: LoadState = LoadState.UNLOADED
|
||||||
|
var cooldown_timer: float = 0.0
|
||||||
|
var reload_timer: float = 0.0
|
||||||
|
var current_target: Enemy = null
|
||||||
|
|
||||||
|
func _on_consumer_item_added(item: Item) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if loaded == LoadState.UNLOADED:
|
||||||
|
if consumer.take_any_item_from_storage():
|
||||||
|
#Engine.time_scale = 1.0
|
||||||
|
loaded = LoadState.RELOADING
|
||||||
|
if loaded == LoadState.RELOADING:
|
||||||
|
reload_timer += delta
|
||||||
|
if reload_timer >= reload_time:
|
||||||
|
loaded = LoadState.LOADED
|
||||||
|
ammo = ammo_cap
|
||||||
|
reload_timer = 0.0
|
||||||
|
if loaded == LoadState.LOADED:
|
||||||
|
cooldown_timer += delta
|
||||||
|
if cooldown_timer >= fire_cooldown_time:
|
||||||
|
cooldown_timer -= fire_cooldown_time
|
||||||
|
if current_target == null:
|
||||||
|
search_for_enemy()
|
||||||
|
if current_target != null:
|
||||||
|
fire_at_target()
|
||||||
|
|
||||||
|
func check_target_status() -> void:
|
||||||
|
if current_target.is_queued_for_deletion():
|
||||||
|
current_target = null
|
||||||
|
|
||||||
|
func search_for_enemy() -> void:
|
||||||
|
var enemies: Array[Node] = get_tree().get_nodes_in_group("Enemies")
|
||||||
|
var closest: float = 9999999999
|
||||||
|
for enemy in enemies:
|
||||||
|
if enemy is Enemy:
|
||||||
|
if !enemy.sighted:
|
||||||
|
continue
|
||||||
|
var distance_sqr = global_position.distance_squared_to(enemy.global_position)
|
||||||
|
if distance_sqr <= closest:
|
||||||
|
var params: PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.new()
|
||||||
|
params.collision_mask = 0b00101
|
||||||
|
params.from = to_global(fire_position)
|
||||||
|
params.to = enemy.global_position
|
||||||
|
var result: Dictionary = get_world_3d().direct_space_state.intersect_ray(params)
|
||||||
|
#DebugDraw3D.draw_line_hit(params.from, params.to, result["position"] if result.has("position") else Vector3(), result.has("position"), 0.25, Color.YELLOW, Color.BLACK, 1.0)
|
||||||
|
if result.has("collider"):
|
||||||
|
if !result["collider"] is PhysicsBody3D:
|
||||||
|
continue
|
||||||
|
var body: PhysicsBody3D = result["collider"]
|
||||||
|
if body is Enemy:
|
||||||
|
current_target = body
|
||||||
|
closest = body.global_position.distance_squared_to(global_position)
|
||||||
|
|
||||||
|
func fire_at_target() -> void:
|
||||||
|
#Engine.time_scale = 0.1
|
||||||
|
var bullet: RigidBody3D = bullet_scene.instantiate()
|
||||||
|
add_child(bullet)
|
||||||
|
bullet.global_position = to_global(fire_position)
|
||||||
|
|
||||||
|
var aim_target: Vector3 = current_target.global_position
|
||||||
|
var range: float = global_position.distance_to(current_target.global_position)
|
||||||
|
aim_target += current_target.linear_velocity * lead_shot_factor * range
|
||||||
|
DebugDraw3D.draw_sphere(aim_target, 0.25, Color.RED, 0.1)
|
||||||
|
|
||||||
|
bullet.look_at(aim_target)
|
||||||
|
bullet.apply_impulse((aim_target - bullet.global_position).normalized()*shot_impulse)
|
||||||
|
current_target = null
|
||||||
|
ammo -= 1
|
||||||
|
if ammo <= 0:
|
||||||
|
loaded = LoadState.UNLOADED
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
extends RigidBody3D
|
||||||
|
|
||||||
|
@export var damage_per_speed: float = 1.0
|
||||||
|
@export var min_damage: float = 10.0
|
||||||
|
@export var lifetime: float = 2.0
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node) -> void:
|
||||||
|
print("Bullet collided with %s" % body.name)
|
||||||
|
if body is Unit:
|
||||||
|
var speed: float = linear_velocity.length()
|
||||||
|
var damage: float = speed * damage_per_speed
|
||||||
|
if damage >= min_damage:
|
||||||
|
body.hurt(damage)
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
lifetime -= delta
|
||||||
|
if lifetime <= 0:
|
||||||
|
destroy()
|
||||||
|
if global_position.y < -10:
|
||||||
|
destroy()
|
||||||
|
|
||||||
|
func destroy() -> void:
|
||||||
|
queue_free()
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ca8i18spgok4i
|
|
@ -0,0 +1,4 @@
|
||||||
|
extends Unit
|
||||||
|
class_name Enemy
|
||||||
|
|
||||||
|
var sighted: bool = true
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cl0k7xolx5rf2
|
|
@ -0,0 +1,15 @@
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
@export var spawn_scene: PackedScene = null
|
||||||
|
@export var spawn_time: float = 5.0
|
||||||
|
|
||||||
|
var spawn_timer: float = 0.0
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
spawn_timer += delta
|
||||||
|
if spawn_timer >= spawn_time:
|
||||||
|
spawn_timer -= spawn_time
|
||||||
|
var node: Node = spawn_scene.instantiate()
|
||||||
|
add_child(node)
|
||||||
|
if node is Node3D:
|
||||||
|
node.global_position = global_position
|
|
@ -0,0 +1 @@
|
||||||
|
uid://b0fgl7qg8ha4n
|
|
@ -1,16 +1,20 @@
|
||||||
extends RigidBody3D
|
extends RigidBody3D
|
||||||
class_name Unit
|
class_name Unit
|
||||||
|
|
||||||
|
@export var max_hp: float = 100
|
||||||
@export var movement_force: float = 100
|
@export var movement_force: float = 100
|
||||||
@export var max_speed: float = 100
|
@export var max_speed: float = 100
|
||||||
@export var minimum_progress_rate: float = 1.0
|
@export var minimum_progress_rate: float = 1.0
|
||||||
@export var stuck_time: float = 1.0
|
@export var stuck_time: float = 1.0
|
||||||
|
|
||||||
|
@onready var hp: float = max_hp
|
||||||
var target_velocity: Vector3 = Vector3()
|
var target_velocity: Vector3 = Vector3()
|
||||||
var avoidance_velocity: Vector3 = Vector3()
|
var avoidance_velocity: Vector3 = Vector3()
|
||||||
var avoidance_timeout: float = 0.0
|
var avoidance_timeout: float = 0.0
|
||||||
var last_distance_to_target: float = 0.0
|
var last_distance_to_target: float = 0.0
|
||||||
var stuck_timer: float = 0.0
|
var stuck_timer: float = 0.0
|
||||||
|
var move_target: Vector3 = Vector3(16, 1, 13)
|
||||||
|
var move_radius: float = 5.0
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$NavigationAgent3D.connect("velocity_computed", avoidance_velocity_computed)
|
$NavigationAgent3D.connect("velocity_computed", avoidance_velocity_computed)
|
||||||
|
@ -22,24 +26,28 @@ func avoidance_velocity_computed(velocity: Vector3) -> void:
|
||||||
avoidance_timeout = 0.5
|
avoidance_timeout = 0.5
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
$Label3D.text = "HP: %d" % hp
|
||||||
|
|
||||||
if $NavigationAgent3D.is_target_reached() \
|
if $NavigationAgent3D.is_target_reached() \
|
||||||
or $NavigationAgent3D.target_position.is_zero_approx() \
|
or $NavigationAgent3D.target_position.is_zero_approx() \
|
||||||
or !$NavigationAgent3D.is_target_reachable():
|
or !$NavigationAgent3D.is_target_reachable():
|
||||||
$NavigationAgent3D.target_position = NavigationServer3D.map_get_random_point(NavigationServer3D.get_maps()[0], 1, true)
|
$NavigationAgent3D.target_position = move_target + Vector3(randfn(0, move_radius), 0, randfn(0, move_radius))
|
||||||
|
#$NavigationAgent3D.target_position = NavigationServer3D.map_get_random_point(NavigationServer3D.get_maps()[0], 1, true)
|
||||||
last_distance_to_target = $NavigationAgent3D.distance_to_target()
|
last_distance_to_target = $NavigationAgent3D.distance_to_target()
|
||||||
else:
|
else:
|
||||||
|
if $ShapeCast3D.is_colliding():
|
||||||
var distance_to_target: float = $NavigationAgent3D.distance_to_target()
|
var distance_to_target: float = $NavigationAgent3D.distance_to_target()
|
||||||
var progress_rate: float = (last_distance_to_target - distance_to_target) / delta
|
var progress_rate: float = (last_distance_to_target - distance_to_target) / delta
|
||||||
$Label3D.text = "Prog: %f" % progress_rate
|
|
||||||
last_distance_to_target = distance_to_target
|
last_distance_to_target = distance_to_target
|
||||||
if progress_rate < minimum_progress_rate:
|
if progress_rate < minimum_progress_rate:
|
||||||
$Label3D.modulate = Color.RED
|
|
||||||
stuck_timer += delta
|
stuck_timer += delta
|
||||||
if stuck_timer >= stuck_time:
|
if stuck_timer >= stuck_time:
|
||||||
unstuck()
|
unstuck()
|
||||||
else:
|
else:
|
||||||
$Label3D.modulate = Color.WHITE
|
$Label3D.modulate = Color.WHITE
|
||||||
stuck_timer = 0
|
stuck_timer = 0
|
||||||
|
if global_position.y <= -10:
|
||||||
|
unstuck()
|
||||||
#DebugDraw3D.draw_sphere($NavigationAgent3D.target_position, 0.5, Color.RED)
|
#DebugDraw3D.draw_sphere($NavigationAgent3D.target_position, 0.5, Color.RED)
|
||||||
var next_point: Vector3 = $NavigationAgent3D.get_next_path_position()
|
var next_point: Vector3 = $NavigationAgent3D.get_next_path_position()
|
||||||
#DebugDraw3D.draw_sphere(next_point, 0.1, Color.YELLOW)
|
#DebugDraw3D.draw_sphere(next_point, 0.1, Color.YELLOW)
|
||||||
|
@ -52,9 +60,19 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
func unstuck() -> void:
|
func unstuck() -> void:
|
||||||
# teleport to next path point
|
# teleport to next path point
|
||||||
|
linear_velocity = Vector3()
|
||||||
global_position = $NavigationAgent3D.get_next_path_position()
|
global_position = $NavigationAgent3D.get_next_path_position()
|
||||||
stuck_timer = 0
|
stuck_timer = 0
|
||||||
|
|
||||||
|
func hurt(damage: float) -> void:
|
||||||
|
hp -= damage
|
||||||
|
print("%s hit for %f damage, HP=%f" % [name, damage, hp])
|
||||||
|
if hp <= 0:
|
||||||
|
die()
|
||||||
|
|
||||||
|
func die() -> void:
|
||||||
|
queue_free()
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if $ShapeCast3D.is_colliding():
|
if $ShapeCast3D.is_colliding():
|
||||||
var actual_target_velocity: Vector3 = target_velocity
|
var actual_target_velocity: Vector3 = target_velocity
|
||||||
|
|
Loading…
Reference in New Issue