Skip to content
Snippets Groups Projects
Commit 314d4ec5 authored by Per Lindgren's avatar Per Lindgren
Browse files

left/right animation

parent f1ca432a
Branches
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld", "-Zshare-generics=y"]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=y"]
rustflags = ["-Zshare-generics=n"]
# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
......
{
"cSpell.ignoreWords": [
"fixed",
"timestep"
"timestep",
"vsync"
]
}
\ No newline at end of file
......@@ -8,7 +8,9 @@ fn main() {
.insert_resource(WindowDescriptor {
title: "My Little Zombie".to_string(),
width: 1920.,
height: 1081.,
height: 1080.,
vsync: true,
resizable: false,
..Default::default()
})
.add_startup_system(setup.system())
......@@ -63,7 +65,7 @@ impl Default for Player {
fn default() -> Self {
Player {
state: State::Idle,
index: 0,
index: 3,
}
}
}
......@@ -75,6 +77,7 @@ fn player_movement(
) {
if let Ok((mut player, mut transform, mut sprite)) = query.single_mut() {
let (index, state, dir) = if keyboard_input.pressed(KeyCode::Right) {
sprite.flip_x = false;
match player.state {
// already walking
State::Right => {
......@@ -89,6 +92,22 @@ fn player_movement(
(index, State::Right, 2.)
}
}
} else if keyboard_input.pressed(KeyCode::Left) {
sprite.flip_x = true;
match player.state {
// already walking
State::Left => {
let index = (player.index + 1) % 32;
sprite.index = (4 * 9) + index / 4;
(index, State::Left, -2.)
}
// starting walking
_ => {
let index = 3 * 4;
sprite.index = (4 * 9) + index / 4;
(index, State::Left, -2.)
}
}
} else {
sprite.index = 0;
(0, State::Idle, 0.)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment