Added splash damage

This commit is contained in:
2025-11-16 23:18:45 +03:00
parent 5adbdd6e54
commit cf7e6d13ef
19 changed files with 147 additions and 43 deletions
+40
View File
@@ -0,0 +1,40 @@
class_name Blast
extends Area2D
@export var damage : AbstractDamage
@export var shape : CircleShape2D
const FALLOFF_FACTOR = 3
@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 = damage_dub.value * factor
return damage_dub
func _get_distance_to(body: Node2D) -> float:
return global_position.distance_to(body.global_position)
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/other/blast.gd" id="1_2fpxy"]
[node name="Blast" type="Area2D"]
script = ExtResource("1_2fpxy")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]