NovemberGodotGame2024/novembergame/scripts/bullet.gd

35 lines
750 B
GDScript3
Raw Normal View History

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