forked from kanium/starcheese
I should commit more often
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
extends Node2D
|
||||
|
||||
@export var hardpoint_id: String = "HardPoint1" # Unique identifier for this hardpoint
|
||||
|
||||
# Optional - can store a reference to the mounted weapon
|
||||
var mounted_weapon: Node2D = null
|
||||
|
||||
# Method to attach a weapon to the hardpoint
|
||||
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
|
||||
|
||||
func _draw():
|
||||
draw_circle(Vector2.ZERO, 10, Color(1, 0, 0)) # Draw a red circle at the hardpoint
|
||||
|
||||
func _ready():
|
||||
add_to_group("hardpoints") # Add the hardpoint to the "hardpoints" group
|
||||
queue_redraw() # Redraw the visual to ensure it's updated
|
||||
@@ -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")
|
||||
@@ -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)
|
||||
@@ -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")
|
||||
@@ -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")
|
||||
@@ -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()
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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")
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user