KHDJHPQ5ORKYPEDSMCJV76OF5OEXNU5K6MBB6DROQJ3RNLSBS64AC
MKRLBBZMDBIZEBXHRCBD2ZEKAUP4TPMOX6AC4ZOV4L2S7A7FWFPQC
BTR6N7MXA2E6C2SFSLTN6BD5E2R5JNFPUL5RPIFBX62QWCO2ASPAC
32P3IHGQEWNR6YN3DESLS4DKZJ55JLWA7LGLONKEDPSXFOEK34FAC
O4C7RMEST2263UZERB2CU4S4JW3ICZ7UJWEVOTDTVNAF44SCP2DQC
D6RN4IZZ7VI6TKZK4HKD5J3KWMWJSB2QXJOYY7TIXQ5CR7RQ6O2QC
Q7WHCTC4ARX6TBEKVX5HCHCDDFZ7VGCAY3WMS37ZI4F4NR36SBWQC
ZBXFR4EQACOIJ35EETMJSL7VPWLGO3Z52BBUGLRTCF6OGQGUKWMAC
SJTZ53IBAUM55GUNDXRRQY6BJHIT4L3UR656PMLMXS42ZQSWL2KQC
MDQDXQHZI3TV2PE4WUG2IQRKVHYDKIWCZYQIQLE74LNG6RPPR3YAC
YM7CYP3LBSNZPT4X6OE7J4TPHVE7IJLZZXJBR3C7UG442DGUVRIAC
ZXAK75RPH25ZNDZ6VMIGXISHUEFWXNG6ROUY5OXK4UIADR4QJMTQC
SRSAJDUS3GJP75CBMZHEAPRKBRG3M3PU3JSEL2KD7PGUCJX46YAQC
5DULGXTSH7NW7TQKDSJB4LQA2S2PKKD7RPC7O3Z4T3KFY6GYFDYAC
// Create the snake's head
commands
.spawn(SpriteBundle {
sprite: Sprite {
color: Color::oklch(1.1, 0.126, 299.66),
..default()
},
transform: Transform {
scale: Vec3::splat(10.0),
}
fn spawn_snake(mut commands: Commands, mut segments: ResMut<SnakeSegments>) {
*segments = SnakeSegments(vec![
commands
.spawn(SpriteBundle {
sprite: Sprite {
color: Color::oklch(1.1, 0.126, 299.66),
..default()
},
transform: Transform {
scale: Vec3::splat(10.0),
..default()
},
},
..default()
})
.insert(SnakeHead { direction: Direction::Up, })
.insert(Position { x: 3, y: 3 })
.insert(Size(0.8));
})
.insert(SnakeHead {
direction: Direction::Up,
})
.insert(Position { x: 3, y: 3 })
.insert(Size(0.8))
.id(),
spawn_segment(commands, Position { x: 3, y: 2 }),
]);
let dir: Direction =
if keyboard_input.pressed(KeyCode::KeyA) {
Direction::Left
}
else if keyboard_input.pressed(KeyCode::KeyD) {
Direction::Right
}
else if keyboard_input.pressed(KeyCode::KeyS) {
Direction::Down
}
else if keyboard_input.pressed(KeyCode::KeyW) {
Direction::Up
} else {
head.direction
};
let dir: Direction = if keyboard_input.pressed(KeyCode::KeyA) {
Direction::Left
} else if keyboard_input.pressed(KeyCode::KeyD) {
Direction::Right
} else if keyboard_input.pressed(KeyCode::KeyS) {
Direction::Down
} else if keyboard_input.pressed(KeyCode::KeyW) {
Direction::Up
} else {
head.direction
};