|
@@ -2,12 +2,11 @@ use godot::prelude::*;
|
|
|
use godot::engine::{Sprite2D, ISprite2D};
|
|
|
|
|
|
struct MyExtension;
|
|
|
-
|
|
|
#[gdextension]
|
|
|
unsafe impl ExtensionLibrary for MyExtension {}
|
|
|
|
|
|
#[derive(GodotClass)]
|
|
|
-#[class(init, base=Sprite2D)]
|
|
|
+#[class(base=Sprite2D)]
|
|
|
struct Player {
|
|
|
#[export]
|
|
|
speed: f64,
|
|
@@ -20,17 +19,34 @@ struct Player {
|
|
|
|
|
|
#[godot_api]
|
|
|
impl ISprite2D for Player {
|
|
|
- /*fn init(base: Base<Sprite2D>) -> Self {
|
|
|
+ fn init(base: Base<Sprite2D>) -> Self {
|
|
|
godot_print!("Hello world!");
|
|
|
Self {
|
|
|
- speed: 400.0,
|
|
|
- angular_speed: std::f64::consts::PI,
|
|
|
+ speed: 0.0,
|
|
|
+ angular_speed: 0.0,
|
|
|
base,
|
|
|
}
|
|
|
- }*/
|
|
|
+ }
|
|
|
|
|
|
fn process(&mut self, delta: f64) {
|
|
|
- let rads = (self.angular_speed * delta) as f32;
|
|
|
- self.base_mut().rotate(rads);
|
|
|
+ if self.angular_speed != 0.0 {
|
|
|
+ let rads = (self.angular_speed * delta) as f32;
|
|
|
+ self.base_mut().rotate(rads);
|
|
|
+ if self.angular_speed > 0.0 {
|
|
|
+ self.angular_speed -= 0.01;
|
|
|
+ } else {
|
|
|
+ self.angular_speed += 0.01;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if self.speed != 0.0 {
|
|
|
+ let rot = self.base().get_rotation();
|
|
|
+ let vel = Vector2::UP.rotated(rot) * self.speed as f32;
|
|
|
+ self.base_mut().translate(vel * delta as f32);
|
|
|
+ if self.speed > 0.0 {
|
|
|
+ self.speed -= 0.1;
|
|
|
+ } else {
|
|
|
+ self.speed += 0.1;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|