35 lines
750 B
GDScript
35 lines
750 B
GDScript
class_name Bullet extends Area2D
|
|
@onready var bulletSprite: Sprite2D = $Sprite2D
|
|
|
|
|
|
var speed = 400
|
|
# did I hit anyone?
|
|
signal hit(bullet, body)
|
|
|
|
func setSpeed(speedValue):
|
|
speed = speedValue
|
|
if speed < 0:
|
|
bulletSprite.flip_h = true
|
|
else:
|
|
bulletSprite.flip_h = false
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
position += transform.x * speed * delta
|
|
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
print("Bullet hit something")
|
|
if not body.is_in_group("player"):
|
|
hit.emit(self, body)
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
#func _ready() -> void:
|
|
# pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta: float) -> void:
|
|
# pass
|