1use bevy::{prelude::*, render::camera::ScalingMode};
2use bevy_pixel_map::{
3 chunk::{Chunk, ChunkBundle},
4 plugin::PixelPlugin,
5 tile::Tile,
6};
7
8pub fn main() {
9 App::new()
10 .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
11 .add_plugins(PixelPlugin)
12 .add_systems(Startup, setup_system)
13 .add_systems(PostStartup, set_tons_of_tiles)
14 .run()
15}
16
17pub fn setup_system(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
18 let mut camera_bundle = Camera2dBundle::default();
19 camera_bundle.projection.viewport_origin = Vec2::new(0.5, 0.5);
20 camera_bundle.projection.scaling_mode = ScalingMode::WindowSize(25.6);
21 commands.spawn(camera_bundle);
22
23 commands.spawn(ChunkBundle::new(IVec2::new(0, 0), Chunk::new(&mut images)));
24}
25
26pub fn set_tons_of_tiles(mut commands: Commands, mut chunks: Query<(Entity, &mut Chunk)>) {
27 let mut tile = Tile::from_color(Color::rgba(1.0, 1.0, 1.0, 1.0));
28 tile.set_pixel(IVec2::new(1, 5), Color::rgba(0.0, 1.0, 0.0, 1.0));
29 for (entity, mut chunk) in &mut chunks {
30 chunk.set_tile(entity, IVec2::new(3, 2), tile.clone(), (), &mut commands);
31 }
32}