Reworked weapons and projectiles

This commit is contained in:
2025-12-20 18:35:27 +03:00
parent 2ecc53416a
commit 8227e8bcf3
312 changed files with 2466 additions and 1376 deletions
+61
View File
@@ -0,0 +1,61 @@
class_name Blast
extends Area2D
const FALLOFF_FACTOR = 3
@export var damage : AbstractDamage
@export var shape : CircleShape2D
@onready var collision : CollisionShape2D = $CollisionShape2D
func _ready() -> void:
if collision and shape:
collision.shape = shape
func get_damage_to(body: Node2D) -> AbstractDamage:
var distance := _get_distance_to(body)
var damage_dub := damage.duplicate()
var factor := _get_damage_factor(distance)
damage_dub.value = round(damage_dub.value * factor)
return damage_dub
func _get_distance_to(body: Node2D) -> float:
if not shape: return INF
var space_state := get_world_2d().direct_space_state
var query := PhysicsShapeQueryParameters2D.new()
var circle_shape := CircleShape2D.new()
query.shape = circle_shape
query.transform = Transform2D(0, global_position)
query.collide_with_areas = false
query.collide_with_bodies = true
query.collision_mask = collision_mask
query.exclude = [self]
#TODO optimize by binary search
for radius in range(shape.radius + 1):
circle_shape.radius = radius
var results := space_state.intersect_shape(query)
for result in results:
if result["collider"] == body:
return radius
return INF
func _get_damage_factor(distance: float) -> float:
if not shape: return 0.0
var coef := distance / shape.radius
if coef > 1:
return 0.0
return 1 - coef * coef * coef
+1
View File
@@ -0,0 +1 @@
uid://clt20ebs6shkm
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://pfvs7wqrnn08"]
[ext_resource type="Script" uid="uid://clt20ebs6shkm" path="res://game/entities/explosions/blast.gd" id="1_2fpxy"]
[node name="Blast" type="Area2D"]
script = ExtResource("1_2fpxy")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
@@ -0,0 +1,39 @@
class_name ExplosionParticles
extends Node2D
signal finished
@export var process_material: ParticleProcessMaterial
@export_range(0, 1) var amount_ratio: float = 1
var _emiting_count := 0
var emitting : bool = false:
set(value):
emitting = value
if particles_huge: particles_huge.emitting = emitting; _emiting_count += 1
if particles_large: particles_large.emitting = emitting; _emiting_count += 1
if particles_medium: particles_medium.emitting = emitting; _emiting_count += 1
@onready var particles_huge : GPUParticles2D = $ParticlesHuge
@onready var particles_large : GPUParticles2D = $ParticlesLarge
@onready var particles_medium : GPUParticles2D = $ParticlesMedium
func _ready() -> void:
particles_huge.amount_ratio = amount_ratio
particles_large.amount_ratio = amount_ratio
particles_medium.amount_ratio = amount_ratio
particles_huge.process_material = process_material
particles_large.process_material = process_material
particles_medium.process_material = process_material
func _on_particles_finished() -> void:
_emiting_count -= 1
if _emiting_count == 0:
finished.emit()
@@ -0,0 +1 @@
uid://dhnjdam04g4tb
@@ -0,0 +1,47 @@
[gd_scene load_steps=6 format=3 uid="uid://bhxib2ltpkcbf"]
[ext_resource type="Texture2D" uid="uid://gh7mwehpqfco" path="res://particle_textures/flame_medium.tres" id="1_6awlt"]
[ext_resource type="Script" uid="uid://dhnjdam04g4tb" path="res://game/entities/explosions/explosion_particles.gd" id="1_w1d42"]
[ext_resource type="Texture2D" uid="uid://b13al44e8ofsx" path="res://particle_textures/flame_large.tres" id="2_w1d42"]
[ext_resource type="Texture2D" uid="uid://blp4o1c7y66wv" path="res://particle_textures/flame_huge.tres" id="3_lplfr"]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_w1d42"]
lifetime_randomness = 0.2
particle_flag_disable_z = true
emission_shape = 1
emission_sphere_radius = 1.0
angle_min = -179.99998
angle_max = 180.00002
spread = 180.0
gravity = Vector3(0, 0, 0)
turbulence_enabled = true
turbulence_noise_speed = Vector3(0.1, 0.1, 0.1)
[node name="ExplosionParticles" type="Node2D"]
script = ExtResource("1_w1d42")
process_material = SubResource("ParticleProcessMaterial_w1d42")
[node name="ParticlesMedium" type="GPUParticles2D" parent="."]
emitting = false
amount = 512
texture = ExtResource("1_6awlt")
lifetime = 0.25
one_shot = true
[node name="ParticlesLarge" type="GPUParticles2D" parent="."]
emitting = false
amount = 512
texture = ExtResource("2_w1d42")
lifetime = 0.25
one_shot = true
[node name="ParticlesHuge" type="GPUParticles2D" parent="."]
emitting = false
amount = 512
texture = ExtResource("3_lplfr")
lifetime = 0.25
one_shot = true
[connection signal="finished" from="ParticlesMedium" to="." method="_on_particles_finished"]
[connection signal="finished" from="ParticlesLarge" to="." method="_on_particles_finished"]
[connection signal="finished" from="ParticlesHuge" to="." method="_on_particles_finished"]