1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00
Files
Dog-Lynx-And-HCN/scripts/Statemachine/BulletBase.gd
T

34 lines
812 B
GDScript
Raw Normal View History

2025-08-26 11:39:47 +08:00
extends Area2D
class_name BulletBase
@export var speed: float = 1
@export var damage: float = 10
var launcher: EntityBase = null
func _ready():
area_entered.connect(hit)
func hit(target: Node):
var entity: EntityBase = EntityTool.fromHurtbox(target)
if !entity || !launcher: return
if entity == launcher: return
if GameRule.allowFriendlyFire:
if entity.isPlayer() == launcher.isPlayer(): return
entity.takeDamage(self)
static func generate(
bullet: PackedScene,
launchBy: EntityBase,
spawnPosition: Vector2,
spawnRotation: float,
addToWorld: bool = true
):
var instance: BulletBase = bullet.instantiate()
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation
if addToWorld:
WorldTool.rootNode.add_child(instance)
return instance