LaserWeapon reworked to hitscan

This commit is contained in:
2025-12-22 16:45:22 +03:00
parent 77981194dd
commit e5155584dd
23 changed files with 190 additions and 174 deletions
@@ -49,19 +49,13 @@ texture = SubResource("AtlasTexture_qawoi")
material = SubResource("ShaderMaterial_6d574")
texture = SubResource("AtlasTexture_c4do6")
[node name="CollisionPolygon2D" parent="." index="3"]
polygon = PackedVector2Array(-31, 2, -31, -2, -17, -19, -11, -22, 8, -23, 30, -23, 30, 23, 8, 23, -11, 22, -17, 19)
[node name="VisibleOnScreenNotifier2D" parent="." index="5"]
rect = Rect2(-29, -21, 58, 42)
[node name="Health" parent="." index="6"]
max_hull = 200
[node name="HealthBar" parent="Ship" index="7"]
[node name="HealthBar" parent="Ship" index="3"]
offset_top = 27.0
offset_bottom = 27.0
[node name="Health" parent="." index="1"]
max_hull = 200
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
position = Vector2(-8, 0)
@@ -71,5 +65,11 @@ position = Vector2(8, -16)
[node name="Third" type="Node2D" parent="WeaponSlots" index="2"]
position = Vector2(8, 16)
[node name="DebrisParticles" parent="." index="9"]
[node name="DebrisParticles" parent="." index="3"]
amount = 32
[node name="VisibleOnScreenNotifier2D" parent="." index="5"]
rect = Rect2(-30, -22, 59, 44)
[node name="CollisionPolygon2D" parent="." index="6"]
polygon = PackedVector2Array(-31, 2, -31, -2, -17, -19, -11, -22, 8, -23, 30, -23, 30, 23, 8, 23, -11, 22, -17, 19)
@@ -49,24 +49,24 @@ texture = SubResource("AtlasTexture_om3xa")
material = SubResource("ShaderMaterial_ren2c")
texture = SubResource("AtlasTexture_jorhn")
[node name="CollisionPolygon2D" parent="." index="3"]
polygon = PackedVector2Array(-23, -2, -12, -13, -6, -15, 22, -15, 23, -14, 23, 14, 22, 15, -6, 15, -12, 13, -23, 2)
[node name="VisibleOnScreenNotifier2D" parent="." index="5"]
rect = Rect2(-13, -21, 26, 42)
[node name="Health" parent="." index="6"]
max_hull = 100
[node name="HealthBar" parent="Ship" index="7"]
[node name="HealthBar" parent="Ship" index="3"]
offset_top = 19.0
offset_bottom = 19.0
[node name="Health" parent="." index="1"]
max_hull = 100
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
position = Vector2(4, -8)
[node name="Second" type="Node2D" parent="WeaponSlots" index="1"]
position = Vector2(4, 8)
[node name="DebrisParticles" parent="." index="9"]
[node name="DebrisParticles" parent="." index="3"]
amount = 16
[node name="VisibleOnScreenNotifier2D" parent="." index="5"]
rect = Rect2(-22, -14, 44, 28)
[node name="CollisionPolygon2D" parent="." index="6"]
polygon = PackedVector2Array(-23, -2, -12, -13, -6, -15, 22, -15, 23, -14, 23, 14, 22, 15, -6, 15, -12, 13, -23, 2)
@@ -1,17 +1,32 @@
[gd_scene load_steps=7 format=3 uid="uid://cbf3kumeoqpba"]
[gd_scene load_steps=10 format=3 uid="uid://cbf3kumeoqpba"]
[ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_lt1av"]
[ext_resource type="Script" uid="uid://btcce3nflycrs" path="res://game/entities/ships/enemies/small/small_enemy_ship.gd" id="2_bw04d"]
[ext_resource type="Texture2D" uid="uid://5xn5jkmtbn6v" path="res://images/ships/enemies/small.png" id="3_tb2nn"]
[ext_resource type="Shader" uid="uid://dwh22f35u5qqi" path="res://game/shaders/shield.gdshader" id="4_3asrx"]
[sub_resource type="AtlasTexture" id="AtlasTexture_tb2nn"]
atlas = ExtResource("3_tb2nn")
region = Rect2(0, 0, 32, 16)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_20te2"]
resource_local_to_scene = true
shader = ExtResource("4_3asrx")
shader_parameter/speed = 0.0
shader_parameter/scale = 20.0
shader_parameter/intensity = 1.0
[sub_resource type="AtlasTexture" id="AtlasTexture_3asrx"]
atlas = ExtResource("3_tb2nn")
region = Rect2(0, 16, 32, 16)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_8fhe4"]
resource_local_to_scene = true
shader = ExtResource("4_3asrx")
shader_parameter/speed = 5.0
shader_parameter/scale = 20.0
shader_parameter/intensity = 1.0
[sub_resource type="AtlasTexture" id="AtlasTexture_20te2"]
atlas = ExtResource("3_tb2nn")
region = Rect2(0, 32, 32, 16)
@@ -27,23 +42,25 @@ mass = 100
texture = SubResource("AtlasTexture_tb2nn")
[node name="ArmorSprite" parent="Ship" index="1"]
material = SubResource("ShaderMaterial_20te2")
texture = SubResource("AtlasTexture_3asrx")
[node name="ShieldSprite" parent="Ship" index="2"]
material = SubResource("ShaderMaterial_8fhe4")
texture = SubResource("AtlasTexture_20te2")
[node name="CollisionPolygon2D" parent="." index="3"]
polygon = PackedVector2Array(-3, -7, 12, -7, 15, -4, 15, 4, 12, 7, -3, 7, -15, 1, -15, -1)
[node name="HealthBar" parent="Ship" index="3"]
offset_top = 11.0
offset_bottom = 11.0
[node name="Health" parent="." index="1"]
max_hull = 50
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
position = Vector2(5, 0)
[node name="VisibleOnScreenNotifier2D" parent="." index="5"]
rect = Rect2(-13, -5, 26, 10)
[node name="Health" parent="." index="6"]
max_hull = 50
[node name="HealthBar" parent="Ship" index="7"]
offset_top = 11.0
offset_bottom = 11.0
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
position = Vector2(5, 0)
[node name="CollisionPolygon2D" parent="." index="6"]
polygon = PackedVector2Array(-3, -7, 12, -7, 15, -4, 15, 4, 12, 7, -3, 7, -15, 1, -15, -1)
@@ -5,3 +5,4 @@
[node name="DirectHitProjectile" instance=ExtResource("1_klynw")]
script = ExtResource("2_0vgnq")
damage = null
+1 -1
View File
@@ -47,7 +47,7 @@ func _on_out_of_screen_timer_timeout() -> void:
delete()
func _try_to_damage(body: Node2D, damage: AbstractDamage) -> bool:
static func _try_to_damage(body: Node2D, damage: AbstractDamage) -> bool:
var health_component : Health = body.find_child("Health")
if health_component and health_component.has_method("apply_damage"):
health_component.apply_damage(damage)
@@ -1,19 +0,0 @@
class_name AbstractLaserProjectile
extends AbstractDirectHitProjectile
@onready var particles : GPUParticles2D = $GPUParticles2D
func _ready() -> void:
super._ready()
_update_sprite(_velocity)
func _update_sprite(velocity: Vector2) -> void:
var angle := posmod(floor(rad_to_deg(velocity.angle())), 360)
if angle > 90 and angle < 270:
particles.process_material.direction = Vector3.RIGHT
else:
particles.process_material.direction = Vector3.LEFT
@@ -1 +0,0 @@
uid://bdxq4aflhc8vd
@@ -1,43 +0,0 @@
[gd_scene load_steps=8 format=3 uid="uid://cmni0xrbbfcy5"]
[ext_resource type="PackedScene" uid="uid://cdv5n4t47hr8i" path="res://game/entities/weapons/abstract_direct_hit_projectile.tscn" id="1_3a8fg"]
[ext_resource type="Script" uid="uid://bdxq4aflhc8vd" path="res://game/entities/weapons/laser/abstract_laser_projectile.gd" id="2_je1a2"]
[ext_resource type="Script" uid="uid://c27v705giygv4" path="res://game/data/damage/energy_damage.gd" id="3_ylokk"]
[ext_resource type="Texture2D" uid="uid://dk3t14mrgjmma" path="res://particle_textures/energy_medium.tres" id="4_bytws"]
[sub_resource type="Resource" id="Resource_bytws"]
script = ExtResource("3_ylokk")
value = 2
metadata/_custom_type_script = "uid://c27v705giygv4"
[sub_resource type="CircleShape2D" id="CircleShape2D_ylokk"]
radius = 1.0
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_7dd03"]
resource_local_to_scene = true
particle_flag_disable_z = true
emission_shape = 3
emission_box_extents = Vector3(8, 0, 1)
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 1.0
direction = Vector3(0, 0, 0)
spread = 0.0
gravity = Vector3(0, 0, 0)
[node name="AbstractLaserProjectile" instance=ExtResource("1_3a8fg")]
collision_layer = 0
collision_mask = 0
script = ExtResource("2_je1a2")
damage = SubResource("Resource_bytws")
speed = 500
[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("CircleShape2D_ylokk")
[node name="GPUParticles2D" type="GPUParticles2D" parent="." index="2"]
amount = 16
texture = ExtResource("4_bytws")
lifetime = 0.09999999999999999
fixed_fps = 20
process_material = SubResource("ParticleProcessMaterial_7dd03")
@@ -2,21 +2,46 @@ class_name AbstractLaserWeapon
extends AbstractWeapon
@export var damage : AbstractDamage
@export_range(-100.0, 100.0) var line_texture_speed := 7.0
@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D
@onready var cooldown_timer : Timer = $CooldownTimer
@onready var ray_cast : RayCast2D = $RayCast2D
@onready var line : Line2D = $Line2D
@onready var hit_particles : GPUParticles2D = $HitParticles
func _ready() -> void:
sprite.play(SHOT_ANIMATION)
func shoot(ship_velocity: Vector2) -> bool:
var is_shot := super.shoot(ship_velocity)
if is_shot:
func _process(_delta: float) -> void:
var collision_point: Vector2
ray_cast.force_raycast_update()
if ray_cast.is_colliding():
collision_point = ray_cast.get_collision_point() - global_position
hit_particles.position = collision_point
hit_particles.show()
else:
collision_point = muzzle.position + ray_cast.target_position
hit_particles.hide()
line.clear_points()
line.add_point(muzzle.position)
line.add_point(collision_point)
func shoot(_ship_velocity: Vector2) -> bool:
if not _can_shoot: return false
if ray_cast.is_colliding():
AbstractProjectile._try_to_damage(ray_cast.get_collider(), damage)
_can_shoot = false
cooldown_timer.start()
return is_shot
return true
func _on_cooldown_timer_timeout() -> void:
@@ -1,21 +1,57 @@
[gd_scene load_steps=4 format=3 uid="uid://def1alrel4ioo"]
[gd_scene load_steps=11 format=3 uid="uid://def1alrel4ioo"]
[ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_pki4x"]
[ext_resource type="Script" uid="uid://bxr150at8ul2a" path="res://game/entities/weapons/laser/abstract_laser_weapon.gd" id="2_lbdvb"]
[ext_resource type="Script" uid="uid://c27v705giygv4" path="res://game/data/damage/energy_damage.gd" id="3_2cxn5"]
[ext_resource type="Shader" uid="uid://bndty4otyxb5t" path="res://game/shaders/laser.gdshader" id="4_dsgqp"]
[ext_resource type="Texture2D" uid="uid://b13pk3rgmggc3" path="res://images/projectiles/laser.png" id="4_sanrs"]
[ext_resource type="Texture2D" uid="uid://dk3t14mrgjmma" path="res://particle_textures/energy_medium.tres" id="6_70bnd"]
[sub_resource type="Resource" id="Resource_sanrs"]
script = ExtResource("3_2cxn5")
value = 2
metadata/_custom_type_script = "uid://c27v705giygv4"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_70bnd"]
shader = ExtResource("4_dsgqp")
shader_parameter/speed = 10.0
[sub_resource type="SpriteFrames" id="SpriteFrames_btyhf"]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_12kuh"]
particle_flag_disable_z = true
spread = 180.0
initial_velocity_min = 5.0
initial_velocity_max = 15.0
gravity = Vector3(0, 0, 0)
[node name="AbstractLaserWeapon" instance=ExtResource("1_pki4x")]
script = ExtResource("2_lbdvb")
damage = SubResource("Resource_sanrs")
line_texture_speed = 7.0
bullet_per_shot = 2
type = 2
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"]
[node name="Line2D" type="Line2D" parent="." index="0"]
material = SubResource("ShaderMaterial_70bnd")
width = 4.0
texture = ExtResource("4_sanrs")
texture_mode = 1
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1"]
sprite_frames = SubResource("SpriteFrames_btyhf")
[node name="CooldownTimer" type="Timer" parent="." index="1"]
[node name="CooldownTimer" type="Timer" parent="." index="2"]
process_callback = 0
wait_time = 0.05
one_shot = true
[node name="RayCast2D" type="RayCast2D" parent="." index="4"]
collision_mask = 0
[node name="HitParticles" type="GPUParticles2D" parent="." index="5"]
texture = ExtResource("6_70bnd")
lifetime = 0.2
process_material = SubResource("ParticleProcessMaterial_12kuh")
[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]
@@ -1,2 +0,0 @@
class_name EnemyLaserProjectile
extends AbstractLaserProjectile
@@ -1 +0,0 @@
uid://1tw0n0y7c3n4
@@ -1,25 +0,0 @@
[gd_scene load_steps=4 format=3 uid="uid://cq8vnjrk70iby"]
[ext_resource type="PackedScene" uid="uid://cmni0xrbbfcy5" path="res://game/entities/weapons/laser/abstract_laser_projectile.tscn" id="1_6hudn"]
[ext_resource type="Script" uid="uid://1tw0n0y7c3n4" path="res://game/entities/weapons/laser/enemy_laser_projectile.gd" id="2_2l4gg"]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_2l4gg"]
resource_local_to_scene = true
particle_flag_disable_z = true
emission_shape = 3
emission_box_extents = Vector3(16, 0, 1)
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 1.0
direction = Vector3(-1, 0, 0)
spread = 0.0
gravity = Vector3(0, 0, 0)
[node name="EnemyLaserProjectile" instance=ExtResource("1_6hudn")]
collision_layer = 16
collision_mask = 2
script = ExtResource("2_2l4gg")
direction = Vector2(-1, 0)
[node name="GPUParticles2D" parent="." index="2"]
process_material = SubResource("ParticleProcessMaterial_2l4gg")
@@ -1,8 +1,7 @@
[gd_scene load_steps=10 format=3 uid="uid://mjt8xj8k28vi"]
[gd_scene load_steps=9 format=3 uid="uid://mjt8xj8k28vi"]
[ext_resource type="PackedScene" uid="uid://def1alrel4ioo" path="res://game/entities/weapons/laser/abstract_laser_weapon.tscn" id="1_wwqbk"]
[ext_resource type="Script" uid="uid://bckua73myf5v7" path="res://game/entities/weapons/laser/enemy_laser_weapon.gd" id="2_preya"]
[ext_resource type="PackedScene" uid="uid://cq8vnjrk70iby" path="res://game/entities/weapons/laser/enemy_laser_projectile.tscn" id="3_yr2si"]
[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/ships/weapons.png" id="4_a3m6t"]
[sub_resource type="AtlasTexture" id="AtlasTexture_dggsl"]
@@ -43,12 +42,15 @@ animations = [{
[node name="EnemyLaserWeapon" instance=ExtResource("1_wwqbk")]
script = ExtResource("2_preya")
projectile_scene = ExtResource("3_yr2si")
[node name="AnimatedSprite2D" parent="." index="0"]
[node name="AnimatedSprite2D" parent="." index="1"]
position = Vector2(-3, 0)
sprite_frames = SubResource("SpriteFrames_ga5wd")
animation = &"shot"
[node name="Muzzle" parent="." index="2"]
[node name="Muzzle" parent="." index="3"]
position = Vector2(-5, 0)
[node name="RayCast2D" parent="." index="4"]
target_position = Vector2(-1000, 0)
collision_mask = 2
@@ -1,2 +0,0 @@
class_name PlayerLaserProjectile
extends AbstractLaserProjectile
@@ -1 +0,0 @@
uid://v7pcdd8yxdse
@@ -1,24 +0,0 @@
[gd_scene load_steps=4 format=3 uid="uid://cyskk1kc88lgf"]
[ext_resource type="PackedScene" uid="uid://cmni0xrbbfcy5" path="res://game/entities/weapons/laser/abstract_laser_projectile.tscn" id="1_q67uk"]
[ext_resource type="Script" uid="uid://v7pcdd8yxdse" path="res://game/entities/weapons/laser/player_laser_projectile.gd" id="2_truhp"]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_truhp"]
resource_local_to_scene = true
particle_flag_disable_z = true
emission_shape = 3
emission_box_extents = Vector3(16, 0, 1)
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 1.0
spread = 0.0
gravity = Vector3(0, 0, 0)
[node name="PlayerLaserProjectile" instance=ExtResource("1_q67uk")]
collision_layer = 8
collision_mask = 4
script = ExtResource("2_truhp")
direction = Vector2(1, 0)
[node name="GPUParticles2D" parent="." index="2"]
process_material = SubResource("ParticleProcessMaterial_truhp")
@@ -1,8 +1,7 @@
[gd_scene load_steps=10 format=3 uid="uid://cargptjtnale2"]
[gd_scene load_steps=9 format=3 uid="uid://cargptjtnale2"]
[ext_resource type="PackedScene" uid="uid://def1alrel4ioo" path="res://game/entities/weapons/laser/abstract_laser_weapon.tscn" id="1_nky8c"]
[ext_resource type="Script" uid="uid://824ta0lbinkb" path="res://game/entities/weapons/laser/player_laser_weapon.gd" id="2_oqbns"]
[ext_resource type="PackedScene" uid="uid://cyskk1kc88lgf" path="res://game/entities/weapons/laser/player_laser_projectile.tscn" id="3_62i0g"]
[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/ships/weapons.png" id="4_oaprh"]
[sub_resource type="AtlasTexture" id="AtlasTexture_5c4fv"]
@@ -43,12 +42,15 @@ animations = [{
[node name="PlayerLaserWeapon" instance=ExtResource("1_nky8c")]
script = ExtResource("2_oqbns")
projectile_scene = ExtResource("3_62i0g")
[node name="AnimatedSprite2D" parent="." index="0"]
[node name="AnimatedSprite2D" parent="." index="1"]
position = Vector2(3, 0)
sprite_frames = SubResource("SpriteFrames_geipx")
animation = &"shot"
[node name="Muzzle" parent="." index="2"]
[node name="Muzzle" parent="." index="3"]
position = Vector2(5, 0)
[node name="RayCast2D" parent="." index="4"]
target_position = Vector2(1000, 0)
collision_mask = 4
-2
View File
@@ -146,8 +146,6 @@ func _show_main_menu() -> void:
if _current_passage_scene: _current_passage_scene.queue_free()
if _current_area_map_scene: _current_area_map_scene.queue_free()
SaveManager.save()
get_tree().paused = false
get_tree().change_scene_to_file("res://game/menu/main/title_screen.tscn")
+9
View File
@@ -0,0 +1,9 @@
shader_type canvas_item;
uniform float speed = 0.0;
void fragment() {
vec2 uv = UV;
uv.x -= TIME * speed;
COLOR = texture(TEXTURE, uv);
}
+1
View File
@@ -0,0 +1 @@
uid://bndty4otyxb5t
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b13pk3rgmggc3"
path="res://.godot/imported/laser.png-ae92c84e9eaba1641bfd8913a88317aa.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://images/projectiles/laser.png"
dest_files=["res://.godot/imported/laser.png-ae92c84e9eaba1641bfd8913a88317aa.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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