const MainMenu_path = "res://scenes/main_menu/MainMenu.tscn"
const Settings_path = "res://scenes/settings/Settings.tscn"
const BaseLevel_path = "res://scenes/base_level/BaseLevel.tscn"
+const BaseBullet_path = "res://components/base_bullet/BaseBullet.tscn"
# others
const default_changeScene_config = {
--- /dev/null
+[gd_scene load_steps=3 format=3 uid="uid://dh2f807ny4qh2"]
+
+[ext_resource type="Script" path="res://components/base_bullet/base_bullet.gd" id="1_0faoa"]
+
+[sub_resource type="CircleShape2D" id="CircleShape2D_b7ejx"]
+radius = 4.96679
+
+[node name="BaseBullet" type="CharacterBody2D"]
+script = ExtResource("1_0faoa")
+
+[node name="Polygon2D" type="Polygon2D" parent="."]
+scale = Vector2(1.79425, 1.69033)
+color = Color(0.828474, 0.826652, 1.54018e-06, 1)
+polygon = PackedVector2Array(2.53263, -1.21713, 2.07215, -1.94741, 1.15119, -2.67769, 0, -2.92112, -1.15119, -2.67769, -2, -2, -2.53263, -1.21713, -2.76287, 0, -2.53263, 1.21713, -2.07215, 1.94741, -1.15119, 2.67769, 0, 2.92112, 1.15119, 2.67769, 2, 2, 2.53263, 1.21713, 2.76287, 0)
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+scale = Vector2(1.00669, 1.00809)
+shape = SubResource("CircleShape2D_b7ejx")
--- /dev/null
+extends CharacterBody2D
+
+@export var SPEED = 200.0
+var origin: Node2D
+var target: Node2D
+
+
+func _ready():
+ if origin:
+ position = origin.position
+
+
+func _process(_delta):
+ if target:
+ velocity = position.direction_to(target.position) * SPEED
+ move_and_slide()
+
+
+func set_origin(node: Node2D):
+ origin = node
+ position = origin.position
+
+
+func set_target(node: Node2D):
+ target = node
polygon = PackedVector2Array(-0.267257, -4.94762, -0.367478, 0, -0.267257, 4.94762, 0, 6.80297, 0.267257, 4.94762, 0.367478, 0, 0.267257, -4.94762, 0, -6.80297)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
-scale = Vector2(1, 1)
shape = SubResource("CircleShape2D_oxutk")
const SPEED = 300.0
+var fire_timer: Timer
+var nearest_enemy: Node2D
+
+func _init():
+ fire_timer = Timer.new()
+ fire_timer.one_shot = false
+ fire_timer.autostart = true
+ fire_timer.wait_time = .5
+ fire_timer.timeout.connect(on_fire_timer_timeout)
+ add_child(fire_timer)
+
+
+func _process(delta):
+ var nearest_node: Node2D
+
+ for node in get_parent().get_children():
+ if node is CharacterBody2D:
+ if node.name.contains("Enemy"):
+ if !nearest_node:
+ nearest_node = node
+ elif (position.distance_squared_to(node.position)
+ < position.distance_squared_to(nearest_node.position)):
+ nearest_node = node
+
+ nearest_enemy = nearest_node
func _physics_process(_delta):
velocity = Vector2(x_force, y_force) * SPEED
move_and_slide()
+
+
+func on_fire_timer_timeout():
+ if nearest_enemy:
+ var bullet = load(Constants.BaseBullet_path)
+ var bullet_instance = bullet.instantiate() as CharacterBody2D
+ get_parent().add_child(bullet_instance)
+ var n2d = Node2D.new()
+ n2d.position = position
+ bullet_instance.set_origin(n2d)
+ bullet_instance.set_target(nearest_enemy)
+
+