From d40e05da3a89a26dd95192d5ddaf53e3537a89cc Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 26 Jan 2024 17:27:29 +0000 Subject: [PATCH] Add initial plugin creating a 256x256 texture --- src/falling_sand/mod.rs | 42 +++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 src/falling_sand/mod.rs diff --git a/src/falling_sand/mod.rs b/src/falling_sand/mod.rs new file mode 100644 index 0000000..0f0d0c5 --- /dev/null +++ b/src/falling_sand/mod.rs @@ -0,0 +1,42 @@ +use bevy::{ + app::{Plugin, Startup}, + asset::Assets, + ecs::system::{Commands, ResMut}, + math::Vec3, + prelude::*, + render::{ + render_resource::{Extent3d, TextureDimension, TextureFormat}, + texture::Image, + }, + sprite::SpriteBundle, + transform::components::Transform, +}; + +pub struct FallingSandPlugin; + +impl Plugin for FallingSandPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.add_systems(Startup, setup); + } +} + +fn setup(mut commands: Commands, mut images: ResMut>) { + let image = Image::new_fill( + Extent3d { + width: 256, + height: 256, + depth_or_array_layers: 1, + }, + TextureDimension::D2, + &[25, 24, 26, 255], + TextureFormat::Rgba8UnormSrgb, + ); + + let image_handle = images.add(image); + + commands.spawn(SpriteBundle { + texture: image_handle, + transform: Transform::from_translation(Vec3::new(256., 0., 0.)), + ..default() + }); +} diff --git a/src/main.rs b/src/main.rs index 9ff4c5a..70f9b3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod falling_sand; + use bevy::{prelude::*, window::PresentMode}; fn main() { @@ -17,6 +19,7 @@ fn main() { .set(window_plugin) .set(ImagePlugin::default_nearest()), ) + .add_plugins(falling_sand::FallingSandPlugin) .add_systems(Startup, setup) .insert_resource(ClearColor(Color::rgb_u8(45, 42, 46))) .run();