// In this game, you can move the camera with the arrow keys, and switch the mage's canvas // by pressing space use bevy::prelude::*; use rand::{thread_rng, Rng}; use seldom_pixel::prelude::*; fn main() { App::new() .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { resolution: Vec2::splat(512.).into(), ..default() }), ..default() }), PxPlugin::::new(UVec2::splat(64), "palette/palette_1.png".into()), )) .insert_resource(ClearColor(Color::BLACK)) .add_systems(Startup, init) .add_systems(Update, (move_mage, move_camera, switch_canvas)) .run(); } fn init(mut commands: Commands, mut sprites: PxAssets) { commands.spawn(Camera2dBundle::default()); // `PxSubPosition` contains a `Vec2`. This is used // to represent the camera's sub-pixel position, which is rounded and applied // to the camera's pixel position. commands.spawn((PxSubPosition::default(), CameraPos)); // By default, the mage is on the world canvas, which means you see it in different positions // based on where the camera is commands.spawn(( PxSpriteBundle:: { sprite: sprites.load("sprite/mage.png"), position: IVec2::splat(32).into(), ..default() }, Mage, )); } #[derive(Component)] struct CameraPos; const CAMERA_SPEED: f32 = 10.; // Move the camera based on the arrow keys fn move_camera( mut camera_poses: Query<&mut PxSubPosition, With>, keys: Res>, time: Res