ArcherTower and Arrows
This commit is contained in:
35
Game/Bullets/bullet.gd
Normal file
35
Game/Bullets/bullet.gd
Normal file
@ -0,0 +1,35 @@
|
||||
extends Node2D
|
||||
|
||||
var target
|
||||
var speed
|
||||
var hitpoint
|
||||
|
||||
func set_targe(_target : Node2D) -> void:
|
||||
target = _target
|
||||
|
||||
func set_speed(_speed: int) -> void:
|
||||
speed = _speed
|
||||
|
||||
func set_hitpoint(_hitpoint: int) -> void:
|
||||
hitpoint = _hitpoint
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if target and speed > 0:
|
||||
# Get the direction vector from the bullet to the target
|
||||
var direction = (target.get_parent().get_parent().get_position() - position).normalized()
|
||||
|
||||
# Rotate the bullet to face the target
|
||||
rotation = direction.angle() + deg_to_rad(90)
|
||||
|
||||
# Move the bullet towards the target
|
||||
position += direction * speed * delta
|
||||
|
||||
if position.distance_to(target.get_parent().get_parent().position) <= 5:
|
||||
target_reached()
|
||||
else:
|
||||
queue_free()
|
||||
|
||||
|
||||
func target_reached() -> void:
|
||||
target.get_parent().enemy_hurt(hitpoint)
|
||||
queue_free()
|
Reference in New Issue
Block a user