player movement
This commit is contained in:
parent
3f47f0305e
commit
943a55dca7
3 changed files with 50 additions and 10 deletions
|
@ -8,7 +8,7 @@ info section
|
||||||
world section
|
world section
|
||||||
|
|
||||||
TT
|
TT
|
||||||
TTT _______ P ______ ___
|
TTT P _______ ______ ___
|
||||||
TTTTTTTTTEEEGGGGGGGETEGGGGGGEGGGE
|
TTTTTTTTTEEEGGGGGGGETEGGGGGGEGGGE
|
||||||
TTTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
|
TTTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
|
||||||
TTTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
|
TTTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
|
||||||
|
|
|
@ -12,7 +12,17 @@ use super::{scene::PlayerCoords, set::IngameSet};
|
||||||
mod animation;
|
mod animation;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Player;
|
struct Player {
|
||||||
|
move_cooldown: Timer,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Player {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
move_cooldown: Timer::from_seconds(0.01, TimerMode::Repeating),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct PlayerSpawnOneshot(pub SystemId);
|
pub struct PlayerSpawnOneshot(pub SystemId);
|
||||||
|
@ -24,7 +34,8 @@ impl FromWorld for PlayerSpawnOneshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn player_plugin(app: &mut App) {
|
pub(super) fn player_plugin(app: &mut App) {
|
||||||
app.init_resource::<PlayerSpawnOneshot>();
|
app.add_systems(Update, (move_player, debug_player_pos))
|
||||||
|
.init_resource::<PlayerSpawnOneshot>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Hash, PartialEq, Eq, Default)]
|
#[derive(Component, Hash, PartialEq, Eq, Default)]
|
||||||
|
@ -34,10 +45,39 @@ enum PlayerAnimations {
|
||||||
Walk,
|
Walk,
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn move_player(
|
fn debug_player_pos(query: Query<&Transform, With<Player>>) {
|
||||||
// kb_input: Res<ButtonInput<KeyCode>>,
|
let trans = query.single();
|
||||||
// mut query:
|
dbg!(trans);
|
||||||
// )
|
}
|
||||||
|
fn move_player(
|
||||||
|
kb_input: Res<ButtonInput<KeyCode>>,
|
||||||
|
mut query: Query<(
|
||||||
|
&mut Velocity,
|
||||||
|
&mut Player,
|
||||||
|
&mut KinematicCharacterController,
|
||||||
|
)>,
|
||||||
|
time: Res<Time>,
|
||||||
|
) {
|
||||||
|
let (mut vel, mut player, mut controller) = query.single_mut();
|
||||||
|
if player.move_cooldown.tick(time.delta()).finished() {
|
||||||
|
let mut moved = false;
|
||||||
|
let mut mv = 0;
|
||||||
|
|
||||||
|
if kb_input.pressed(KeyCode::KeyA) {
|
||||||
|
moved = true;
|
||||||
|
mv -= 1;
|
||||||
|
}
|
||||||
|
if kb_input.pressed(KeyCode::KeyD) {
|
||||||
|
moved = true;
|
||||||
|
mv += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if moved {
|
||||||
|
dbg!(mv);
|
||||||
|
controller.translation = Some(Vec2::new(mv as f32 * 6., 0.));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn add_player(
|
fn add_player(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
@ -83,7 +123,7 @@ fn add_player(
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Player,
|
Player::default(),
|
||||||
AnimBundle {
|
AnimBundle {
|
||||||
tag: PlayerAnimations::Idle,
|
tag: PlayerAnimations::Idle,
|
||||||
mgr: anims,
|
mgr: anims,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::fs;
|
||||||
use bevy::sprite::MaterialMesh2dBundle;
|
use bevy::sprite::MaterialMesh2dBundle;
|
||||||
use bevy::{core_pipeline::smaa::SmaaSpecializedRenderPipelines, prelude::*};
|
use bevy::{core_pipeline::smaa::SmaaSpecializedRenderPipelines, prelude::*};
|
||||||
use bevy::{prelude::*, scene::ScenePlugin};
|
use bevy::{prelude::*, scene::ScenePlugin};
|
||||||
use bevy_editor_pls::EditorPlugin;
|
// use bevy_editor_pls::EditorPlugin;
|
||||||
use bevy_rapier2d::prelude::{Collider, *};
|
use bevy_rapier2d::prelude::{Collider, *};
|
||||||
use readformat::{readf, readf1};
|
use readformat::{readf, readf1};
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl From<PlayerCoords> for Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn scene_plugin(app: &mut App) {
|
pub(super) fn scene_plugin(app: &mut App) {
|
||||||
app.add_plugins(EditorPlugin::default());
|
// app.add_plugins(EditorPlugin::default());
|
||||||
// app.add_systems(, )
|
// app.add_systems(, )
|
||||||
app.add_systems(Startup, (import_text_world,));
|
app.add_systems(Startup, (import_text_world,));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue