diff --git a/gdrust/Cargo.toml b/gdrust/Cargo.toml index 883834f..4dc7f15 100644 --- a/gdrust/Cargo.toml +++ b/gdrust/Cargo.toml @@ -1,10 +1,17 @@ +cargo-features = ["edition2024", "profile-rustflags"] [package] name = "gdrust" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] godot = { git = "https://github.com/godot-rust/gdext", branch = "master" } [lib] crate-type = ["cdylib"] + +[profile.release] +lto = true +codegen-units = 1 +strip = true +rustflags = ["-D", "warnings"] diff --git a/gdrust/src/fight_items.rs b/gdrust/src/fight_items.rs index fc9210d..7364794 100644 --- a/gdrust/src/fight_items.rs +++ b/gdrust/src/fight_items.rs @@ -1 +1 @@ -mod block; +mod block_drawer; diff --git a/gdrust/src/fight_items/block.rs b/gdrust/src/fight_items/block.rs deleted file mode 100644 index b2fd232..0000000 --- a/gdrust/src/fight_items/block.rs +++ /dev/null @@ -1,16 +0,0 @@ -use godot::engine::{INode2D, Node2D}; -use godot::prelude::*; - -#[derive(GodotClass)] -#[class(base = Node2D)] -struct BlockDrawer { - base: Base, -} - -#[godot_api] -impl INode2D for BlockDrawer { - fn init(base: Base) -> BlockDrawer { - // godot_print!("BlockDrawer created from Godot Rust"); - Self { base } - } -} diff --git a/gdrust/src/fight_items/block_drawer.rs b/gdrust/src/fight_items/block_drawer.rs new file mode 100644 index 0000000..4f5263d --- /dev/null +++ b/gdrust/src/fight_items/block_drawer.rs @@ -0,0 +1,60 @@ +use godot::engine::{INode2D, Node2D}; +use godot::obj::WithBaseField; +use godot::prelude::*; + +#[derive(GodotClass)] +#[class(base = Node2D)] +struct BlockDrawer { + base: Base, + #[var] + // x方向上的block数量 + x: i32, + #[var] + // y方向上的block数量 + y: i32, +} + +#[godot_api] +impl INode2D for BlockDrawer { + fn init(base: Base) -> BlockDrawer { + // godot_print!("BlockDrawer created from Godot Rust"); + Self { + x: Self::X_BLOCKS, + y: Self::Y_BLOCKS, + base, + } + } + + fn process(&mut self, delta: f64) {} + + fn draw(&mut self) {} +} + +#[godot_api] +impl BlockDrawer { + #[constant] + const X_BLOCKS: i32 = 10; + #[constant] + const Y_BLOCKS: i32 = 10; + + #[func] + fn change_block_immediate(&mut self, x: i32, y: i32) { + self.x = x; + self.y = y; + } + + #[func] + fn change_block_gently(&mut self, x: i32, y: i32) {} + + #[func] + fn get_y_min(&mut self) -> i32 { + // self.base(). + (self.base().get_viewport_rect().size.y - self.y as f32) as i32 + } + + #[func] + fn get_x_min(&mut self) -> i32 { + // self.base(). + (self.base().get_viewport_rect().size.x - self.x as f32) as i32 + } +} diff --git a/gdrust/src/player.rs b/gdrust/src/player.rs index 7264818..66fd46b 100644 --- a/gdrust/src/player.rs +++ b/gdrust/src/player.rs @@ -4,14 +4,19 @@ use godot::prelude::*; #[derive(GodotClass)] #[class(base = Area2D)] struct Player { + #[var] + health: i32, base: Base, } #[godot_api()] impl IArea2D for Player { fn init(base: Base) -> Player { - godot_print!("Player created from Godot Rust"); - Self { base } + // godot_print!("Player created from Godot Rust"); + Self { + base, + health: Self::MAX_HEALTH, + } } fn physics_process(&mut self, delta: f64) { @@ -43,4 +48,6 @@ impl IArea2D for Player { impl Player { #[constant] const SPEED: i32 = 500; + #[constant] + const MAX_HEALTH: i32 = 100; }