Implemented state machine & added NPC ship template

This commit is contained in:
2ndbeam 2024-05-01 17:45:17 +03:00
commit bda9232e72
15 changed files with 284 additions and 22 deletions

View file

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://bkd4gyhlota7l"]
[ext_resource type="PackedScene" uid="uid://bsu4eqwdfewwi" path="res://scenes/Ships/Modules/Hulls/hull.tscn" id="1_l56rl"]
[ext_resource type="Texture2D" uid="uid://bchkncbniclhh" path="res://sprites/kamikaze.png" id="2_8ba3c"]
[node name="Hull" instance=ExtResource("1_l56rl")]
max_hp = 10.0
velocity_collision_treshold = 150.0
collision_damage = 10.0
[node name="Sprite" parent="." index="0"]
position = Vector2(0.5, 0.5)
texture = ExtResource("2_8ba3c")
[node name="Collision" parent="." index="1"]
polygon = PackedVector2Array(-69.5, 21, -69.5, 66, -68.5, 66, -57.5, 55, -57.5, 65, -56.5, 65, 70.5, 1, 70.5, 0, -56.5, -64, -57.5, -64, -57.5, -54, -68.5, -65, -69.5, -65, -69.5, -20, -68.5, -20, -57.5, -31, -57.5, -23, -32.5, -10, -32.5, 11, -57.5, 24, -57.5, 32, -68.5, 21)

View file

@ -0,0 +1,35 @@
[gd_scene load_steps=7 format=3 uid="uid://pev6k21vqaem"]
[ext_resource type="Script" path="res://scripts/Ship/ship.gd" id="1_82bba"]
[ext_resource type="PackedScene" uid="uid://bkd4gyhlota7l" path="res://scenes/Ships/Modules/Hulls/kamikaze_hull.tscn" id="2_165nu"]
[ext_resource type="PackedScene" uid="uid://mw4kwxoeqch3" path="res://scenes/Ships/Modules/Engines/engine.tscn" id="3_plu72"]
[ext_resource type="PackedScene" uid="uid://bunboi5ouscw8" path="res://scenes/Ships/Modules/Shields/shield.tscn" id="4_aos8x"]
[ext_resource type="Script" path="res://scripts/State Machine/tree.gd" id="5_m8m3f"]
[ext_resource type="Script" path="res://scripts/State Machine/Kamikaze/WanderingState.gd" id="6_emcj1"]
[node name="KamikazeShip" type="Node2D"]
script = ExtResource("1_82bba")
[node name="HullHolder" type="Node" parent="."]
[node name="Hull" parent="HullHolder" instance=ExtResource("2_165nu")]
collision_damage = 15.0
[node name="Engine" parent="." instance=ExtResource("3_plu72")]
[node name="Shield" parent="." instance=ExtResource("4_aos8x")]
max_capacity = 5
[node name="Weapons" type="Node2D" parent="."]
[node name="StateTree" type="Node" parent="." node_paths=PackedStringArray("state")]
script = ExtResource("5_m8m3f")
state = NodePath("WanderingState")
[node name="WanderingState" type="Node" parent="StateTree"]
script = ExtResource("6_emcj1")
[node name="UpdateDestination" type="Timer" parent="StateTree/WanderingState"]
wait_time = 10.0
[connection signal="timeout" from="StateTree/WanderingState/UpdateDestination" to="StateTree/WanderingState" method="update_destination"]

View file

