ArcherTower and Arrows

This commit is contained in:
2025-03-17 11:30:18 +01:00
parent d701893663
commit 9d853dd4f3
14 changed files with 253 additions and 2 deletions

19
Game/Bullets/arrow.tscn Normal file
View File

@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://bjihbmnkq0n3b"]
[ext_resource type="Texture2D" uid="uid://bqdblby54pv2s" path="res://Assets/Bullets/arrow.png" id="1_v0wue"]
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_wft0c"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_wft0c"]
size = Vector2(3, 16)
[node name="Arrow" type="Node2D"]
script = ExtResource("1_wft0c")
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
shape = SubResource("RectangleShape2D_wft0c")
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
texture = ExtResource("1_v0wue")

35
Game/Bullets/bullet.gd Normal file
View 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()

View File

@ -0,0 +1 @@
uid://dqvdgdobuo2rf