Skip to content

Commit

Permalink
fix:rotation of star wrath bullet
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jul 6, 2024
1 parent d4357aa commit 88201ea
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
5 changes: 3 additions & 2 deletions gdrust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions gdrust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
cargo-features = ["edition2024", "profile-rustflags"]
[package]
name = "gdrust"
version = "0.1.0"
edition = "2024"
edition = "2021"

[dependencies]
godot = {version = "0", features = ["experimental-threads"]}
godot = { version = "0", features = ["experimental-threads"] }
rand = "0.8"
derive = { path = "./derive" }
proto = { path = "proto" }
Expand Down
14 changes: 10 additions & 4 deletions gdrust/src/bullets/star_wrath_bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl IArea2D for StarWrathBullet {
let tmp = self.base().get_position() + self.direct * delta as f32 * self.speed as f32;
self.base_mut().set_position(tmp);
}

fn draw(&mut self) {}
}

#[godot_api]
Expand Down Expand Up @@ -79,12 +81,16 @@ impl StarWrathBullet {
let pos = Vector2::new(x_idx, 0.0);
self.base_mut().set_global_position(pos);
let mask = self.get_track_scene();
let mut new_mask = mask.instantiate().unwrap();
self.base_mut().add_child(new_mask.clone());
// let mut new_mask = mask.instantiate().unwrap();
// self.base_mut().add_child(new_mask.clone());
godot_print!("now pos:{}", pos);
new_mask.call("init".into(), &[pos.to_variant()]);
// new_mask.call("init".into(), &[pos.to_variant()]);
self.base_mut().show();
self.base_mut().set_rotation(-PI / 2.0);
self.base_mut().set_global_rotation(-PI / 2.0);
}

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

#[func]
Expand Down
4 changes: 2 additions & 2 deletions gdrust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod zenith;
use godot::prelude::*;
use multi::{MultiManager, MultiManagerImpl};
use std::{
panic::{set_hook, PanicHookInfo},
panic::{set_hook, PanicInfo},
sync::{Arc, Mutex, OnceLock},
};
use tokio::runtime::{Builder, Runtime};
Expand All @@ -31,7 +31,7 @@ fn get_tokio_runtime() -> &'static Runtime {
TMP.get_or_init(|| Builder::new_multi_thread().enable_all().build().unwrap())
}

fn panic_handler(info: &PanicHookInfo) {
fn panic_handler(info: &PanicInfo) {
if let Some(p) = info.location() {
godot_error!(
"Panic occurred in file '{}' at line {}\n",
Expand Down
8 changes: 4 additions & 4 deletions gdrust/src/weapons/star_wrath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ impl StarWrath {
}

#[func]
/// 新建一个从天而降垂直下落的弹幕
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;
let random_x = thread_rng().gen_range(0.0..sz);
let sz = self.base_mut().get_viewport_rect().size.x - 100.0;
let random_x = thread_rng().gen_range(100.0..sz);
godot_print!("{}", random_x);
self.base_mut().add_child(star.clone().upcast());
star.bind_mut().init_from_sky(random_x);
self.base_mut().add_child(star.upcast());
// godot_print!("Star Falling!")
}
}
5 changes: 3 additions & 2 deletions scenes/bullets/star_wrath_original.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://d1po1tqcrrhe3"]
[gd_scene load_steps=4 format=3 uid="uid://d1po1tqcrrhe3"]

[ext_resource type="Texture2D" uid="uid://ca6gwuskjes5u" path="res://resources/images/bullets/star_wrath/Star_Wrath_Original_Bullet.webp" id="1_do8sq"]
[ext_resource type="Script" path="res://scripts/bullets/star_wrath_original.gd" id="1_y6as6"]

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_kmd7p"]
radius = 27.3309
height = 172.02

[node name="StarWrathBullet" type="StarWrathBullet"]
visible = false
script = ExtResource("1_y6as6")

[node name="Image" type="Sprite2D" parent="."]
scale = Vector2(2, 2)
Expand Down
11 changes: 11 additions & 0 deletions scripts/bullets/star_wrath_original.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends StarWrathBullet


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
hide()


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

0 comments on commit 88201ea

Please sign in to comment.