use std::time::Duration; use bevy::{ color::palettes::css::{ORANGE, WHITE}, prelude::*, render::{camera::ScalingMode, texture::ImageLoaderSettings}, }; use bevy_neosprite::{ NeoMaterial, NeoMesh2dBundle, PointLight2d, PointLight2dBundle, Sprite2d, SpritePlugin, }; fn main() { App::new() .add_plugins(( DefaultPlugins.set(ImagePlugin::default_nearest()), SpritePlugin, )) .add_systems(Startup, (setup, setup_floor)) .add_systems(Update, (update_cursor_aim, animate)) .run(); } #[derive(Component)] pub struct Aaaaa; #[derive(Component)] pub struct FrameTimer(Timer); fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, asset_server: Res, ) { commands.spawn(Camera2dBundle { projection: OrthographicProjection { scaling_mode: ScalingMode::FixedVertical(40.), near: -1000.0, far: 1000.0, ..default() }, ..default() }); commands.spawn(PointLight2dBundle { point_light: PointLight2d { color: ORANGE.into(), intensity: 5000., range: 5., radius: 1., }, transform: Transform::from_xyz(0., 0., 3.), ..default() }); commands .spawn((SpatialBundle::default(), Aaaaa)) .with_children(|c| { c.spawn(NeoMesh2dBundle { mesh: meshes.add(Rectangle::new(4., 4.)).into(), transform: Transform::from_xyz(0., -0.2, 0.), material: materials.add(NeoMaterial { color: WHITE.into(), texture: Some(asset_server.load("sprites/spritesheet_diffuse.png")), normal: Some(asset_server.load_with_settings( "sprites/spritesheet_normal.png", |settings: &mut ImageLoaderSettings| settings.is_srgb = false, )), }), ..default() }) .insert(Sprite2d { sprites_horizontal: 10, sprites_vertical: 4, sprites_total: 9, sprite_index: 0, }) .insert(FrameTimer(Timer::new( Duration::from_secs_f32(0.15), TimerMode::Repeating, ))); }); } fn setup_floor( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, asset_server: Res, ) { let n = 30; let size = 8.; for x in -n..n { for y in -n..n { commands.spawn(NeoMesh2dBundle { mesh: meshes.add(Rectangle::new(size, size)).into(), transform: Transform::from_xyz(x as f32 * size, y as f32 * size, -0.01), material: materials.add(NeoMaterial { color: WHITE.into(), texture: Some(asset_server.load("sprites/cobblestone/diffuse.png")), normal: Some(asset_server.load_with_settings( "sprites/cobblestone/normal.png", |settings: &mut ImageLoaderSettings| settings.is_srgb = false, )), }), ..default() }); } } } fn update_cursor_aim( mut players: Query<&mut Transform, With>, q_window: Query<&Window>, q_camera: Query<(&Camera, &GlobalTransform)>, time: Res