Skip to content

Commit

Permalink
feat:make heart slide instead of blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jun 15, 2024
1 parent 9dd71b2 commit c47790f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 36 additions & 1 deletion gdrust/src/player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::panic;
use derive::gen_debug;
use godot::engine::{Area2D, CharacterBody2D, GpuParticles2D, ICharacterBody2D, Timer};
use godot::global::abs;
use godot::obj::WithBaseField;
use godot::prelude::*;
use real_consts::PI;
Expand Down Expand Up @@ -109,9 +110,43 @@ impl ICharacterBody2D for Player {
MOVE_DOWN.into(),
);
if vel != Vector2::ZERO {
let _res = self
let res = self
.base_mut()
.move_and_collide(vel.normalized() * Self::SPEED as f32 * down_rate * delta as f32);
if let Some(obj) = res {
let me = self.base_mut().get_position();
let point = obj.get_position();
let diff_x = (me.x - point.x).abs().abs();
let diff_y = (me.y - point.y).abs().abs();
if (diff_x - diff_y).abs() >= 6.0 {
// 确认没有卡墙角
let vel = if diff_x > diff_y {
Vector2::new(
0.0,
if input_obj.is_action_pressed(MOVE_UP.into()) {
-1.0
} else if input_obj.is_action_pressed(MOVE_DOWN.into()) {
1.0
} else {
0.0
},
)
} else {
Vector2::new(
if input_obj.is_action_pressed(MOVE_LEFT.into()) {
-1.0
} else if input_obj.is_action_pressed(MOVE_RIGHT.into()) {
1.0
} else {
0.0
},
0.0,
)
};
self.base_mut()
.move_and_collide(vel * Self::SPEED as f32 * down_rate * delta as f32);
}
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions scenes/fight.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ texture = ExtResource("3_2spkb")
[node name="Player" type="Player" parent="."]
position = Vector2(570, 414)
scale = Vector2(0.2, 0.2)
motion_mode = 1
floor_stop_on_slope = false
floor_block_on_wall = false
floor_max_angle = 1.5708
platform_floor_layers = 0
platform_wall_layers = 4294967295

[node name="virtual" type="GPUParticles2D" parent="Player"]
emitting = false
Expand Down

0 comments on commit c47790f

Please sign in to comment.