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
|
||||
|
||||
TT
|
||||
TTT _______ P ______ ___
|
||||
TTT P _______ ______ ___
|
||||
TTTTTTTTTEEEGGGGGGGETEGGGGGGEGGGE
|
||||
TTTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
|
||||
TTTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
|
||||
|
|
|
@ -12,7 +12,17 @@ use super::{scene::PlayerCoords, set::IngameSet};
|
|||
mod animation;
|
||||
|
||||
#[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)]
|
||||
pub struct PlayerSpawnOneshot(pub SystemId);
|
||||
|
@ -24,7 +34,8 @@ impl FromWorld for PlayerSpawnOneshot {
|
|||
}
|
||||
|
||||
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)]
|
||||
|
@ -34,10 +45,39 @@ enum PlayerAnimations {
|
|||
Walk,
|
||||
}
|
||||
|
||||
// fn move_player(
|
||||
// kb_input: Res<ButtonInput<KeyCode>>,
|
||||
// mut query:
|
||||
// )
|
||||
fn debug_player_pos(query: Query<&Transform, With<Player>>) {
|
||||
let trans = query.single();
|
||||
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(
|
||||
mut commands: Commands,
|
||||
|
@ -83,7 +123,7 @@ fn add_player(
|
|||
|
||||
commands
|
||||
.spawn((
|
||||
Player,
|
||||
Player::default(),
|
||||
AnimBundle {
|
||||
tag: PlayerAnimations::Idle,
|
||||
mgr: anims,
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::fs;
|
|||
use bevy::sprite::MaterialMesh2dBundle;
|
||||
use bevy::{core_pipeline::smaa::SmaaSpecializedRenderPipelines, prelude::*};
|
||||
use bevy::{prelude::*, scene::ScenePlugin};
|
||||
use bevy_editor_pls::EditorPlugin;
|
||||
// use bevy_editor_pls::EditorPlugin;
|
||||
use bevy_rapier2d::prelude::{Collider, *};
|
||||
use readformat::{readf, readf1};
|
||||
|
||||
|
@ -48,7 +48,7 @@ impl From<PlayerCoords> for Transform {
|
|||
}
|
||||
|
||||
pub(super) fn scene_plugin(app: &mut App) {
|
||||
app.add_plugins(EditorPlugin::default());
|
||||
// app.add_plugins(EditorPlugin::default());
|
||||
// app.add_systems(, )
|
||||
app.add_systems(Startup, (import_text_world,));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue