sunoku/scenes/bullet/bullet.gd

34 lines
732 B
GDScript

extends Node2D
var speed = 100
var base_speed = 10
var direction = 0
var damage
var hostile = false
@onready var polygon = $Polygon2D
func _ready() -> void:
if hostile:
polygon.color = Color(0.772,0.412,0.506,1)
func _physics_process(delta: float) -> void:
position += speed*delta*base_speed*direction
if position.x < 0 or position.x > 256 or position.y < 0 or position.y > 256:
queue_free()
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player") and hostile:
body.health -= damage
body.inventory.update_stats()
queue_free()
elif body.is_in_group("enemy") and not hostile:
damage = body.damage(damage)
if damage <= 0:
queue_free()
elif body.is_in_group("terrain"):
queue_free()