Skip to content

Commit

Permalink
feat:finish fight scene 's playing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jul 12, 2024
1 parent d99b72b commit 0035a97
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
17 changes: 3 additions & 14 deletions gdrust/src/fight.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<SwordManager> {
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(), &[]);
}
}
19 changes: 13 additions & 6 deletions gdrust/src/fight_items/sword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}
}
Expand Down Expand Up @@ -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<Node> {
let obj = self.get_sword();
Expand Down
2 changes: 1 addition & 1 deletion gdrust/src/weapons/star_wrath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 11 additions & 0 deletions scenes/fight.gd
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 3 additions & 1 deletion scenes/fight.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions scenes/weapons/star_wrath/star_wrath.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand Down

0 comments on commit 0035a97

Please sign in to comment.