AugGodotGameCourse/augustgamecourse/scripts/bullet.gd
2024-10-07 20:56:53 -04:00

25 lines
535 B
GDScript

extends Area2D
@onready var bulletsprite: Sprite2D = $Sprite2D
var speed := 700
signal hit(bullet, body)
func setSpeed(speedVal):
speed = speedVal
if speedVal < 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:
if body is Enemy:
print("blow away enemy")
func _on_area_entered(area: Area2D) -> void:
if area is Enemy:
print("blow this enemy away")
hit.emit(self, area)