diff --git a/README.md b/README.md index 76257b4..2cf02c0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # StarCheese - The Final Fromage -StarCheese is a small game project made in the Godot engine, specifically Godot 4.2.2 Stable (which might change) \ No newline at end of file +StarCheese is a small game project made in the Godot engine, specifically Godot 4.2.2 Stable (which might change) diff --git a/images/32blacksquare.png b/images/32blacksquare.png new file mode 100644 index 0000000..21b7d76 Binary files /dev/null and b/images/32blacksquare.png differ diff --git a/images/32blacksquare.png.import b/images/32blacksquare.png.import new file mode 100644 index 0000000..7b96e03 --- /dev/null +++ b/images/32blacksquare.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ciy0e5x055p51" +path="res://.godot/imported/32blacksquare.png-4ebf2398d9deb7b95f7724d503d45993.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://images/32blacksquare.png" +dest_files=["res://.godot/imported/32blacksquare.png-4ebf2398d9deb7b95f7724d503d45993.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/images/dot.png b/images/dot.png new file mode 100644 index 0000000..2e16b84 Binary files /dev/null and b/images/dot.png differ diff --git a/images/dot.png.import b/images/dot.png.import new file mode 100644 index 0000000..4c779cd --- /dev/null +++ b/images/dot.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c3o1ttqdwn30x" +path.s3tc="res://.godot/imported/dot.png-33c725e4dcea1d588eb81ca554765516.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://images/dot.png" +dest_files=["res://.godot/imported/dot.png-33c725e4dcea1d588eb81ca554765516.s3tc.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/images/sparkle.png b/images/sparkle.png new file mode 100644 index 0000000..af2b74e Binary files /dev/null and b/images/sparkle.png differ diff --git a/images/sparkle.png.import b/images/sparkle.png.import new file mode 100644 index 0000000..c264c1b --- /dev/null +++ b/images/sparkle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ck4bdea7gygiy" +path="res://.godot/imported/sparkle.png-bba60cb338ecc797d98a52c40cce2293.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://images/sparkle.png" +dest_files=["res://.godot/imported/sparkle.png-bba60cb338ecc797d98a52c40cce2293.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/images/white_glowing_circle.png b/images/white_glowing_circle.png new file mode 100644 index 0000000..5d34a03 Binary files /dev/null and b/images/white_glowing_circle.png differ diff --git a/images/white_glowing_circle.png.import b/images/white_glowing_circle.png.import new file mode 100644 index 0000000..5e548ef --- /dev/null +++ b/images/white_glowing_circle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://crpe745kqyxhg" +path="res://.godot/imported/white_glowing_circle.png-76499b4ab0ce3075586e96e9632fd006.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://images/white_glowing_circle.png" +dest_files=["res://.godot/imported/white_glowing_circle.png-76499b4ab0ce3075586e96e9632fd006.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/laser.gd b/laser.gd deleted file mode 100644 index 4b716b4..0000000 --- a/laser.gd +++ /dev/null @@ -1,74 +0,0 @@ -extends Node2D - -@export var laser_range: float = 800.0 -@export var laser_damage: float = 0.2 -@export var hardpoint_id: String = "HardPoint1" # Identifier for the hardpoint to attach this laser - -var hardpoint = null # Reference to the attached hardpoint -var is_firing = false # Track the laser's firing state -var current_damage_output: float = 0.0 # Track the current damage output -var event_bus: EventBus - -func _ready(): - # Register the laser to the "weapons" group - add_to_group("weapons") - # Connect to the correct hardpoint when ready - call_deferred("_connect_to_hardpoint") - event_bus = get_node("/root/Main/MainEventBus") - - # Initialize LaserLine2D with two points (origin and target) - $LaserLine2D.clear_points() - $LaserLine2D.add_point(Vector2.ZERO) # Origin point - $LaserLine2D.add_point(Vector2.ZERO) # Target point (initially the same as origin) - $DamageOutputLabel.text = str(current_damage_output) - -# Connect the laser to the appropriate hardpoint -func _connect_to_hardpoint(): - var hardpoints = get_tree().get_nodes_in_group("hardpoints") - for h in hardpoints: - if h.hardpoint_id == hardpoint_id: - hardpoint = h - h.attach_weapon(self) - break - - -func fire(): - is_firing = true - current_damage_output = laser_damage - $DamageOutputLabel.text = str(current_damage_output) - _process_laser(true) - - -func cease_fire(): - is_firing = false - current_damage_output = 0.0 - $DamageOutputLabel.text = str(current_damage_output) - _process_laser(false) - -func _process(delta: float) -> void: - if is_firing: - _process_laser(true) - - -func _process_laser(active: bool): - var raycast = $LaserBeam2D - raycast.enabled = active - - if active: - raycast.force_raycast_update() - - if raycast.is_colliding(): - var collision_point = raycast.get_collision_point() - $LaserLine2D.set_point_position(0, Vector2.ZERO) - $LaserLine2D.set_point_position(1, to_local(collision_point)) - - var collider = raycast.get_collider() - if collider: - var damage_event = DamageEvent.new(laser_damage, collider) - event_bus.publish(get_node("/root/Main/DamageEventScope"), damage_event) - else: - $LaserLine2D.set_point_position(1, Vector2(0, -laser_range)) - else: - $LaserLine2D.clear_points() - $LaserLine2D.add_point(Vector2.ZERO) - $LaserLine2D.add_point(Vector2.ZERO) diff --git a/main.gd b/main.gd index ebb22cf..11a3036 100644 --- a/main.gd +++ b/main.gd @@ -31,7 +31,7 @@ func _ready() -> void: pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: +func _process(_delta: float) -> void: var actions = [ "ui_fire", "ui_up", diff --git a/main.tscn b/main.tscn index 122934a..1bb12c9 100644 --- a/main.tscn +++ b/main.tscn @@ -1,22 +1,10 @@ -[gd_scene load_steps=11 format=3 uid="uid://8ocp10j32f62"] +[gd_scene load_steps=5 format=3 uid="uid://8ocp10j32f62"] [ext_resource type="Script" path="res://main.gd" id="1_eedai"] [ext_resource type="Texture2D" uid="uid://y6phkg4twpdm" path="res://images/bg_space_seamless.png" id="1_rpyi5"] -[ext_resource type="Texture2D" uid="uid://cran7fr1i2qou" path="res://images/spaceship-placeholder.png" id="2_f2x66"] -[ext_resource type="Script" path="res://spaceship.gd" id="3_ttkgl"] -[ext_resource type="Script" path="res://laser.gd" id="4_uhf7q"] -[ext_resource type="Texture2D" uid="uid://bxgw2u7j4b634" path="res://images/laser_turret.png" id="6_qxhyw"] -[ext_resource type="Script" path="res://hardpoint.gd" id="7_6cr6a"] +[ext_resource type="PackedScene" uid="uid://dej58eek7fudd" path="res://spaceship.tscn" id="3_h8rrl"] [ext_resource type="Script" path="res://spawn_asteroid_button.gd" id="9_21dg0"] -[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_3vtwu"] -radius = 48.0 -height = 102.0 - -[sub_resource type="Gradient" id="Gradient_sx4rn"] -offsets = PackedFloat32Array(0.961735, 1) -colors = PackedColorArray(1, 1, 0, 1, 1, 1, 1, 0.137255) - [node name="Main" type="Node2D"] script = ExtResource("1_eedai") @@ -24,52 +12,9 @@ script = ExtResource("1_eedai") position = Vector2(955, 537) scale = Vector2(2, 2) texture = ExtResource("1_rpyi5") +metadata/_edit_lock_ = true -[node name="spaceship" type="CharacterBody2D" parent="."] -position = Vector2(956, 623) -collision_layer = 2 -motion_mode = 1 -script = ExtResource("3_ttkgl") - -[node name="Sprite2D" type="Sprite2D" parent="spaceship"] -z_index = 1 -texture = ExtResource("2_f2x66") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="spaceship"] -position = Vector2(0, 6) -rotation = -3.14159 -shape = SubResource("CapsuleShape2D_3vtwu") - -[node name="Laser1" type="Node2D" parent="spaceship"] -light_mask = 2 -position = Vector2(95, -159) -script = ExtResource("4_uhf7q") - -[node name="LaserSprite2D" type="Sprite2D" parent="spaceship/Laser1"] -position = Vector2(0, -5) -texture = ExtResource("6_qxhyw") - -[node name="LaserBeam2D" type="RayCast2D" parent="spaceship/Laser1"] -position = Vector2(0, -17) -target_position = Vector2(0, -800) -collide_with_areas = true - -[node name="LaserLine2D" type="Line2D" parent="spaceship/Laser1"] -points = PackedVector2Array(0, 0, 0, 0) -default_color = Color(1, 1, 0, 0.54902) -gradient = SubResource("Gradient_sx4rn") -texture_mode = 2 -joint_mode = 2 - -[node name="DamageOutputLabel" type="Label" parent="spaceship/Laser1"] -offset_left = 18.0 -offset_top = -71.0 -offset_right = 104.0 -offset_bottom = -20.0 - -[node name="HardPoint1" type="Node2D" parent="spaceship"] -position = Vector2(0, -46) -script = ExtResource("7_6cr6a") +[node name="spaceship" parent="." instance=ExtResource("3_h8rrl")] [node name="SpawnAsteroidButton" type="Button" parent="."] offset_left = 72.0 diff --git a/project.godot b/project.godot index bbc0fb8..06caccc 100644 --- a/project.godot +++ b/project.godot @@ -27,6 +27,11 @@ ui_fire={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +fire_weapon={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(133, 15),"global_position":Vector2(142, 61),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [layer_names] diff --git a/spaceship.gd b/spaceship.gd index c822f60..208c6d7 100644 --- a/spaceship.gd +++ b/spaceship.gd @@ -4,9 +4,7 @@ extends CharacterBody2D @export var max_speed: float = 1500.0 @export var rotation_speed: float = 3.0 @export var friction: float = 0.99 - -signal fire # Signal to start firing -signal stop_fire # Signal to stop firing +@onready var laser := $WeaponsSystem/mining_beam_turret/mining_beam var weapons_system: WeaponsSystem var event_bus: EventBus @@ -14,7 +12,7 @@ func _ready(): weapons_system = get_node("/root/Main/WeaponsSystem") event_bus = get_node("/root/Main/MainEventBus") event_bus.subscribe_to(get_node("/root/Main/InputEventScope"), "KeyboardInputEvent", Callable(self, "handle_keyboard_input")) - + func get_spaceship_orientation_vector() -> Vector2: return -global_transform.y @@ -22,11 +20,11 @@ func handle_movement(delta: float) -> void: var thrust = Vector2.ZERO if Input.is_action_pressed("ui_up"): - thrust = Vector2(0, -1).rotated(rotation) * acceleration * delta + thrust = Vector2(1, 0).rotated(rotation) * acceleration * delta velocity += thrust if Input.is_action_pressed("ui_down"): - thrust = Vector2(0, 1).rotated(rotation) * acceleration * delta + thrust = Vector2(-1, 0).rotated(rotation) * acceleration * delta velocity += thrust if Input.is_action_pressed("ui_left"): @@ -35,7 +33,6 @@ func handle_movement(delta: float) -> void: if Input.is_action_pressed("ui_right"): rotation += rotation_speed * delta - # Clamp velocity and apply friction velocity = velocity.clamp(Vector2(-max_speed, -max_speed), Vector2(max_speed, max_speed)) velocity *= friction @@ -47,14 +44,17 @@ func handle_movement(delta: float) -> void: var collision_normal = collision.get_normal() velocity = velocity.slide(collision_normal) +func _unhandled_input(event: InputEvent) -> void: + if not event.is_action("fire_weapon"): + return + laser.is_casting = event.is_action_pressed("fire_weapon") + func handle_keyboard_input(event: KeyboardInputEvent): - if( event.action == "ui_fire" ): - if( event.pressed ): + if event.action == "ui_fire": + if event.pressed: weapons_system.fire_all() else: weapons_system.cease_fire_all() - - pass func _process(delta: float) -> void: handle_movement(delta) diff --git a/spaceship.tscn b/spaceship.tscn new file mode 100644 index 0000000..8e81aaf --- /dev/null +++ b/spaceship.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=6 format=3 uid="uid://dej58eek7fudd"] + +[ext_resource type="Script" path="res://spaceship.gd" id="1_bwnho"] +[ext_resource type="PackedScene" uid="uid://kke1bgv1bvht" path="res://src/vessels/weapons/beams/mining/mining_beam_turret.tscn" id="2_4ub4i"] +[ext_resource type="Texture2D" uid="uid://cran7fr1i2qou" path="res://images/spaceship-placeholder.png" id="3_xxo2y"] +[ext_resource type="Script" path="res://src/vessels/systems/weapons_system.gd" id="4_w4ss2"] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_3vtwu"] +radius = 48.0 +height = 102.0 + +[node name="spaceship" type="CharacterBody2D"] +position = Vector2(956, 623) +collision_layer = 2 +motion_mode = 1 +script = ExtResource("1_bwnho") + +[node name="WeaponsSystem" type="Node" parent="."] +script = ExtResource("4_w4ss2") + +[node name="mining_beam_turret" parent="WeaponsSystem" instance=ExtResource("2_4ub4i")] +position = Vector2(1009, 623) + +[node name="Sprite2D" type="Sprite2D" parent="."] +z_index = 1 +rotation = 1.5708 +texture = ExtResource("3_xxo2y") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CapsuleShape2D_3vtwu") diff --git a/hardpoint.gd b/src/vessels/components/hardpoints/hardpoint.gd similarity index 88% rename from hardpoint.gd rename to src/vessels/components/hardpoints/hardpoint.gd index 228b5b7..20b3fec 100644 --- a/hardpoint.gd +++ b/src/vessels/components/hardpoints/hardpoint.gd @@ -9,7 +9,7 @@ var mounted_weapon: Node2D = null func attach_weapon(weapon: Node2D) -> void: mounted_weapon = weapon weapon.global_position = global_position # Set weapon position to the hardpoint position - weapon.rotation = rotation # Align the weapon's rotation to the hardpoint's rotation + #weapon.rotation = rotation # Align the weapon's rotation to the hardpoint's rotation func _draw(): draw_circle(Vector2.ZERO, 10, Color(1, 0, 0)) # Draw a red circle at the hardpoint diff --git a/src/vessels/components/hardpoints/hardpoint.tscn b/src/vessels/components/hardpoints/hardpoint.tscn new file mode 100644 index 0000000..678d144 --- /dev/null +++ b/src/vessels/components/hardpoints/hardpoint.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://detjgwvlxhxhk"] + +[ext_resource type="Script" path="res://src/vessels/components/hardpoints/hardpoint.gd" id="1_sd20m"] +[ext_resource type="Texture2D" uid="uid://ciy0e5x055p51" path="res://images/32blacksquare.png" id="2_d8vdx"] + +[node name="Hardpoint" type="Node2D"] +script = ExtResource("1_sd20m") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("2_d8vdx") diff --git a/src/vessels/hulls/base_hull.gd b/src/vessels/hulls/base_hull.gd new file mode 100644 index 0000000..076fa5f --- /dev/null +++ b/src/vessels/hulls/base_hull.gd @@ -0,0 +1,64 @@ +extends CharacterBody2D + +@export var acceleration: float = 400.0 +@export var max_speed: float = 1500.0 +@export var rotation_speed: float = 3.0 +@export var friction: float = 0.99 + +var weapons_system: WeaponsSystem +var event_bus: EventBus +func _ready(): + weapons_system = get_node("/root/Main/WeaponsSystem") + event_bus = get_node("/root/Main/MainEventBus") + event_bus.subscribe_to(get_node("/root/Main/InputEventScope"), "KeyboardInputEvent", Callable(self, "handle_keyboard_input")) + + +func get_spaceship_orientation_vector() -> Vector2: + return -global_transform.y + +func handle_movement(delta: float) -> void: + var thrust = Vector2.ZERO + + if Input.is_action_pressed("ui_up"): + thrust = Vector2(1, 0).rotated(rotation) * acceleration * delta + velocity += thrust + + if Input.is_action_pressed("ui_down"): + thrust = Vector2(-1, 0).rotated(rotation) * acceleration * delta + velocity += thrust + + if Input.is_action_pressed("ui_left"): + rotation -= rotation_speed * delta + + if Input.is_action_pressed("ui_right"): + rotation += rotation_speed * delta + + # Clamp velocity and apply friction + velocity = velocity.clamp(Vector2(-max_speed, -max_speed), Vector2(max_speed, max_speed)) + velocity *= friction + + var collision = move_and_collide(velocity * delta) + + if collision: + print("Collided with: ", collision.get_collider().name) + + var collision_normal = collision.get_normal() + velocity = velocity.slide(collision_normal) + +#func _unhandled_input(event: InputEvent) -> void: +# if not event.is_action("fire_weapon"): +# return + #laser.is_casting = event.is_action_pressed("fire_weapon") +# pass + +func handle_keyboard_input(event: KeyboardInputEvent): + if( event.action == "ui_fire" ): + if( event.pressed ): + weapons_system.fire_all() + else: + weapons_system.cease_fire_all() + + pass + +func _process(delta: float) -> void: + handle_movement(delta) diff --git a/src/vessels/hulls/base_hull.tscn b/src/vessels/hulls/base_hull.tscn new file mode 100644 index 0000000..5a5de78 --- /dev/null +++ b/src/vessels/hulls/base_hull.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://b1goask3ynem3"] + +[ext_resource type="Texture2D" uid="uid://cran7fr1i2qou" path="res://images/spaceship-placeholder.png" id="1_2uldm"] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_3vtwu"] +radius = 48.0 +height = 102.0 + +[node name="spaceship" type="CharacterBody2D"] +position = Vector2(956, 623) +collision_layer = 2 +motion_mode = 1 + +[node name="Sprite2D" type="Sprite2D" parent="."] +z_index = 1 +rotation = 1.5708 +texture = ExtResource("1_2uldm") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CapsuleShape2D_3vtwu") diff --git a/src/vessels/systems/weapons_system.gd b/src/vessels/systems/weapons_system.gd new file mode 100644 index 0000000..128519f --- /dev/null +++ b/src/vessels/systems/weapons_system.gd @@ -0,0 +1,8 @@ +class_name WeaponsSystem +extends Node + +func fire_all(): + get_tree().call_group("turrets", "fire") + +func cease_fire_all(): + get_tree().call_group("turrets", "cease_fire") diff --git a/src/vessels/weapons/beams/base_beam.gd b/src/vessels/weapons/beams/base_beam.gd new file mode 100644 index 0000000..a14ff49 --- /dev/null +++ b/src/vessels/weapons/beams/base_beam.gd @@ -0,0 +1,87 @@ +# Casts a laser along a raycast, emitting particles on the impact point. +# Use `is_casting` to make the laser fire and stop. +# You can attach it to a weapon or a ship; the laser will rotate with its parent. +extends RayCast2D + +# Speed at which the laser extends when first fired, in pixels per seconds. +@export var cast_speed := 70000.0 +# Maximum length of the laser in pixels. +@export var max_length := 1400.0 +# Base duration of the tween animation in seconds. +@export var growth_time := 0.1 + + + +# If `true`, the laser is firing. +# It plays appearing and disappearing animations when it's not animating. +# See `appear()` and `disappear()` for more information. +var is_casting := false: set = set_is_casting + +@onready var fill : Line2D = $FillLine2D +var tween : Tween +@onready var casting_particles := $CastingParticles2D +@onready var collision_particles := $CollisionParticles2D +@onready var beam_particles := $BeamParticles2D + +@onready var line_width: float = fill.width + + +func _ready() -> void: + set_physics_process(false) + fill.points[1] = Vector2.ZERO + + + +func _physics_process(delta: float) -> void: + target_position = (target_position + Vector2.RIGHT * cast_speed * delta).limit_length(max_length) + cast_beam() + + +func set_is_casting(cast: bool) -> void: + is_casting = cast + + if is_casting: + target_position = Vector2.ZERO + fill.points[1] = target_position + appear() + else: + # Reset the laser endpoint + fill.points[1] = Vector2.ZERO + + collision_particles.emitting = false + disappear() + + set_physics_process(is_casting) + beam_particles.emitting = is_casting + casting_particles.emitting = is_casting + + +# Controls the emission of particles and extends the Line2D to `cast_to` or the ray's +# collision point, whichever is closest. +func cast_beam() -> void: + var cast_point := target_position + + force_raycast_update() + collision_particles.emitting = is_colliding() + + if is_colliding(): + cast_point = to_local(get_collision_point()) + collision_particles.global_rotation = get_collision_normal().angle() + collision_particles.position = cast_point + + fill.points[1] = cast_point + beam_particles.position = cast_point * 0.5 + beam_particles.process_material.emission_box_extents.x = cast_point.length() * 0.5 + + +func appear() -> void: + if tween and tween.is_running(): + tween.kill() + tween = create_tween() + tween.tween_property(fill, "width", line_width, growth_time * 2).from(0) + +func disappear() -> void: + if tween and tween.is_running(): + tween.kill() + tween = create_tween() + tween.tween_property(fill, "width", 0, growth_time).from_current() diff --git a/src/vessels/weapons/beams/base_beam.tscn b/src/vessels/weapons/beams/base_beam.tscn new file mode 100644 index 0000000..49b7d29 --- /dev/null +++ b/src/vessels/weapons/beams/base_beam.tscn @@ -0,0 +1,104 @@ +[gd_scene load_steps=12 format=3 uid="uid://tldpf6ukiu3f"] + +[ext_resource type="Script" path="res://src/vessels/weapons/beams/base_beam.gd" id="1_fdyd4"] +[ext_resource type="Texture2D" uid="uid://di7nndrreqmtf" path="res://images/glowing_circle.png" id="2_h1jdn"] + +[sub_resource type="Gradient" id="1"] +offsets = PackedFloat32Array(0.582915, 1) +colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0) + +[sub_resource type="GradientTexture2D" id="2"] +gradient = SubResource("1") + +[sub_resource type="Curve" id="3"] +_data = [Vector2(0.518072, 1), 0.0, -3.53434, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="4"] +width = 2048 +curve = SubResource("3") + +[sub_resource type="ParticleProcessMaterial" id="5"] +initial_velocity_min = 100.0 +initial_velocity_max = 100.0 +gravity = Vector3(0, 0, 0) +scale_min = 0.5 +scale_max = 0.5 +scale_curve = SubResource("4") +color_ramp = SubResource("2") + +[sub_resource type="Curve" id="6"] +_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.503614, 0.957505), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 3 + +[sub_resource type="CurveTexture" id="7"] +curve = SubResource("6") + +[sub_resource type="ParticleProcessMaterial" id="8"] +particle_flag_align_y = true +particle_flag_disable_z = true +emission_shape = 3 +emission_box_extents = Vector3(60, 20, 1) +direction = Vector3(-1, 0, 0) +spread = 0.0 +gravity = Vector3(0, 0, 0) +tangential_accel_min = 100.0 +tangential_accel_max = 100.0 +scale_min = 0.3 +scale_max = 0.3 +scale_curve = SubResource("7") + +[sub_resource type="ParticleProcessMaterial" id="9"] +particle_flag_disable_z = true +spread = 50.0 +initial_velocity_min = 300.0 +initial_velocity_max = 300.0 +gravity = Vector3(0, 0, 0) +scale_min = 0.5 +scale_max = 0.5 +scale_curve = SubResource("4") +color_ramp = SubResource("2") + +[node name="BaseBeam2D" type="RayCast2D"] +target_position = Vector2(0, 0) +script = ExtResource("1_fdyd4") + +[node name="FillLine2D" type="Line2D" parent="."] +modulate = Color(1.5, 1.5, 1.5, 1) +points = PackedVector2Array(0, 0, 100, 0) +default_color = Color(0.301961, 0.65098, 1, 1) +texture_mode = 2 +joint_mode = 2 +begin_cap_mode = 2 +end_cap_mode = 2 +sharp_limit = 8.0 +antialiased = true + +[node name="CastingParticles2D" type="GPUParticles2D" parent="."] +modulate = Color(1.5, 1.5, 1.5, 1) +show_behind_parent = true +emitting = false +process_material = SubResource("5") +texture = ExtResource("2_h1jdn") +lifetime = 0.3 +visibility_rect = Rect2(0, -18.722, 29.6756, 38.4841) + +[node name="BeamParticles2D" type="GPUParticles2D" parent="."] +modulate = Color(1.5, 1.5, 1.5, 1) +emitting = false +amount = 50 +process_material = SubResource("8") +texture = ExtResource("2_h1jdn") +preprocess = 1.0 +randomness = 1.0 +visibility_rect = Rect2(-2500, -2500, 5000, 5000) + +[node name="CollisionParticles2D" type="GPUParticles2D" parent="."] +modulate = Color(1.5, 1.5, 1.5, 1) +show_behind_parent = true +emitting = false +amount = 16 +process_material = SubResource("9") +texture = ExtResource("2_h1jdn") +lifetime = 0.3 +visibility_rect = Rect2(-2500, -2500, 5000, 5000) diff --git a/src/vessels/weapons/beams/mining/mining_beam.gd b/src/vessels/weapons/beams/mining/mining_beam.gd new file mode 100644 index 0000000..f8c3df2 --- /dev/null +++ b/src/vessels/weapons/beams/mining/mining_beam.gd @@ -0,0 +1,21 @@ +extends "res://src/vessels/weapons/beams/base_beam.gd" +var event_bus: EventBus +@export var laser_damage: float = 0.8 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + super._ready() + add_to_group("weapons") + event_bus = get_node("/root/Main/MainEventBus") + +func cast_beam() -> void: + super.cast_beam() + if is_colliding(): + var collider = get_collider() + if collider: + var damage_event = DamageEvent.new(laser_damage, collider) + event_bus.publish(get_node("/root/Main/DamageEventScope"), damage_event) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/src/vessels/weapons/beams/mining/mining_beam_turret.tscn b/src/vessels/weapons/beams/mining/mining_beam_turret.tscn new file mode 100644 index 0000000..cece554 --- /dev/null +++ b/src/vessels/weapons/beams/mining/mining_beam_turret.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://kke1bgv1bvht"] + +[ext_resource type="Script" path="res://src/vessels/weapons/beams/mining/mining_turret.gd" id="1_l6ng7"] +[ext_resource type="PackedScene" uid="uid://tldpf6ukiu3f" path="res://src/vessels/weapons/beams/base_beam.tscn" id="2_litw1"] +[ext_resource type="Script" path="res://src/vessels/weapons/beams/mining/mining_beam.gd" id="3_orfy2"] +[ext_resource type="Texture2D" uid="uid://bxgw2u7j4b634" path="res://images/laser_turret.png" id="4_ut0ve"] + +[node name="mining_beam_turret" type="Node2D"] +script = ExtResource("1_l6ng7") + +[node name="mining_beam" parent="." instance=ExtResource("2_litw1")] +position = Vector2(14, 0) +script = ExtResource("3_orfy2") +laser_damage = 0.8 + +[node name="turret" type="Sprite2D" parent="."] +position = Vector2(-3, -0.0834265) +rotation = 1.5708 +scale = Vector2(1.50815, 1.37222) +texture = ExtResource("4_ut0ve") diff --git a/src/vessels/weapons/beams/mining/mining_turret.gd b/src/vessels/weapons/beams/mining/mining_turret.gd new file mode 100644 index 0000000..646d732 --- /dev/null +++ b/src/vessels/weapons/beams/mining/mining_turret.gd @@ -0,0 +1,14 @@ +extends Node2D +@onready var mining_beam := $mining_beam +var event_bus: EventBus + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + event_bus = get_node("/root/Main/MainEventBus") + add_to_group("turrets") # Add this turret to the "turrets" group + +func fire(): + mining_beam.is_casting = true + +func cease_fire(): + mining_beam.is_casting = false diff --git a/test_object.gd b/test_object.gd new file mode 100644 index 0000000..8ff8c3e --- /dev/null +++ b/test_object.gd @@ -0,0 +1,13 @@ +extends Node2D + +@onready var laser := $LaserBeam2D + + +func _process(_delta: float) -> void: + look_at(get_global_mouse_position()) + + +func _unhandled_input(event: InputEvent) -> void: + if not event.is_action("fire_weapon"): + return + laser.is_casting = event.is_action_pressed("fire_weapon") diff --git a/weapons_system.gd b/weapons_system.gd deleted file mode 100644 index 23e70e2..0000000 --- a/weapons_system.gd +++ /dev/null @@ -1,16 +0,0 @@ -class_name WeaponsSystem -extends Node - -var weapons = [] - - -func _ready(): - pass - - -func fire_all(): - get_tree().call_group("weapons", "fire") - - -func cease_fire_all(): - get_tree().call_group("weapons", "cease_fire")