diff --git a/gdrust/src/fight.rs b/gdrust/src/fight.rs index 863c0e2..f33846b 100644 --- a/gdrust/src/fight.rs +++ b/gdrust/src/fight.rs @@ -1,4 +1,4 @@ -use crate::fight_items::sword::{SwordManager, START}; +use crate::fight_items::sword::SwordManager; use crate::{debug_check, get_global, get_global_screen_effects}; use godot::classes::{Control, IControl}; use godot::obj::WithBaseField; @@ -19,27 +19,16 @@ impl IControl for Fight { fn ready(&mut self) { debug_check!(self); get_global_screen_effects!(self).bind_mut().shake(3.0, 1.0); - self.start_fight(); + self.base_mut().call("start_fight".into(), &[]); } } #[godot_api()] #[derive::gen_debug] impl Fight { - #[debug] - fn get_end_fight(&self) -> Callable { - self.base().callable("end_fight") - } - + #[func] #[debug] fn get_sword_manager(&self) -> Gd { self.base().get_node_as("SwordManager") } - - #[func] - fn start_fight(&mut self) { - let mut sword = self.get_sword_manager().bind_mut().get_and_next_sword(); - sword.connect("attack_finished".into(), self.get_end_fight()); - sword.call(START.into(), &[]); - } } diff --git a/gdrust/src/fight_items/sword.rs b/gdrust/src/fight_items/sword.rs index 66d12c3..c9ce3c4 100644 --- a/gdrust/src/fight_items/sword.rs +++ b/gdrust/src/fight_items/sword.rs @@ -40,17 +40,19 @@ fn get_fight_list() -> &'static Vec<&'static str> { Ok(sword) => { // 检查剑是否存在 let sword = sword.trim(); - match get_sword_map().get(sword) { - Some(val) => { - return vec![val]; - } - None => { - panic!( + if !sword.is_empty() { + match get_sword_map().get(sword) { + Some(val) => { + return vec![val]; + } + None => { + panic!( "Found {},but sword {} not found.Available sword names are {:?}", SWORD_DEBUG, sword, get_sword_basic() ) + } } } } @@ -101,6 +103,11 @@ impl SwordManager { self.sword_idx += 1; } + #[func] + fn has_sword(&mut self) -> bool { + self.sword_idx < get_fight_list().len() + } + #[func] pub fn get_and_next_sword(&mut self) -> Gd { let obj = self.get_sword(); diff --git a/gdrust/src/weapons/star_wrath.rs b/gdrust/src/weapons/star_wrath.rs index f419bf1..a0f5027 100644 --- a/gdrust/src/weapons/star_wrath.rs +++ b/gdrust/src/weapons/star_wrath.rs @@ -76,7 +76,7 @@ impl StarWrath { godot_print!("start star wrath"); self.base_mut().set_process(true); self.start_flag = true; - self.new_bullet(); + // // self.new_bullet(); let mut anmi = self.get_animation(); anmi.play_ex().name("enter_scene".into()).done(); } diff --git a/scenes/fight.gd b/scenes/fight.gd new file mode 100644 index 0000000..cb30c65 --- /dev/null +++ b/scenes/fight.gd @@ -0,0 +1,11 @@ +extends Fight + + +func start_fight(): + var manager = self.get_sword_manager() + if !manager.has_sword(): + return + var sword = manager.get_and_next_sword() + sword.connect("attack_finished", self.start_fight.bind()) + await get_tree().create_timer(0.5).timeout + sword.start() diff --git a/scenes/fight.tscn b/scenes/fight.tscn index 20bec3d..7110148 100644 --- a/scenes/fight.tscn +++ b/scenes/fight.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=26 format=3 uid="uid://cibwxaqnuodid"] +[gd_scene load_steps=27 format=3 uid="uid://cibwxaqnuodid"] +[ext_resource type="Script" path="res://scenes/fight.gd" id="1_dqpk1"] [ext_resource type="Texture2D" uid="uid://byln211i8r3lq" path="res://scenes/Zenith.png" id="1_jsdtx"] [ext_resource type="Texture2D" uid="uid://b5jjl8np5jm6q" path="res://scenes/player/shields/shield.png" id="3_bdq2j"] [ext_resource type="PackedScene" uid="uid://dn2ixin15jtt3" path="res://scenes/weapons/star_wrath/star_wrath.tscn" id="4_8ipx5"] @@ -53,6 +54,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("1_dqpk1") [node name="BgColor" type="ColorRect" parent="."] layout_mode = 1 diff --git a/scenes/weapons/star_wrath/star_wrath.gd b/scenes/weapons/star_wrath/star_wrath.gd index eb468d9..3fbd22e 100644 --- a/scenes/weapons/star_wrath/star_wrath.gd +++ b/scenes/weapons/star_wrath/star_wrath.gd @@ -5,16 +5,6 @@ var operations = [func(): self.fall_star_process()] var operation_idx = 0 -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta: float) -> void: - pass - - func next_operation(): if operation_idx >= operations.size(): $"..".attack_finished.emit() @@ -27,6 +17,7 @@ func fall_star_process(): for i in range(10): self.fall_star() await get_tree().create_timer(randf_range(1.0, 2.0)).timeout + next_operation() func laser():