2024-11-26 01:52:12 +00:00
|
|
|
class_name Bullet extends Area2D
|
2024-12-03 01:49:40 +00:00
|
|
|
@onready var bulletSprite: Sprite2D = $Sprite2D
|
2024-11-26 01:52:12 +00:00
|
|
|
|
|
|
|
var speed = 750
|
|
|
|
# did I hit someone?
|
|
|
|
signal hit(bullet, body)
|
|
|
|
|
|
|
|
func setSpeed(speedValue):
|
|
|
|
speed = speedValue
|
2024-12-03 01:49:40 +00:00
|
|
|
if speed <0:
|
|
|
|
bulletSprite.flip_h = true
|
|
|
|
else:
|
|
|
|
bulletSprite.flip_h = false
|
2024-11-26 01:52:12 +00:00
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
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)
|
|
|
|
|