Skip to content

Commit

Permalink
Merge branch 'SkyUOI:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
wlywlywlywly authored Jun 6, 2024
2 parents b45d17b + 2a2c400 commit 6f95df8
Show file tree
Hide file tree
Showing 42 changed files with 672 additions and 85 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Godot 4+ specific ignores
.godot/
.lapce/
.idea/

# Godot-specific ignores
.import/
Expand All @@ -19,4 +20,4 @@ mono_crash.*.json
target/

# Godot Cpp
gdcpp/extension_api.json
gdcpp/extension_api.json
1 change: 0 additions & 1 deletion gdcpp/godot-cpp
Submodule godot-cpp deleted from 2b6eb6
20 changes: 10 additions & 10 deletions gdrust/Cargo.lock

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

8 changes: 7 additions & 1 deletion gdrust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
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
1 change: 1 addition & 0 deletions gdrust/src/bullets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod star_wrath_bullet;
32 changes: 32 additions & 0 deletions gdrust/src/bullets/star_wrath_bullet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use godot::engine::{Area2D, IArea2D};
use godot::obj::WithBaseField;
use godot::prelude::*;

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

const INIT_DIRECT: Vector2 = Vector2::new(0.0, 0.0);

#[godot_api()]
impl IArea2D for StarWrathBullet {
fn init(base: Base<Area2D>) -> Self {
Self {
base,
direct: INIT_DIRECT,
}
}

fn process(&mut self, delta: f64) {
let tmp = self.base().get_position() + self.direct.normalized() * delta as f32;
self.base_mut().set_position(tmp);
}
}

#[godot_api()]
impl StarWrathBullet {
fn init() {}
}
4 changes: 3 additions & 1 deletion gdrust/src/fight_items.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
mod block;
mod bar;
mod block_drawer;
mod health_bar;
15 changes: 15 additions & 0 deletions gdrust/src/fight_items/bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use godot::engine::{Control, IControl};
use godot::prelude::*;

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

#[godot_api()]
impl IControl for Bar {
fn init(base: Base<Control>) -> Self {
Self { base }
}
}
16 changes: 0 additions & 16 deletions gdrust/src/fight_items/block.rs

This file was deleted.

100 changes: 100 additions & 0 deletions gdrust/src/fight_items/block_drawer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use godot::engine::{Area2D, CollisionPolygon2D, INode2D, Node2D};
use godot::obj::WithBaseField;
use godot::prelude::*;

#[derive(GodotClass)]
#[class(base = Node2D)]
struct BlockDrawer {
base: Base<Node2D>,
#[var]
x: f32,
#[var]
y: f32,
}

const BLOCK_COLOR: Color = Color::from_rgb(10.0, 10.0, 10.0);
const WIDTH: f32 = 12.0;

#[godot_api]
impl INode2D for BlockDrawer {
fn init(base: Base<Node2D>) -> BlockDrawer {
// godot_print!("BlockDrawer created from Godot Rust");
Self {
x: Self::BOX_START_POS_X,
y: Self::BOX_START_POS_Y,
base,
}
}

fn ready(&mut self) {
let mut collision_obj = self
.base_mut()
.get_node_as::<CollisionPolygon2D>("collision/collision");
let mut points = PackedVector2Array::new();
points.push(Vector2::new(self.x, self.y));
points.push(Vector2::new(self.get_opposite_x(), self.y));
points.push(Vector2::new(
self.get_opposite_x(),
self.y + Self::Y_SIZE_DEFAULT,
));
points.push(Vector2::new(self.x, self.y + Self::Y_SIZE_DEFAULT));
collision_obj.set_polygon(points);
collision_obj.set_disabled(false);
}

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

fn draw(&mut self) {
let xsize = self.get_opposite_x();

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)),
BLOCK_COLOR,
)
.width(WIDTH)
.filled(false)
.done();
}
}

impl BlockDrawer {
fn get_opposite_x(&self) -> f32 {
let tmp = self.x;
let xsize = self.base().get_viewport_rect().size.x - tmp * 2.0;
xsize
}
}

#[godot_api]
impl BlockDrawer {
const BOX_START_POS_X: f32 = 400.0;
const BOX_START_POS_Y: f32 = 300.0;
const Y_SIZE_DEFAULT: f32 = 200.0;

#[func]
fn change_block_immediate(&mut self, x: f32, y: f32) {
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 i32
}

#[func]
fn get_x_min(&mut self) -> i32 {
// self.base().
(self.base().get_viewport_rect().size.x - self.x) as i32
}

#[func]
fn collision_signal(&mut self, obj: Gd<Area2D>) {}
}
17 changes: 17 additions & 0 deletions gdrust/src/fight_items/health_bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use godot::engine::{INode2D, Node2D};
use godot::prelude::*;

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

#[godot_api()]
impl INode2D for HealthBar {
fn init(base: Base<Node2D>) -> Self {
Self { base }
}

fn draw(&mut self) {}
}
3 changes: 3 additions & 0 deletions gdrust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod bullets;
mod fight_items;
mod player;
mod weapons;
mod zenith;

use godot::prelude::*;

Expand Down
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;
}
1 change: 1 addition & 0 deletions gdrust/src/weapons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod star_wrath;
23 changes: 23 additions & 0 deletions gdrust/src/weapons/star_wrath.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use godot::engine::{Area2D, IArea2D};
use godot::obj::WithBaseField;
use godot::prelude::*;

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

#[godot_api()]
impl IArea2D for StarWrath {
fn init(base: Base<Area2D>) -> Self {
Self { base }
}

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

#[godot_api()]
impl StarWrath {
fn init() {}
}
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 }
}
}
Binary file added resources/images/UIAct/Default/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6f95df8

Please sign in to comment.