25 lines
563 B
GDScript
25 lines
563 B
GDScript
class_name Bullet extends Area2D
|
|
@onready var bullet_graphic: Sprite2D = $bullet_graphic
|
|
|
|
|
|
var speed: float = 700
|
|
signal bulletDamageSignal(target: Node2D, bullet: Node2D)
|
|
|
|
func setSpeed(value: float):
|
|
speed = value
|
|
if value<0:
|
|
bullet_graphic.flip_h = true
|
|
if value>0:
|
|
bullet_graphic.flip_h= false
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
position+=transform.x*speed*delta
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
if body is Player:
|
|
return
|
|
print("emit?")
|
|
if body is Crate && visible:
|
|
print("emit")
|
|
bulletDamageSignal.emit(body, self)
|