diff --git a/assets/neocat.png b/assets/neocat.png new file mode 100755 index 0000000..bb2e0b2 Binary files /dev/null and b/assets/neocat.png differ diff --git a/data/player_data.yml b/data/player_data.yml index a81e1af..c12ccdd 100644 --- a/data/player_data.yml +++ b/data/player_data.yml @@ -1,8 +1,9 @@ #These values you can just go edit no problem - speed: 0.3 + sprite_path: blobcat_hertog.png + speed: 75.0 movement: [ - 10.0, + 0.0, 0.0 ] #These you should leave alone @@ -11,4 +12,5 @@ 0.0 ] dash: false + dash_modifier: 0.3 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index acac47e..8cbcb9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,12 +11,23 @@ pub struct Settings { pub right: String, } -#[derive(Component, Serialize, Deserialize)] +#[derive(Serialize, Deserialize)] +pub struct PlayerYAML { + pub sprite_path: String, + pub speed: f32, + pub movement: Vec2, + pub direction: Vec2, + pub dash: bool, + pub dash_modifier: f32, +} + +#[derive(Component)] pub struct Player { pub speed: f32, pub movement: Vec2, pub direction: Vec2, pub dash: bool, + pub dash_modifier: f32, } fn main() { @@ -50,21 +61,26 @@ fn setup(mut commands: Commands, asset_server: Res) { down: S left: A right: D - ".to_string(); + " + .to_string(); let settings_file = Path::new("./data/settings.yml"); if settings_file.exists() { - settings_yaml = fs::read_to_string("./data/settings.yml").expect("Error reading data/settings.yml"); + settings_yaml = + fs::read_to_string("./data/settings.yml").expect("Error reading data/settings.yml"); } else { - fs::write("./data/settings.yml", settings_yaml.clone()).expect("Error writing data/settings.yml"); + fs::write("./data/settings.yml", settings_yaml.clone()) + .expect("Error writing data/settings.yml"); } - let settings_data = serde_yaml::from_str::(&settings_yaml).expect("Error serializing to YAML"); - - //Default player_data + let settings_data = + serde_yaml::from_str::(&settings_yaml).expect("Error serializing to YAML"); + + //Default player_data let mut player_data_yaml: String = " #These values you can just go edit no problem - speed: 0.3 + sprite_path: blobcat_hertog.png + speed: 75.0 movement: [ - 10.0, + 0.0, 0.0 ] #These you should leave alone @@ -73,21 +89,26 @@ fn setup(mut commands: Commands, asset_server: Res) { 0.0 ] dash: false - ".to_string(); + dash_modifier: 0.3 + " + .to_string(); let player_data_file = Path::new("./data/player_data.yml"); if player_data_file.exists() { - player_data_yaml = fs::read_to_string("./data/player_data.yml").expect("Error reading data/player_data.yml"); + player_data_yaml = fs::read_to_string("./data/player_data.yml") + .expect("Error reading data/player_data.yml"); } else { - fs::write("./data/player_data.yml", player_data_yaml.clone()).expect("Error writing data/player_data.yml"); + fs::write("./data/player_data.yml", player_data_yaml.clone()) + .expect("Error writing data/player_data.yml"); } - let player_data = serde_yaml::from_str::(&player_data_yaml).expect("Error serializing to YAML"); + let player_data = + serde_yaml::from_str::(&player_data_yaml).expect("Error serializing to YAML"); commands.spawn(( SpriteBundle { sprite: Sprite { custom_size: Some(Vec2::new(50.0, 50.0)), ..default() }, - texture: asset_server.load("blobcat_hertog.png"), + texture: asset_server.load(player_data.sprite_path), ..default() }, //TODO: find out how to use vectors in json so I don't have to use this array fuckery @@ -96,6 +117,7 @@ fn setup(mut commands: Commands, asset_server: Res) { movement: Vec2::new(player_data.movement.x, player_data.movement.y), direction: Vec2::new(player_data.direction.x, player_data.direction.y), dash: player_data.dash, + dash_modifier: player_data.dash_modifier, }, )); } @@ -130,31 +152,67 @@ fn get_input(mut input_recievers: Query<&mut Player>, input: Res> if input.just_released(KeyCode::A) { player.direction.x += 1.0; } + + if input.just_pressed(KeyCode::Space) { + player.dash = true; + } + if input.just_released(KeyCode::Space) { + player.dash = false; + } } } fn character_movement(mut characters: Query<(&mut Transform, &mut Player)>, time: Res