Skip to content

Commit

Permalink
feat:star wrath can run in fight scene
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jul 11, 2024
1 parent f8217c8 commit 94ecf9a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
15 changes: 9 additions & 6 deletions gdrust/src/bullets/star_wrath_bullet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use derive::gen_debug;
use godot::classes::{Area2D, IArea2D};
use godot::engine::CollisionShape2D;
use godot::obj::WithBaseField;
use godot::prelude::*;
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -38,8 +39,6 @@ impl IArea2D for StarWrathBullet {
self.base_mut().set_global_position(tmp);
}

fn draw(&mut self) {}

fn ready(&mut self) {
debug_check!(self)
}
Expand Down Expand Up @@ -96,10 +95,6 @@ impl StarWrathBullet {
self.direct = Vector2::DOWN;
}

fn track(&mut self) {
self.base_mut().queue_redraw();
}

#[func]
#[debug]
fn get_track_scene(&self) -> Gd<PackedScene> {
Expand All @@ -111,6 +106,14 @@ impl StarWrathBullet {
if obj.get_name() == "Player".into() {
let mut obj = obj.get_parent().unwrap().cast::<Player>();
obj.bind_mut().hit(1);
// 关闭碰撞检测
self.get_collison()

Check warning on line 110 in gdrust/src/bullets/star_wrath_bullet.rs

View workflow job for this annotation

GitHub Actions / Typos

"collison" should be "collision" or "collusion".

Check warning on line 110 in gdrust/src/bullets/star_wrath_bullet.rs

View workflow job for this annotation

GitHub Actions / Typos

"collison" should be "collision" or "collusion".
.set_deferred("disabled".into(), true.to_variant());
}
}

#[debug]
fn get_collison(&mut self) -> Gd<CollisionShape2D> {

Check warning on line 116 in gdrust/src/bullets/star_wrath_bullet.rs

View workflow job for this annotation

GitHub Actions / Typos

"collison" should be "collision" or "collusion".

Check warning on line 116 in gdrust/src/bullets/star_wrath_bullet.rs

View workflow job for this annotation

GitHub Actions / Typos

"collison" should be "collision" or "collusion".
self.base_mut().get_node_as("CollisionShape2D")
}
}
1 change: 0 additions & 1 deletion gdrust/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::debug_check;
#[derive(GodotClass)]
#[class(base = CharacterBody2D)]
pub struct Player {
#[var]
health: i32,
base: Base<CharacterBody2D>,
status: Movement,
Expand Down
20 changes: 4 additions & 16 deletions gdrust/src/weapons/star_wrath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@ use rand::{thread_rng, Rng};
pub struct StarWrath {
base: Base<Area2D>,
start_flag: bool,
state: State,
}

#[derive(PartialEq, Eq)]
enum State {
Wave1,
Wave2,
WaveReSet,
None,
}

pub type Action = fn(&mut StarWrath);

const BULLETS_NUM: i32 = 3;

#[godot_api()]
Expand All @@ -32,7 +21,6 @@ impl IArea2D for StarWrath {
Self {
base,
start_flag: false,
state: State::Wave1,
}
}

Expand Down Expand Up @@ -85,8 +73,7 @@ impl StarWrath {

#[func]
fn start(&mut self) {
// let mut fight_time = self.get_fight_timer();
// fight_time.start();
godot_print!("start star wrath");
self.base_mut().set_process(true);
self.start_flag = true;
self.new_bullet();
Expand All @@ -99,8 +86,9 @@ impl StarWrath {
fn fall_star(&mut self) {
let bullet = self.get_bullet_scene();
let mut star = bullet.instantiate_as::<StarWrathBullet>();
let sz = self.base_mut().get_viewport_rect().size.x - 100.0;
let random_x = thread_rng().gen_range(100.0..sz);
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);
// godot_print!("{}", random_x);
self.base_mut().add_child(star.clone().upcast());
star.bind_mut().init_from_sky(random_x);
Expand Down
20 changes: 11 additions & 9 deletions scenes/weapons/star_wrath/star_wrath_root.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ extends Node

signal attack_finished


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if get_tree().current_scene == self:
$StarWrath.start()
self.start()
else:
$StarWrath.hide()
$Bg.hide()
hide()

func start():
$StarWrath.start()
func hide():
$StarWrath.hide()
$Bg.hide()

func show():
$StarWrath.show()
$Bg.show()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func start():
show()
$StarWrath.start()

0 comments on commit 94ecf9a

Please sign in to comment.