Added dash as a mode (badly I'll fix it later)
parent
253e1654d8
commit
32ed8b2bf8
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
|
@ -1,8 +1,9 @@
|
||||||
|
|
||||||
#These values you can just go edit no problem
|
#These values you can just go edit no problem
|
||||||
speed: 0.3
|
sprite_path: blobcat_hertog.png
|
||||||
|
speed: 75.0
|
||||||
movement: [
|
movement: [
|
||||||
10.0,
|
0.0,
|
||||||
0.0
|
0.0
|
||||||
]
|
]
|
||||||
#These you should leave alone
|
#These you should leave alone
|
||||||
|
@ -11,4 +12,5 @@
|
||||||
0.0
|
0.0
|
||||||
]
|
]
|
||||||
dash: false
|
dash: false
|
||||||
|
dash_modifier: 0.3
|
||||||
|
|
88
src/main.rs
88
src/main.rs
|
@ -11,12 +11,23 @@ pub struct Settings {
|
||||||
pub right: String,
|
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 struct Player {
|
||||||
pub speed: f32,
|
pub speed: f32,
|
||||||
pub movement: Vec2,
|
pub movement: Vec2,
|
||||||
pub direction: Vec2,
|
pub direction: Vec2,
|
||||||
pub dash: bool,
|
pub dash: bool,
|
||||||
|
pub dash_modifier: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -50,21 +61,26 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
down: S
|
down: S
|
||||||
left: A
|
left: A
|
||||||
right: D
|
right: D
|
||||||
".to_string();
|
"
|
||||||
|
.to_string();
|
||||||
let settings_file = Path::new("./data/settings.yml");
|
let settings_file = Path::new("./data/settings.yml");
|
||||||
if settings_file.exists() {
|
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 {
|
} 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>(&settings_yaml).expect("Error serializing to YAML");
|
let settings_data =
|
||||||
|
serde_yaml::from_str::<Settings>(&settings_yaml).expect("Error serializing to YAML");
|
||||||
|
|
||||||
//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
|
||||||
speed: 0.3
|
sprite_path: blobcat_hertog.png
|
||||||
|
speed: 75.0
|
||||||
movement: [
|
movement: [
|
||||||
10.0,
|
0.0,
|
||||||
0.0
|
0.0
|
||||||
]
|
]
|
||||||
#These you should leave alone
|
#These you should leave alone
|
||||||
|
@ -73,21 +89,26 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
0.0
|
0.0
|
||||||
]
|
]
|
||||||
dash: false
|
dash: false
|
||||||
".to_string();
|
dash_modifier: 0.3
|
||||||
|
"
|
||||||
|
.to_string();
|
||||||
let player_data_file = Path::new("./data/player_data.yml");
|
let player_data_file = Path::new("./data/player_data.yml");
|
||||||
if player_data_file.exists() {
|
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 {
|
} 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>(&player_data_yaml).expect("Error serializing to YAML");
|
let player_data =
|
||||||
|
serde_yaml::from_str::<PlayerYAML>(&player_data_yaml).expect("Error serializing to YAML");
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
SpriteBundle {
|
SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
custom_size: Some(Vec2::new(50.0, 50.0)),
|
custom_size: Some(Vec2::new(50.0, 50.0)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
texture: asset_server.load("blobcat_hertog.png"),
|
texture: asset_server.load(player_data.sprite_path),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
//TODO: find out how to use vectors in json so I don't have to use this array fuckery
|
//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<AssetServer>) {
|
||||||
movement: Vec2::new(player_data.movement.x, player_data.movement.y),
|
movement: Vec2::new(player_data.movement.x, player_data.movement.y),
|
||||||
direction: Vec2::new(player_data.direction.x, player_data.direction.y),
|
direction: Vec2::new(player_data.direction.x, player_data.direction.y),
|
||||||
dash: player_data.dash,
|
dash: player_data.dash,
|
||||||
|
dash_modifier: player_data.dash_modifier,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -130,19 +152,54 @@ fn get_input(mut input_recievers: Query<&mut Player>, input: Res<Input<KeyCode>>
|
||||||
if input.just_released(KeyCode::A) {
|
if input.just_released(KeyCode::A) {
|
||||||
player.direction.x += 1.0;
|
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<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 current_speed: f32 = player.speed;
|
let dash_modifier: f32 = player.dash_modifier;
|
||||||
let current_movement: Vec2 = player.movement;
|
let current_movement: Vec2 = player.movement;
|
||||||
|
if player.dash == false {
|
||||||
|
if player.direction.y == 1.0 && player.movement.y <= 1.0 {
|
||||||
|
player.movement.y += player.speed;
|
||||||
|
}
|
||||||
|
if player.direction.y == 0.0 && player.movement.y >= 1.0 {
|
||||||
|
player.movement.y -= player.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if player.direction.y == -1.0 && player.movement.y >= -1.0 {
|
||||||
|
player.movement.y -= player.speed;
|
||||||
|
}
|
||||||
|
if player.direction.y == 0.0 && player.movement.y <= -1.0 {
|
||||||
|
player.movement.y += player.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if player.direction.x == 1.0 && player.movement.x <= 1.0 {
|
||||||
|
player.movement.x += player.speed;
|
||||||
|
}
|
||||||
|
if player.direction.x == 0.0 && player.movement.x >= 1.0 {
|
||||||
|
player.movement.x -= player.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if player.direction.x == -1.0 && player.movement.x >= -1.0 {
|
||||||
|
player.movement.x -= player.speed;
|
||||||
|
}
|
||||||
|
if player.direction.x == 0.0 && player.movement.x <= -1.0 {
|
||||||
|
player.movement.x += player.speed;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if player.direction.y == 1.0 {
|
if player.direction.y == 1.0 {
|
||||||
player.movement += current_movement * current_speed;
|
player.movement += current_movement * dash_modifier;
|
||||||
}
|
}
|
||||||
if player.direction.y == -1.0 {
|
if player.direction.y == -1.0 {
|
||||||
player.movement -= current_movement * current_speed;
|
player.movement -= current_movement * dash_modifier;
|
||||||
}
|
}
|
||||||
if player.direction.x == 1.0 {
|
if player.direction.x == 1.0 {
|
||||||
player.movement = Vec2::new(
|
player.movement = Vec2::new(
|
||||||
|
@ -156,6 +213,7 @@ fn character_movement(mut characters: Query<(&mut Transform, &mut Player)>, time
|
||||||
player.movement.y - player.movement.x * 0.1,
|
player.movement.y - player.movement.x * 0.1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: make locking the player within bounds not ass and use the screensize instead of magic numbers
|
//TODO: make locking the player within bounds not ass and use the screensize instead of magic numbers
|
||||||
if transform.translation.x < 250.0 && transform.translation.x > -250.0 {
|
if transform.translation.x < 250.0 && transform.translation.x > -250.0 {
|
||||||
|
|
Loading…
Reference in New Issue