From 27aa1afce3c0567ded1b03e40806b96e24421ad6 Mon Sep 17 00:00:00 2001 From: Artur David Date: Tue, 14 Apr 2026 14:06:43 +0200 Subject: [PATCH] Added homing shuriken and fixed Viewport --- scenes/fireball.tscn | 2 ++ scenes/shuriken.tscn | 55 ++++++++++++++++++++++++++++++++++++++++ scripts/shuriken.gd | 40 +++++++++++++++++++++++++++++ scripts/shuriken.gd.uid | 1 + scripts/spawn_control.gd | 21 ++++++--------- scripts/witch.gd | 19 +++++++++++++- 6 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 scenes/shuriken.tscn create mode 100644 scripts/shuriken.gd create mode 100644 scripts/shuriken.gd.uid diff --git a/scenes/fireball.tscn b/scenes/fireball.tscn index 3ca25ec..17dd868 100644 --- a/scenes/fireball.tscn +++ b/scenes/fireball.tscn @@ -49,5 +49,7 @@ script = ExtResource("1_1gl40") shape = SubResource("CircleShape2D_7kba2") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1117029857] +texture_filter = 1 sprite_frames = SubResource("SpriteFrames_mi4h5") +autoplay = "default" frame_progress = 0.02371424 diff --git a/scenes/shuriken.tscn b/scenes/shuriken.tscn new file mode 100644 index 0000000..8f6beb0 --- /dev/null +++ b/scenes/shuriken.tscn @@ -0,0 +1,55 @@ +[gd_scene format=3 uid="uid://ddfdsj38deof6"] + +[ext_resource type="Script" uid="uid://d0vbrag76qoil" path="res://scripts/shuriken.gd" id="1_k18gy"] +[ext_resource type="Texture2D" uid="uid://dimo6wv81xev4" path="res://assets/Fire Pixel Bullet 16x16/All_Fire_Bullet_Pixel_16x16_02.png" id="2_0rvwh"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_jr3c8"] +atlas = ExtResource("2_0rvwh") +region = Rect2(496, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yvn8i"] +atlas = ExtResource("2_0rvwh") +region = Rect2(512, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tacqd"] +atlas = ExtResource("2_0rvwh") +region = Rect2(528, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_c2qga"] +atlas = ExtResource("2_0rvwh") +region = Rect2(544, 32, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_r3mqu"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_jr3c8") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_yvn8i") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tacqd") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_c2qga") +}], +"loop": true, +"name": &"default", +"speed": 20.0 +}] + +[sub_resource type="CircleShape2D" id="CircleShape2D_bgiul"] +radius = 8.0 + +[node name="Shuriken" type="Area2D" unique_id=1854090943] +script = ExtResource("1_k18gy") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1281987394] +texture_filter = 1 +sprite_frames = SubResource("SpriteFrames_r3mqu") +autoplay = "default" +frame_progress = 0.3453456 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=572140399] +shape = SubResource("CircleShape2D_bgiul") diff --git a/scripts/shuriken.gd b/scripts/shuriken.gd new file mode 100644 index 0000000..aa0534f --- /dev/null +++ b/scripts/shuriken.gd @@ -0,0 +1,40 @@ +extends ProjectileBase + +var enemies_hit = 0 + + +func _ready() -> void: + speed = 500 + super() + var first = get_nearest_enemy(global_position) + if first == null: + queue_free() + return + launch(first.global_position) + +func _on_body_entered(body: Node2D) -> void: + if body.is_in_group("enemies"): + enemies_hit += 1 + body.die() + if enemies_hit == 20: + queue_free() + else: + var next = get_nearest_enemy(global_position, body) + if next == null: + queue_free() + else: + launch(next.global_position) + +func get_nearest_enemy(from: Vector2, exclude: Node = null) -> Node: + var nearest = null + var min_distance = INF + for enemy in get_tree().get_nodes_in_group("enemies"): + if enemy == exclude or enemy.is_dying: + continue + var dist = from.distance_to(enemy.global_position) + if dist < min_distance: + min_distance = dist + nearest = enemy + return nearest + + diff --git a/scripts/shuriken.gd.uid b/scripts/shuriken.gd.uid new file mode 100644 index 0000000..9a4884d --- /dev/null +++ b/scripts/shuriken.gd.uid @@ -0,0 +1 @@ +uid://d0vbrag76qoil diff --git a/scripts/spawn_control.gd b/scripts/spawn_control.gd index dce11de..f0e2b1a 100644 --- a/scripts/spawn_control.gd +++ b/scripts/spawn_control.gd @@ -7,20 +7,15 @@ var down_left var viewport_rect func _ready() -> void: - viewport_rect = get_viewport_rect() + var camera: Camera2D = get_parent().get_node("Camera2D") + var viewport_size = get_viewport_rect().size + var world_size = viewport_size / camera.zoom + var world_origin = camera.global_position # anchor_mode = 0 → top-left corner - print(get_viewport_rect()) - - up_left = viewport_rect.position - down_right = viewport_rect.end - up_right = Vector2(viewport_rect.end.x, viewport_rect.position.y) - down_left = Vector2(viewport_rect.position.x, viewport_rect.end.y) - print(up_left) - print(up_right) - print(down_left) - print(down_right) - print(get_spawn_position()) - pass # Replace with function body. + up_left = world_origin + down_right = world_origin + world_size + up_right = Vector2(down_right.x, up_left.y) + down_left = Vector2(up_left.x, down_right.y) func get_spawn_position() -> Vector2: var side = randi() % 4 diff --git a/scripts/witch.gd b/scripts/witch.gd index 3d0ab65..6df9c04 100644 --- a/scripts/witch.gd +++ b/scripts/witch.gd @@ -4,6 +4,8 @@ var camera var bar_progress = 0 var is_casting = false var fireball = preload("res://scenes/fireball.tscn") +var shuriken = preload("res://scenes/shuriken.tscn") + func _ready() -> void: camera = get_node("/root/Game/Camera2D") @@ -20,7 +22,7 @@ func _on_collect(DropsBase): bar_progress = 0 is_casting = true await $CauldronBar.ignite_cauldrons() - shoot_fireballs() + shoot_shuriken() camera.shake(0.3,0.8) $CauldronBar.reset_texture() is_casting = false @@ -32,3 +34,18 @@ func shoot_fireballs(): fb.global_position = global_position get_parent().add_child(fb) fb.launch(enemy.global_position) + +func shoot_shuriken(): + var sh = shuriken.instantiate() + sh.global_position = global_position + get_parent().add_child(sh) + +func get_nearest_enemy(from: Vector2) -> Node: + var nearest = null + var min_distance = INF + for enemy in get_tree().get_nodes_in_group("enemies"): + var dist = from.distance_to(enemy.global_position) + if dist < min_distance: + min_distance = dist + nearest = enemy + return nearest