Displayer input
parent
32ed8b2bf8
commit
af393f6a30
|
@ -3,5 +3,14 @@
|
||||||
up: W
|
up: W
|
||||||
down: S
|
down: S
|
||||||
left: A
|
left: A
|
||||||
right: D
|
right: D
|
||||||
|
input_sprite_path: neocat.png
|
||||||
|
input_sprite_size: [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
input_sprite_location: [
|
||||||
|
-200.0,
|
||||||
|
-200.0
|
||||||
|
]
|
||||||
|
|
66
src/main.rs
66
src/main.rs
|
@ -9,6 +9,9 @@ pub struct Settings {
|
||||||
pub down: String,
|
pub down: String,
|
||||||
pub left: String,
|
pub left: String,
|
||||||
pub right: String,
|
pub right: String,
|
||||||
|
pub input_sprite_path: String,
|
||||||
|
pub input_sprite_size: Vec2,
|
||||||
|
pub input_sprite_location: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -30,6 +33,12 @@ pub struct Player {
|
||||||
pub dash_modifier: f32,
|
pub dash_modifier: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct InputVisual {
|
||||||
|
pub location: Vec2,
|
||||||
|
pub input_direction: Vec2,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(
|
.add_plugins(
|
||||||
|
@ -48,6 +57,7 @@ fn main() {
|
||||||
)
|
)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, get_input)
|
.add_systems(Update, get_input)
|
||||||
|
.add_systems(Update, draw_input)
|
||||||
.add_systems(Update, character_movement)
|
.add_systems(Update, character_movement)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +70,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
up: W
|
up: W
|
||||||
down: S
|
down: S
|
||||||
left: A
|
left: A
|
||||||
right: D
|
right: D
|
||||||
|
input_sprite_path: neocat.png
|
||||||
|
input_sprite_size: [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
input_sprite_location: [
|
||||||
|
-200.0,
|
||||||
|
-200.0
|
||||||
|
]
|
||||||
"
|
"
|
||||||
.to_string();
|
.to_string();
|
||||||
let settings_file = Path::new("./data/settings.yml");
|
let settings_file = Path::new("./data/settings.yml");
|
||||||
|
@ -74,6 +93,27 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let settings_data =
|
let settings_data =
|
||||||
serde_yaml::from_str::<Settings>(&settings_yaml).expect("Error serializing to YAML");
|
serde_yaml::from_str::<Settings>(&settings_yaml).expect("Error serializing to YAML");
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
SpriteBundle {
|
||||||
|
sprite: Sprite {
|
||||||
|
custom_size: Some(Vec2::new(
|
||||||
|
settings_data.input_sprite_size.x,
|
||||||
|
settings_data.input_sprite_size.y,
|
||||||
|
)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
texture: asset_server.load(settings_data.input_sprite_path),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
InputVisual {
|
||||||
|
location: Vec2::new(
|
||||||
|
settings_data.input_sprite_location.x,
|
||||||
|
settings_data.input_sprite_location.y,
|
||||||
|
),
|
||||||
|
input_direction: Vec2::new(0.0, 0.0),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
//Default player_data
|
//Default player_data
|
||||||
let mut player_data_yaml: String = "
|
let mut player_data_yaml: String = "
|
||||||
#These values you can just go edit no problem
|
#These values you can just go edit no problem
|
||||||
|
@ -162,6 +202,17 @@ fn get_input(mut input_recievers: Query<&mut Player>, input: Res<Input<KeyCode>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_input(mut visuals: Query<(&mut Transform, &mut InputVisual)>, input: Query<&mut Player>) {
|
||||||
|
for player in &input {
|
||||||
|
for (mut transform, mut visual) in &mut visuals {
|
||||||
|
visual.input_direction.x = player.direction.x;
|
||||||
|
visual.input_direction.y = player.direction.y;
|
||||||
|
transform.translation.x = visual.location.x + (visual.input_direction.x * 10.0);
|
||||||
|
transform.translation.y = visual.location.y + (visual.input_direction.y * 10.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn character_movement(mut characters: Query<(&mut Transform, &mut Player)>, time: Res<Time>) {
|
fn character_movement(mut characters: Query<(&mut Transform, &mut Player)>, time: Res<Time>) {
|
||||||
for (mut transform, mut player) in &mut characters {
|
for (mut transform, mut player) in &mut characters {
|
||||||
let dash_modifier: f32 = player.dash_modifier;
|
let dash_modifier: f32 = player.dash_modifier;
|
||||||
|
@ -215,16 +266,7 @@ fn character_movement(mut characters: Query<(&mut Transform, &mut Player)>, time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make locking the player within bounds not ass and use the screensize instead of magic numbers
|
transform.translation.x += player.movement.x * time.delta_seconds();
|
||||||
if transform.translation.x < 250.0 && transform.translation.x > -250.0 {
|
transform.translation.y += player.movement.y * time.delta_seconds();
|
||||||
transform.translation.x += player.movement.x * time.delta_seconds();
|
|
||||||
} else {
|
|
||||||
player.movement.x = -player.movement.x;
|
|
||||||
}
|
|
||||||
if transform.translation.y < 250.0 && transform.translation.y > -250.0 {
|
|
||||||
transform.translation.y += player.movement.y * time.delta_seconds();
|
|
||||||
} else {
|
|
||||||
player.movement.y = -player.movement.y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue