Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jun 5, 2024
1 parent 5285c45 commit 007420d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
15 changes: 15 additions & 0 deletions gdrust/src/Zenith.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use godot::engine::{Area2D, IArea2D};
use godot::prelude::*;

#[derive(GodotClass)]
#[class(base = Area2D)]
struct ZenithBegin {
base: Base<Area2D>,
}

#[godot_api()]
impl IArea2D for ZenithBegin {
fn init(base: Base<Area2D>) -> ZenithBegin {
ZenithBegin { base }
}
}
39 changes: 25 additions & 14 deletions gdrust/src/fight_items/block_drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,49 @@ use godot::prelude::*;
struct BlockDrawer {
base: Base<Node2D>,
#[var]
// x方向上的block数量
x: i32,
x: f32,
#[var]
// y方向上的block数量
y: i32,
y: f32,
}

#[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,
x: Self::BOX_START_POS_X,
y: Self::BOX_START_POS_Y,
base,
}
}

fn process(&mut self, delta: f64) {}

fn draw(&mut self) {}
fn draw(&mut self) {
let tmp = self.x;
let xsize = self.base_mut().get_viewport_rect().size.x - tmp * 2.0;

godot_print!("enter");
let tmp = Vector2::new(self.x, self.y);
self.base_mut()
.draw_rect_ex(
Rect2::new(tmp, Vector2::new(xsize, Self::Y_SIZE_DEFAULT)),
Color::from_rgb(10.0, 10.0, 10.0),
)
.width(20.0)
.filled(false)
.done();
}
}

#[godot_api]
impl BlockDrawer {
#[constant]
const X_BLOCKS: i32 = 10;
#[constant]
const Y_BLOCKS: i32 = 10;
const BOX_START_POS_X: f32 = 400.0;
const BOX_START_POS_Y: f32 = 330.0;
const Y_SIZE_DEFAULT: f32 = 200.0;

#[func]
fn change_block_immediate(&mut self, x: i32, y: i32) {
fn change_block_immediate(&mut self, x: f32, y: f32) {
self.x = x;
self.y = y;
}
Expand All @@ -49,12 +60,12 @@ impl BlockDrawer {
#[func]
fn get_y_min(&mut self) -> i32 {
// self.base().
(self.base().get_viewport_rect().size.y - self.y as f32) as i32
(self.base().get_viewport_rect().size.y - self.y) 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
(self.base().get_viewport_rect().size.x - self.x) as i32
}
}
1 change: 1 addition & 0 deletions gdrust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod Zenith;
mod fight_items;
mod player;

Expand Down
10 changes: 6 additions & 4 deletions scenes/fight.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 1)

[node name="ZenithBegin" type="Sprite2D" parent="."]
position = Vector2(563, 154)
rotation = 2.35389
scale = Vector2(-3.28571, -3.28571)
[node name="ZenithBegin" type="ZenithBegin" parent="."]
position = Vector2(569, 137)
rotation = -0.787703
scale = Vector2(3.28571, 3.28571)

[node name="image" type="Sprite2D" parent="ZenithBegin"]
texture = ExtResource("3_2spkb")

[node name="Star_Wrath" parent="." instance=ExtResource("4_8ipx5")]
Expand Down

0 comments on commit 007420d

Please sign in to comment.