From bb965530264d5b9f941cea3a8c89f404d9378ab0 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sun, 25 May 2025 02:39:07 +0200 Subject: [PATCH] Add ship movement and shooting mechanics; update flying ship scene with new components --- objects/entities/brick_player.tscn | 8 +- objects/entities/flying_enemy.tscn | 32 ++++- objects/entities/flying_ship.tscn | 172 +++++++++++++++++++++++- objects/entities/green_laser.tscn | 74 ++++++++++ objects/entities/red_laser.tscn | 68 ++++++++++ scenes/level_village_1.tscn | 1 - scripts/components/ship_movement.gd | 26 ++++ scripts/components/ship_movement.gd.uid | 1 + scripts/components/ship_shooter.gd | 33 +++++ scripts/components/ship_shooter.gd.uid | 1 + 10 files changed, 406 insertions(+), 10 deletions(-) create mode 100644 objects/entities/green_laser.tscn create mode 100644 objects/entities/red_laser.tscn create mode 100644 scripts/components/ship_movement.gd create mode 100644 scripts/components/ship_movement.gd.uid create mode 100644 scripts/components/ship_shooter.gd create mode 100644 scripts/components/ship_shooter.gd.uid diff --git a/objects/entities/brick_player.tscn b/objects/entities/brick_player.tscn index 4941201..6c1bca2 100644 --- a/objects/entities/brick_player.tscn +++ b/objects/entities/brick_player.tscn @@ -48,14 +48,14 @@ radius = 48.0 [sub_resource type="Gradient" id="Gradient_qb72p"] colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0) -[sub_resource type="GradientTexture1D" id="GradientTexture1D_f1fvy"] +[sub_resource type="GradientTexture1D" id="GradientTexture1D_lgb3u"] gradient = SubResource("Gradient_qb72p") [sub_resource type="Curve" id="Curve_82d6e"] _data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] point_count = 2 -[sub_resource type="CurveTexture" id="CurveTexture_7b7mt"] +[sub_resource type="CurveTexture" id="CurveTexture_xoue7"] curve = SubResource("Curve_82d6e") [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_lgb3u"] @@ -71,9 +71,9 @@ gravity = Vector3(0, 80, 0) damping_min = 400.0 damping_max = 800.0 scale_max = 3.0 -scale_curve = SubResource("CurveTexture_7b7mt") +scale_curve = SubResource("CurveTexture_xoue7") color = Color(0.764706, 0.443137, 0, 1) -color_ramp = SubResource("GradientTexture1D_f1fvy") +color_ramp = SubResource("GradientTexture1D_lgb3u") [node name="Brick Player" type="CharacterBody2D" node_paths=PackedStringArray("jump_sfx", "rotation_target") groups=["player"]] collision_layer = 4 diff --git a/objects/entities/flying_enemy.tscn b/objects/entities/flying_enemy.tscn index 85e7853..bbfe95c 100644 --- a/objects/entities/flying_enemy.tscn +++ b/objects/entities/flying_enemy.tscn @@ -1,11 +1,13 @@ -[gd_scene load_steps=25 format=3 uid="uid://xp4njljog0x2"] +[gd_scene load_steps=29 format=3 uid="uid://xp4njljog0x2"] [ext_resource type="Texture2D" uid="uid://22k1u37j6k8y" path="res://sprites/flying_enemy.png" id="1_30hhw"] +[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="1_uyhuj"] [ext_resource type="Script" uid="uid://btfsq0bvtrx3t" path="res://scripts/components/health.gd" id="2_ivniq"] [ext_resource type="AudioStream" uid="uid://b3tsqhr06pbrs" path="res://sfx/enemy_hurt.wav" id="3_fd2du"] [ext_resource type="AudioStream" uid="uid://dyev46uqusimi" path="res://sfx/shoot.wav" id="4_rhq76"] [ext_resource type="Script" uid="uid://dkmxhjtmu5xlb" path="res://scripts/components/damage_component.gd" id="5_cmp1h"] [ext_resource type="Script" uid="uid://b37gqnycj6rtk" path="res://scripts/components/periodic_shooting.gd" id="6_4ajjm"] +[ext_resource type="PackedScene" uid="uid://t422jkov2t1b" path="res://objects/entities/red_laser.tscn" id="7_4ajjm"] [ext_resource type="Script" uid="uid://dqm371fysuk7i" path="res://scripts/components/enemy_death.gd" id="7_uyhuj"] [ext_resource type="Script" uid="uid://dqmbvuutd5c3c" path="res://scripts/components/flashing_component.gd" id="8_q78ru"] [ext_resource type="Script" uid="uid://ceq8n7yw7qxpi" path="res://scripts/components/hit_component.gd" id="9_weo6b"] @@ -19,6 +21,11 @@ [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_hil2i"] radius = 6.0 +[sub_resource type="ShaderMaterial" id="ShaderMaterial_q78ru"] +shader = ExtResource("1_uyhuj") +shader_parameter/enabled = false +shader_parameter/tint = Color(1, 1, 1, 1) + [sub_resource type="Curve" id="Curve_68xvh"] _data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.870036, 0.767164), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] point_count = 3 @@ -69,22 +76,31 @@ scale_curve = SubResource("CurveTexture_7b7mt") color = Color(0.47451, 0.47451, 0.47451, 1) color_ramp = SubResource("GradientTexture1D_f1fvy") +[sub_resource type="RectangleShape2D" id="RectangleShape2D_cmp1h"] +size = Vector2(16, 26) + [node name="Flying Enemy" type="CharacterBody2D"] +collision_layer = 8 +collision_mask = 21 +motion_mode = 1 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] visible = false shape = SubResource("CapsuleShape2D_hil2i") [node name="Sprite2D" type="Sprite2D" parent="."] +material = SubResource("ShaderMaterial_q78ru") texture = ExtResource("1_30hhw") [node name="Jetpack Particles" type="GPUParticles2D" parent="."] +z_index = -1 position = Vector2(-4, 16) explosiveness = 0.5 fixed_fps = 24 process_material = SubResource("ParticleProcessMaterial_fd2du") [node name="Jetpack Particles2" type="GPUParticles2D" parent="."] +z_index = -1 position = Vector2(4, 16) explosiveness = 0.5 fixed_fps = 24 @@ -103,11 +119,11 @@ stream = ExtResource("4_rhq76") [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] script = ExtResource("5_cmp1h") -area2d = NodePath("") +area2d = NodePath("../Hitbox") -[node name="PeriodicShootingComponent" type="Node" parent="." node_paths=PackedStringArray("side_to_side_movement", "root", "bullet_spawn_right", "bullet_spawn_left")] +[node name="PeriodicShootingComponent" type="Node" parent="." node_paths=PackedStringArray("root", "bullet_spawn_right", "bullet_spawn_left")] script = ExtResource("6_4ajjm") -side_to_side_movement = NodePath("") +bullet_scene = ExtResource("7_4ajjm") root = NodePath("..") bullet_spawn_right = NodePath("../laser spawn point right") bullet_spawn_left = NodePath("../laser spawn point left") @@ -166,3 +182,11 @@ position = Vector2(8, -2) [node name="laser spawn point left" type="Node2D" parent="."] position = Vector2(-9, -2) + +[node name="Hitbox" type="Area2D" parent="."] +collision_layer = 8 +collision_mask = 20 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"] +position = Vector2(0, 2) +shape = SubResource("RectangleShape2D_cmp1h") diff --git a/objects/entities/flying_ship.tscn b/objects/entities/flying_ship.tscn index c968c94..376ac83 100644 --- a/objects/entities/flying_ship.tscn +++ b/objects/entities/flying_ship.tscn @@ -1,13 +1,183 @@ -[gd_scene load_steps=2 format=3 uid="uid://8wy1jxy1lihn"] +[gd_scene load_steps=29 format=3 uid="uid://8wy1jxy1lihn"] [ext_resource type="Texture2D" uid="uid://dhkwyv6ayb5qb" path="res://sprites/flying_ship.png" id="1_umrfk"] +[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_vlo17"] +[ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="3_e1par"] +[ext_resource type="Texture2D" uid="uid://jl1gwqchhpdc" path="res://sprites/left_eye.png" id="4_d5f6y"] +[ext_resource type="Texture2D" uid="uid://iiawtnwmeny3" path="res://sprites/right_eye.png" id="5_k3peb"] +[ext_resource type="Script" uid="uid://btfsq0bvtrx3t" path="res://scripts/components/health.gd" id="6_e1par"] +[ext_resource type="AudioStream" uid="uid://bmfn6p88gy575" path="res://sfx/player_hurt.wav" id="7_q8x53"] +[ext_resource type="AudioStream" uid="uid://ycgtf6wj7mto" path="res://sfx/heal.wav" id="8_5aboc"] +[ext_resource type="PackedScene" uid="uid://b12tppjkkqpt4" path="res://objects/fxs/hit_particles.tscn" id="9_buvrj"] +[ext_resource type="Script" uid="uid://ijrli0x8ij8v" path="res://scripts/components/invulnerability_component.gd" id="10_y4xwp"] +[ext_resource type="Script" uid="uid://dqmbvuutd5c3c" path="res://scripts/components/flashing_component.gd" id="11_m7okj"] +[ext_resource type="Script" uid="uid://ceq8n7yw7qxpi" path="res://scripts/components/hit_component.gd" id="12_dwqug"] +[ext_resource type="Script" uid="uid://b3mrdvre1y567" path="res://scripts/components/ship_movement.gd" id="13_m7okj"] +[ext_resource type="Script" uid="uid://d1ctdx52gskv1" path="res://scripts/components/ship_shooter.gd" id="14_e7gat"] +[ext_resource type="AudioStream" uid="uid://dyev46uqusimi" path="res://sfx/shoot.wav" id="15_4fjnq"] +[ext_resource type="PackedScene" uid="uid://dtem8jgcyoqar" path="res://objects/entities/green_laser.tscn" id="15_67g38"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_y4xwp"] +size = Vector2(16, 32) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_q8x53"] +shader = ExtResource("2_vlo17") +shader_parameter/enabled = false +shader_parameter/tint = Color(1, 1, 1, 1) + +[sub_resource type="Gradient" id="Gradient_umrfk"] +offsets = PackedFloat32Array(0, 0.173759, 0.521277, 0.687943, 0.886525, 1) +colors = PackedColorArray(1.635, 0.188, 0, 1, 1.89, 0.318, 0, 1, 1, 0.470588, 0.188235, 1, 1, 0.635294, 0, 1, 1, 0.858824, 0.635294, 1, 1, 1, 1, 0.501961) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_g31n1"] +gradient = SubResource("Gradient_umrfk") +use_hdr = true + +[sub_resource type="Curve" id="Curve_wcyu2"] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.606498, 0.621642), -1.25408, -1.25408, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 3 + +[sub_resource type="CurveTexture" id="CurveTexture_epnjh"] +curve = SubResource("Curve_wcyu2") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_vlo17"] +lifetime_randomness = 0.85 +particle_flag_disable_z = true +emission_shape = 1 +emission_sphere_radius = 3.0 +angle_min = -35.0 +angle_max = 35.0 +direction = Vector3(0, 1, 0) +initial_velocity_min = 30.0 +initial_velocity_max = 60.0 +gravity = Vector3(0, 98, 0) +scale_min = 2.0 +scale_max = 4.0 +scale_curve = SubResource("CurveTexture_epnjh") +color_ramp = SubResource("GradientTexture1D_g31n1") + +[sub_resource type="Gradient" id="Gradient_m7okj"] +colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_f1fvy"] +gradient = SubResource("Gradient_m7okj") + +[sub_resource type="Curve" id="Curve_dwqug"] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="CurveTexture_7b7mt"] +curve = SubResource("Curve_dwqug") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_e7gat"] +resource_local_to_scene = true +lifetime_randomness = 1.0 +particle_flag_disable_z = true +emission_shape = 1 +emission_sphere_radius = 8.0 +direction = Vector3(0.1, -0.5, 0) +initial_velocity_min = 200.0 +initial_velocity_max = 400.0 +gravity = Vector3(0, 80, 0) +damping_min = 400.0 +damping_max = 800.0 +scale_max = 3.0 +scale_curve = SubResource("CurveTexture_7b7mt") +color = Color(0.764706, 0.443137, 0, 1) +color_ramp = SubResource("GradientTexture1D_f1fvy") [node name="Flying ship" type="CharacterBody2D"] +collision_layer = 4 +collision_mask = 9 +motion_mode = 1 [node name="CollisionShape2D" type="CollisionPolygon2D" parent="."] position = Vector2(-0.5, 7) polygon = PackedVector2Array(-13.5, -8, -13.5, -10, -12.5, -11, -10.5, -11, -8.5, -8, -7.5, -7, 10.5, -7, 15.5, -3, 15.5, -1, 10.5, 3, 6.5, 4, 4.5, 5, 2.5, 7, -1.5, 7, -5.5, 4, -9.5, 3, -11.5, 2, -14.5, -1, -14.5, -3, -12.5, -5, -11.5, -5, -11.5, -7, -12.5, -7) +[node name="Player hitbox" type="CollisionShape2D" parent="."] +position = Vector2(-2, -7) +shape = SubResource("RectangleShape2D_y4xwp") + [node name="Sprite2D" type="Sprite2D" parent="."] position = Vector2(0, -1) texture = ExtResource("1_umrfk") + +[node name="Brick Position" type="Node2D" parent="."] + +[node name="Root" type="Node2D" parent="Brick Position"] +z_index = -1 +position = Vector2(-2, -7) + +[node name="Base" type="Sprite2D" parent="Brick Position/Root"] +material = SubResource("ShaderMaterial_q8x53") +texture = ExtResource("3_e1par") + +[node name="Left Eye" type="Sprite2D" parent="Brick Position/Root"] +position = Vector2(-7, -6) +texture = ExtResource("4_d5f6y") +hframes = 2 + +[node name="Right Eye" type="Sprite2D" parent="Brick Position/Root"] +position = Vector2(6, -5) +texture = ExtResource("5_k3peb") +hframes = 2 + +[node name="Engine particles" type="GPUParticles2D" parent="."] +z_index = -1 +position = Vector2(0, 12) +amount = 64 +fixed_fps = 24 +process_material = SubResource("ParticleProcessMaterial_vlo17") + +[node name="HealthComponent" type="Node" parent="." node_paths=PackedStringArray("hurt_fx", "heal_fx")] +script = ExtResource("6_e1par") +hurt_fx = NodePath("../sfx_hurt") +heal_fx = NodePath("../sfx_heal") +metadata/_custom_type_script = "uid://btfsq0bvtrx3t" + +[node name="sfx_hurt" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource("7_q8x53") + +[node name="sfx_heal" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource("8_5aboc") + +[node name="HitParticles" parent="." instance=ExtResource("9_buvrj")] +position = Vector2(-2, -5) +process_material = SubResource("ParticleProcessMaterial_e7gat") + +[node name="InvulnerabilityComponent" type="Node" parent="." node_paths=PackedStringArray("flashing_component")] +script = ExtResource("10_y4xwp") +flashing_component = NodePath("../FlashingComponent Base") + +[node name="FlashingComponent Base" type="Node" parent="." node_paths=PackedStringArray("sprite", "health_component")] +script = ExtResource("11_m7okj") +sprite = NodePath("../Brick Position/Root/Base") +flash_duration = 1.0 +health_component = NodePath("../HealthComponent") + +[node name="HitComponent" type="Node" parent="." node_paths=PackedStringArray("sprite", "health_component", "hit_fx")] +script = ExtResource("12_dwqug") +sprite = NodePath("../Brick Position/Root/Base") +health_component = NodePath("../HealthComponent") +hit_fx = NodePath("../HitParticles") +metadata/_custom_type_script = "uid://ceq8n7yw7qxpi" + +[node name="ShipMovement" type="Node" parent="." node_paths=PackedStringArray("body")] +script = ExtResource("13_m7okj") +acceleration = 800.0 +friction = 600.0 +body = NodePath("..") + +[node name="Shoot spawn" type="Marker2D" parent="."] +position = Vector2(16, -2) +gizmo_extents = 1.0 + +[node name="ShipShooter" type="Node" parent="." node_paths=PackedStringArray("bullet_spawn", "shoot_sfx")] +script = ExtResource("14_e7gat") +bullet_scene = ExtResource("15_67g38") +bullet_spawn = NodePath("../Shoot spawn") +shoot_sfx = NodePath("../sfx_shoot") + +[node name="sfx_shoot" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource("15_4fjnq") diff --git a/objects/entities/green_laser.tscn b/objects/entities/green_laser.tscn new file mode 100644 index 0000000..c17fe53 --- /dev/null +++ b/objects/entities/green_laser.tscn @@ -0,0 +1,74 @@ +[gd_scene load_steps=9 format=3 uid="uid://dtem8jgcyoqar"] + +[ext_resource type="Script" uid="uid://dkmxhjtmu5xlb" path="res://scripts/components/damage_component.gd" id="1_nuljg"] +[ext_resource type="Script" uid="uid://cdnwrn8v05qhi" path="res://scripts/components/bullet_component.gd" id="2_1gu8o"] +[ext_resource type="Script" uid="uid://1tnr46o1ib4u" path="res://scripts/components/out_of_screen_component.gd" id="3_2vcrp"] +[ext_resource type="Script" uid="uid://cvcnfrr1udco5" path="res://scripts/components/straight_motion_component.gd" id="4_2bmqm"] +[ext_resource type="Script" uid="uid://873un8agkyja" path="res://scripts/components/launch_component.gd" id="5_772bd"] +[ext_resource type="Script" uid="uid://bvsgg8lu0a8m6" path="res://scripts/components/lifetime_component.gd" id="6_vd16u"] +[ext_resource type="Script" uid="uid://bgty7040ams6s" path="res://scripts/components/projectile_init_component.gd" id="7_1gu8o"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_n4uav"] +size = Vector2(16, 2) + +[node name="Red Laser" type="Area2D"] +collision_layer = 16 +collision_mask = 9 + +[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] +script = ExtResource("1_nuljg") +area2d = NodePath("..") +metadata/_custom_type_script = "uid://dkmxhjtmu5xlb" + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(8, -0.5) +shape = SubResource("RectangleShape2D_n4uav") + +[node name="Line2D" type="Line2D" parent="."] +points = PackedVector2Array(0, 0, 16, 0) +width = 2.0 +default_color = Color(0, 94.012, 1, 1) + +[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d")] +script = ExtResource("2_1gu8o") +root = NodePath("..") +area2d = NodePath("..") +metadata/_custom_type_script = "uid://cdnwrn8v05qhi" + +[node name="OutOfScreenComponent" type="Node" parent="." node_paths=PackedStringArray("visibility_notifier", "root")] +script = ExtResource("3_2vcrp") +visibility_notifier = NodePath("../VisibleOnScreenNotifier2D") +root = NodePath("..") +metadata/_custom_type_script = "uid://1tnr46o1ib4u" + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] +position = Vector2(8, 0) +scale = Vector2(0.8, 0.1) + +[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("root", "launch_component")] +script = ExtResource("4_2bmqm") +root = NodePath("..") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://cvcnfrr1udco5" + +[node name="LaunchComponent" type="Node2D" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("5_772bd") +root = NodePath("..") +speed = 320.0 +metadata/_custom_type_script = "uid://873un8agkyja" + +[node name="LifetimeComponent" type="Node" parent="." node_paths=PackedStringArray("root", "timer")] +script = ExtResource("6_vd16u") +root = NodePath("..") +life_time = 10.0 +timer = NodePath("../Timer") +metadata/_custom_type_script = "uid://bvsgg8lu0a8m6" + +[node name="Timer" type="Timer" parent="."] +wait_time = 5.0 +autostart = true + +[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("launch_component")] +script = ExtResource("7_1gu8o") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://bgty7040ams6s" diff --git a/objects/entities/red_laser.tscn b/objects/entities/red_laser.tscn new file mode 100644 index 0000000..f413beb --- /dev/null +++ b/objects/entities/red_laser.tscn @@ -0,0 +1,68 @@ +[gd_scene load_steps=8 format=3 uid="uid://t422jkov2t1b"] + +[ext_resource type="Script" uid="uid://dkmxhjtmu5xlb" path="res://scripts/components/damage_component.gd" id="1_koyoa"] +[ext_resource type="Script" uid="uid://cdnwrn8v05qhi" path="res://scripts/components/bullet_component.gd" id="2_eru3x"] +[ext_resource type="Script" uid="uid://1tnr46o1ib4u" path="res://scripts/components/out_of_screen_component.gd" id="3_m14o3"] +[ext_resource type="Script" uid="uid://cvcnfrr1udco5" path="res://scripts/components/straight_motion_component.gd" id="4_dolct"] +[ext_resource type="Script" uid="uid://873un8agkyja" path="res://scripts/components/launch_component.gd" id="5_eafpt"] +[ext_resource type="Script" uid="uid://bvsgg8lu0a8m6" path="res://scripts/components/lifetime_component.gd" id="6_m14o3"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_n4uav"] +size = Vector2(16, 2) + +[node name="Red Laser" type="Area2D"] +collision_layer = 8 +collision_mask = 21 + +[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] +script = ExtResource("1_koyoa") +area2d = NodePath("..") +metadata/_custom_type_script = "uid://dkmxhjtmu5xlb" + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(8, -0.5) +shape = SubResource("RectangleShape2D_n4uav") + +[node name="Line2D" type="Line2D" parent="."] +points = PackedVector2Array(0, 0, 16, 0) +width = 2.0 +default_color = Color(90, 1, 1, 1) + +[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d")] +script = ExtResource("2_eru3x") +root = NodePath("..") +area2d = NodePath("..") +metadata/_custom_type_script = "uid://cdnwrn8v05qhi" + +[node name="OutOfScreenComponent" type="Node" parent="." node_paths=PackedStringArray("visibility_notifier", "root")] +script = ExtResource("3_m14o3") +visibility_notifier = NodePath("../VisibleOnScreenNotifier2D") +root = NodePath("..") +metadata/_custom_type_script = "uid://1tnr46o1ib4u" + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] +position = Vector2(8, 0) +scale = Vector2(0.8, 0.1) + +[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("root", "launch_component")] +script = ExtResource("4_dolct") +root = NodePath("..") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://cvcnfrr1udco5" + +[node name="LaunchComponent" type="Node2D" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("5_eafpt") +root = NodePath("..") +speed = 64.0 +metadata/_custom_type_script = "uid://873un8agkyja" + +[node name="LifetimeComponent" type="Node" parent="." node_paths=PackedStringArray("root", "timer")] +script = ExtResource("6_m14o3") +root = NodePath("..") +life_time = 10.0 +timer = NodePath("../Timer") +metadata/_custom_type_script = "uid://bvsgg8lu0a8m6" + +[node name="Timer" type="Timer" parent="."] +wait_time = 5.0 +autostart = true diff --git a/scenes/level_village_1.tscn b/scenes/level_village_1.tscn index 48ae3ff..5fed040 100644 --- a/scenes/level_village_1.tscn +++ b/scenes/level_village_1.tscn @@ -92,7 +92,6 @@ top_level = true script = ExtResource("6_18aqg") follow_mode = 2 follow_target = NodePath("../Brick Player") -snap_to_pixel = true tween_resource = SubResource("Resource_0nwt7") draw_limits = true limit_target = NodePath("../Terrain Layer") diff --git a/scripts/components/ship_movement.gd b/scripts/components/ship_movement.gd new file mode 100644 index 0000000..90759b9 --- /dev/null +++ b/scripts/components/ship_movement.gd @@ -0,0 +1,26 @@ +class_name ShipMovement +extends Node + +@export var max_speed: float = 200.0 +@export var acceleration: float = 100.0 +@export var friction: float = 50.0 +@export var body: CharacterBody2D + +var velocity: Vector2 = Vector2.ZERO + + +func _physics_process(delta: float) -> void: + var input_vector := Vector2( + Input.get_action_strength("right") - Input.get_action_strength("left"), + Input.get_action_strength("down") - Input.get_action_strength("up") + ).normalized() + + if input_vector != Vector2.ZERO: + velocity = velocity.move_toward(input_vector * max_speed, acceleration * delta) + else: + velocity = velocity.move_toward(Vector2.ZERO, friction * delta) + + velocity = velocity.limit_length(max_speed) + body.velocity = velocity + body.move_and_slide() + \ No newline at end of file diff --git a/scripts/components/ship_movement.gd.uid b/scripts/components/ship_movement.gd.uid new file mode 100644 index 0000000..cc54df9 --- /dev/null +++ b/scripts/components/ship_movement.gd.uid @@ -0,0 +1 @@ +uid://b3mrdvre1y567 diff --git a/scripts/components/ship_shooter.gd b/scripts/components/ship_shooter.gd new file mode 100644 index 0000000..98ae738 --- /dev/null +++ b/scripts/components/ship_shooter.gd @@ -0,0 +1,33 @@ +class_name ShipShooter +extends Node + +@export var bullet_scene: PackedScene +@export var fire_rate: float = 0.2 +@export var bullet_spawn: Marker2D +@export var shoot_sfx: AudioStreamPlayer2D + +var can_shoot: bool = true + + +func _process(_delta: float) -> void: + if Input.is_action_just_pressed("attack") and can_shoot: + shoot() + + +func shoot() -> void: + if not can_shoot: + return + + var bullet: Node2D = bullet_scene.instantiate() + var init := bullet.get_node_or_null("ProjectileInitComponent") as ProjectileInitComponent + if init: + init.initialize({ + "position": bullet_spawn.global_position, + }) + get_tree().current_scene.add_child(bullet) + if shoot_sfx: + shoot_sfx.play() + + can_shoot = false + await get_tree().create_timer(fire_rate).timeout + can_shoot = true \ No newline at end of file diff --git a/scripts/components/ship_shooter.gd.uid b/scripts/components/ship_shooter.gd.uid new file mode 100644 index 0000000..d244698 --- /dev/null +++ b/scripts/components/ship_shooter.gd.uid @@ -0,0 +1 @@ +uid://d1ctdx52gskv1