Added splash damage
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://clt20ebs6shkm
|
||||
@@ -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="."]
|
||||
Reference in New Issue
Block a user