diff --git a/gdrust/src/bullets/star_wrath_bullet.rs b/gdrust/src/bullets/star_wrath_bullet.rs index dc17704..9f1013b 100644 --- a/gdrust/src/bullets/star_wrath_bullet.rs +++ b/gdrust/src/bullets/star_wrath_bullet.rs @@ -7,9 +7,8 @@ use rand::{thread_rng, Rng}; use std::f32::consts::PI; use crate::player::Player; -use crate::utils::screen_effects::ScreenEffects; use crate::utils::split_to_vec; -use crate::{debug_check, get_global, godot_debug_assert}; +use crate::{debug_check, godot_debug_assert}; #[derive(GodotClass)] #[class(base=Area2D)] @@ -17,6 +16,8 @@ pub struct StarWrathBullet { base: Base, direct: Vector2, speed: i32, + #[var] + explode: bool, } const SPEED_MIN: i32 = 300; @@ -31,6 +32,7 @@ impl IArea2D for StarWrathBullet { base, direct: Vector2::ZERO, speed: 0, + explode: false, } } diff --git a/gdrust/src/weapons/star_wrath.rs b/gdrust/src/weapons/star_wrath.rs index a0f5027..7d63a26 100644 --- a/gdrust/src/weapons/star_wrath.rs +++ b/gdrust/src/weapons/star_wrath.rs @@ -83,9 +83,10 @@ impl StarWrath { #[func] /// 新建一个从天而降垂直下落的弹幕 - fn fall_star(&mut self) { + fn fall_star(&mut self, explode: bool) { let bullet = self.get_bullet_scene(); let mut star = bullet.instantiate_as::(); + star.bind_mut().set_explode(explode); const SZ_TO_SIDE: f32 = 200.0; let sz = self.base_mut().get_viewport_rect().size.x - SZ_TO_SIDE; let random_x = thread_rng().gen_range(SZ_TO_SIDE..sz); diff --git a/scenes/bullets/star_wrath/little_star.gd b/scenes/bullets/star_wrath/little_star.gd new file mode 100644 index 0000000..c728594 --- /dev/null +++ b/scenes/bullets/star_wrath/little_star.gd @@ -0,0 +1,24 @@ +extends Sprite2D + +const SPEED: float = 90 +var direct + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + set_process(false) + + +func shoot(direction: Vector2): + assert(direction.length() > 0) + self.direct = direction.normalized() + set_process(true) + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + self.position += delta * SPEED * direct + + +func _on_visible_on_screen_notifier_2d_screen_exited() -> void: + queue_free() diff --git a/scenes/bullets/star_wrath/little_star.tscn b/scenes/bullets/star_wrath/little_star.tscn new file mode 100644 index 0000000..c3896a1 --- /dev/null +++ b/scenes/bullets/star_wrath/little_star.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=3 uid="uid://dtboow2wo76hq"] + +[ext_resource type="Texture2D" uid="uid://dsq0jnh5u5avq" path="res://scenes/bullets/star_wrath/littlestar.png" id="1_hkmep"] +[ext_resource type="Script" path="res://scenes/bullets/star_wrath/little_star.gd" id="2_kxmji"] + +[node name="LittleStar" type="Sprite2D"] +texture = ExtResource("1_hkmep") +script = ExtResource("2_kxmji") + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] + +[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/scenes/bullets/star_wrath/littlestar.png b/scenes/bullets/star_wrath/littlestar.png new file mode 100644 index 0000000..54632f3 Binary files /dev/null and b/scenes/bullets/star_wrath/littlestar.png differ diff --git a/scenes/bullets/star_wrath/littlestar.png.import b/scenes/bullets/star_wrath/littlestar.png.import new file mode 100644 index 0000000..bbd3fdd --- /dev/null +++ b/scenes/bullets/star_wrath/littlestar.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dsq0jnh5u5avq" +path="res://.godot/imported/littlestar.png-3be6e558e4d3350cfb1e4879ffa30bd8.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scenes/bullets/star_wrath/littlestar.png" +dest_files=["res://.godot/imported/littlestar.png-3be6e558e4d3350cfb1e4879ffa30bd8.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/bullets/star_wrath/littlestar.pxo b/scenes/bullets/star_wrath/littlestar.pxo new file mode 100644 index 0000000..a140c16 Binary files /dev/null and b/scenes/bullets/star_wrath/littlestar.pxo differ diff --git a/scenes/bullets/star_wrath/point.gd b/scenes/bullets/star_wrath/point.gd new file mode 100644 index 0000000..3ec4c82 --- /dev/null +++ b/scenes/bullets/star_wrath/point.gd @@ -0,0 +1,16 @@ +extends Sprite2D + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + hide() + set_process(false) + + +func work(): + set_process(true) + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/scenes/bullets/star_wrath/point.png b/scenes/bullets/star_wrath/point.png new file mode 100644 index 0000000..2bc0cdb Binary files /dev/null and b/scenes/bullets/star_wrath/point.png differ diff --git a/scenes/bullets/star_wrath/point.png.import b/scenes/bullets/star_wrath/point.png.import new file mode 100644 index 0000000..ed925c6 --- /dev/null +++ b/scenes/bullets/star_wrath/point.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cyrklccri8jt4" +path="res://.godot/imported/point.png-0d81272545105e3a341cfa9087101a89.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scenes/bullets/star_wrath/point.png" +dest_files=["res://.godot/imported/point.png-0d81272545105e3a341cfa9087101a89.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/bullets/star_wrath/point.pxo b/scenes/bullets/star_wrath/point.pxo new file mode 100644 index 0000000..a32597d Binary files /dev/null and b/scenes/bullets/star_wrath/point.pxo differ diff --git a/scenes/bullets/star_wrath/point.tscn b/scenes/bullets/star_wrath/point.tscn new file mode 100644 index 0000000..95e3d94 --- /dev/null +++ b/scenes/bullets/star_wrath/point.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://bgq78c0mfx381"] + +[node name="Point" type="Sprite2D"] diff --git a/scenes/bullets/star_wrath/star_wrath_original.gd b/scenes/bullets/star_wrath/star_wrath_original.gd index 7c23c25..93926bb 100644 --- a/scenes/bullets/star_wrath/star_wrath_original.gd +++ b/scenes/bullets/star_wrath/star_wrath_original.gd @@ -3,6 +3,7 @@ extends StarWrathBullet @export var track: PackedScene var tween var block_color: Color = Color8(255, 255, 255, 255) +var littlestar_scene = preload("res://scenes/bullets/star_wrath/little_star.tscn") # Called when the node enters the scene tree for the first time. @@ -10,6 +11,21 @@ func _ready() -> void: hide() +func explode_effect(callback): + for i in range(3): + var direct = PI / 12 + for j in range(10): + var littlestar = littlestar_scene.instantiate() + littlestar.shoot(direct * j) + add_child(littlestar) + await get_tree().create_timer(0.1).timeout + callback.call() + + func _on_killer_screen_exited() -> void: await get_tree().create_timer(0.5).timeout - queue_free() + if self.explode: + # 爆炸 + self.explode_effect(queue_free) + else: + queue_free() diff --git a/scenes/weapons/star_wrath/star_wrath.gd b/scenes/weapons/star_wrath/star_wrath.gd index 31360f2..aa94ce9 100644 --- a/scenes/weapons/star_wrath/star_wrath.gd +++ b/scenes/weapons/star_wrath/star_wrath.gd @@ -2,11 +2,17 @@ extends StarWrath @export var star_wrath_origin: PackedScene var operation_idx = 0 -# func(): self.fall_star_process(), -var operations = [func(): self.beam_shoot1(), func(): self.leave()] +var operations = [ + func(): self.fall_star_process(), + func(): self.beam_shoot1(), + func(): self.fall_star_explode(), + func(): five_surrounding_points(), + func(): self.leave() +] @onready var animation_player = $AnimationPlayer @onready var star_wrath = $StarWrath var beam_scene: PackedScene = preload("res://scenes/bullets/star_wrath/laser_beam.tscn") +var point_scene: PackedScene = preload("res://scenes/bullets/star_wrath/point.tscn") func next_operation(): @@ -20,11 +26,25 @@ func next_operation(): func fall_star_process(): for i in range(10): - self.fall_star() + self.fall_star(false) await get_tree().create_timer(randf_range(1.0, 2.0)).timeout next_operation() +func fall_star_explode(): + for i in range(4): + self.fall_star(true) + await get_tree().create_timer(randf_range(5.0, 6.0)).timeout + next_operation() + + +func five_surrounding_points(): + var points = [] + for i in range(5): + var point = point_scene.instantiate() + points.push_back(point) + + func beam_shoot1(): var beam = beam_scene.instantiate() self.add_child(beam)