Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jun 1, 2024
1 parent ecc0656 commit 4080c68
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 20 deletions.
9 changes: 8 additions & 1 deletion gdrust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion gdrust/src/fight_items.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod block;
mod block_drawer;
16 changes: 0 additions & 16 deletions gdrust/src/fight_items/block.rs

This file was deleted.

60 changes: 60 additions & 0 deletions gdrust/src/fight_items/block_drawer.rs
Original file line number Diff line number Diff line change
@@ -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<Node2D>,
#[var]
// x方向上的block数量
x: i32,
#[var]
// y方向上的block数量
y: i32,
}

#[godot_api]
impl INode2D for BlockDrawer {
fn init(base: Base<Node2D>) -> 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
}
}
11 changes: 9 additions & 2 deletions gdrust/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ use godot::prelude::*;
#[derive(GodotClass)]
#[class(base = Area2D)]
struct Player {
#[var]
health: i32,
base: Base<Area2D>,
}

#[godot_api()]
impl IArea2D for Player {
fn init(base: Base<Area2D>) -> 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) {
Expand Down Expand Up @@ -43,4 +48,6 @@ impl IArea2D for Player {
impl Player {
#[constant]
const SPEED: i32 = 500;
#[constant]
const MAX_HEALTH: i32 = 100;
}

0 comments on commit 4080c68

Please sign in to comment.