@ -1,10 +1,13 @@
[gd_scene load_steps=11 format=3 uid="uid://dok3i8u5t1ka4"]
[gd_scene load_steps=14 format=3 uid="uid://dok3i8u5t1ka4"]
[ext_resource type="PackedScene" uid="uid://bjkshql8ut6hk" path="res://scenes/Ships/ship.tscn" id="1_6x7bu"]
[ext_resource type="Script" path="res://scripts/Ship/player_ship.gd" id="2_oqdd7"]
[ext_resource type="Script" path="res://scripts/Ship/player_input_controller.gd" id="3_0e84a"]
[ext_resource type="PackedScene" uid="uid://bsu4eqwdfewwi" path="res://scenes/Ships/Modules/Hulls/hull.tscn" id="3_ku5af"]
[ext_resource type="PackedScene" uid="uid://ryy1tdrxmjav" path="res://scenes/Ships/Modules/Weapons/weapon.tscn" id="4_fy1be"]
[ext_resource type="PackedScene" uid="uid://mw4kwxoeqch3" path="res://scenes/Ships/Modules/Engines/engine.tscn" id="4_pmbbn"]
[ext_resource type="PackedScene" uid="uid://bunboi5ouscw8" path="res://scenes/Ships/Modules/Shields/shield.tscn" id="5_7fjpq"]
[ext_resource type="Script" path="res://scripts/Ship/player_camera.gd" id="5_rclap"]
[ext_resource type="Script" path="res://scripts/Ship/weapons.gd" id="6_f6fm2"]
[sub_resource type="GDScript" id="GDScript_ry4sc"]
resource_name = "money_counter"
@ -77,20 +80,35 @@ func _process(_delta):
text = unformatted_text.format(format)
"
[node name="PlayerShip" instance=ExtResource("1_6x7bu")]
[node name="PlayerShip" type="Node2D"]
process_mode = 1
script = ExtResource("2_oqdd7")
[node name="InputController" type="Node2D" parent="." index="0"]
[node name="InputController" type="Node2D" parent="."]
script = ExtResource("3_0e84a")
[node name="Weapon" parent="Weapons" index="0" instance=ExtResource("4_fy1be")]
[node name="HullHolder" type="Node" parent="."]
[node name="Hull" parent="HullHolder" instance=ExtResource("3_ku5af")]
collision_mask = 3
max_contacts_reported = 1
contact_monitor = true
[node name="Engine" parent="." instance=ExtResource("4_pmbbn")]
[node name="Shield" parent="." instance=ExtResource("5_7fjpq")]
[node name="Weapons" type="Node2D" parent="."]
script = ExtResource("6_f6fm2")
[node name="Weapon" parent="Weapons" instance=ExtResource("4_fy1be")]
action_id = "primary"
ammo_type = "Laser Energy"
ammo_consumption = 1.0
[node name="ColorableGUI" type="CanvasLayer" parent="." index="5"]
[node name="ColorableGUI" type="CanvasLayer" parent="."]
[node name="Money" type="Label" parent="ColorableGUI" index="0"]
[node name="Money" type="Label" parent="ColorableGUI"]
offset_left = 7.0
offset_top = 611.0
offset_right = 92.0
@ -98,7 +116,7 @@ offset_bottom = 634.0
text = "Money: %d"
script = SubResource("GDScript_ry4sc")
[node name="Velocity" type="Label" parent="ColorableGUI" index="1"]
[node name="Velocity" type="Label" parent="ColorableGUI"]
offset_left = 7.0
offset_top = 688.0
offset_right = 137.0
@ -106,7 +124,7 @@ offset_bottom = 711.0
text = "Velocity: %d px/s"
script = SubResource("GDScript_vko7a")
[node name="Health" type="Label" parent="ColorableGUI" index="2"]
[node name="Health" type="Label" parent="ColorableGUI"]
offset_left = 7.0
offset_top = 663.0
offset_right = 168.0
@ -114,7 +132,7 @@ offset_bottom = 686.0
text = "Health: {0} / {1} units"
script = SubResource("GDScript_uoaip")
[node name="Shield" type="Label" parent="ColorableGUI" index="3"]
[node name="Shield" type="Label" parent="ColorableGUI"]
offset_left = 8.0
offset_top = 638.0
offset_right = 164.0
@ -122,7 +140,7 @@ offset_bottom = 661.0
text = "Shield: {0} / {1} units"
script = SubResource("GDScript_q1sx2")
[node name="Ammunition" type="Label" parent="ColorableGUI" index="4"]
[node name="Ammunition" type="Label" parent="ColorableGUI"]
offset_left = 1060.0
offset_top = 638.0
offset_right = 1273.0
@ -133,8 +151,8 @@ Rockets: {2} / {3}"
horizontal_alignment = 2
script = SubResource("GDScript_rrgab")
[node name="NonColorableGUI" type="CanvasLayer" parent="." index="6"]
[node name="NonColorableGUI" type="CanvasLayer" parent="."]
[node name="Camera" type="Camera2D" parent="." index="7"]
[node name="Camera" type="Camera2D" parent="."]
zoom = Vector2(0.5, 0.5)
script = ExtResource("5_rclap")