40 lines
753 B
GDScript
40 lines
753 B
GDScript
class_name Weapon extends Node
|
|
|
|
enum Type {
|
|
MELEE,
|
|
PROJECTILE,
|
|
AOF, # area of effect
|
|
RAY,
|
|
}
|
|
|
|
var effects : Callable
|
|
var durationInMilliseconds : int
|
|
var area: Area2D
|
|
|
|
func onBodyEntered ():
|
|
print('onBodyEntered')
|
|
|
|
func onTimeEnd ():
|
|
print('onTimeEnd')
|
|
|
|
|
|
func _ready() -> void:
|
|
var children = self.get_children()
|
|
for i in children.size():
|
|
if (children[i] is Area2D):
|
|
area = children[i]
|
|
area.connect('body_entered', onBodyEntered)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
set_process(true)
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if (durationInMilliseconds > 0):
|
|
durationInMilliseconds -= delta * 1000
|
|
if durationInMilliseconds <= 0:
|
|
durationInMilliseconds = 0 # Ensure duration doesn't go negative
|
|
set_process(false)
|
|
|