diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-03-20 12:35:38 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-03-20 12:35:38 +0100 |
commit | ec95776771d061c21af17686491181c78b7955c9 (patch) | |
tree | 3b7558079f3c72664b4109e51872d17ffe2aed69 /src/main.rs | |
parent | e131d553d2526edb7cffbe9f4ba48d9c6ae4e44f (diff) |
draw grid
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 89 |
1 files changed, 60 insertions, 29 deletions
diff --git a/src/main.rs b/src/main.rs index c4e40f9..acecaad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,55 +23,86 @@ impl Cell { } } -struct Position { - x: f32, - y: f32, -} - -pub fn add_cells(commands: &mut Commands) { - for i in 0..8 { - for j in 0..8 { - commands.spawn(( - Cell::new(i, j), - Position { - x: (i as f32 * constants::TILE_HEIGHT), - y: (j as f32 * constants::TILE_WIDTH), - }, - )); - } - } -} - -pub fn add_background( +pub fn setup( commands: &mut Commands, asset_server: Res<AssetServer>, mut materials: ResMut<Assets<ColorMaterial>>, + mut texture_atlases: ResMut<Assets<TextureAtlas>>, ) { - let texture_handle = asset_server.load("background.png"); + let background = asset_server.load("background.png"); + let tileset = asset_server.load("tileset.png"); + + let atlas = TextureAtlas::from_grid(tileset, Vec2::new(16.0, 16.0), 4, 4); + let atlas_handle = texture_atlases.add(atlas); + commands - .spawn(Camera2dBundle { + .spawn(Camera2dBundle::default()) + .spawn(SpriteBundle { + material: materials.add(background.into()), transform: Transform { - translation: Vec3{ - x: -40.0, + translation: Vec3 { + x: 50.0, y: 0.0, z: 0.0, }, - scale: Vec3::splat(0.3), + scale: Vec3::splat(3.5), ..Default::default() }, ..Default::default() }) - .spawn(SpriteBundle { - material: materials.add(texture_handle.into()), + .spawn(SpriteSheetBundle { + sprite: TextureAtlasSprite::new(8), + texture_atlas: atlas_handle.clone(), + transform: Transform { + translation: Vec3 { + x: 225.0, + y: -200.0, + z: 0.0, + }, + scale: Vec3::splat(3.5), + ..Default::default() + }, + ..Default::default() + }) + .spawn(SpriteSheetBundle { + sprite: TextureAtlasSprite::new(12), + texture_atlas: atlas_handle.clone(), + transform: Transform { + translation: Vec3 { + x: 225.0, + y: -200.0 + (-16.0) * 3.5, + z: 0.0, + }, + scale: Vec3::splat(3.5), + ..Default::default() + }, ..Default::default() }); + + for i in 0..8 { + for j in 0..8 { + commands.spawn(SpriteSheetBundle { + sprite: TextureAtlasSprite::new(1), + texture_atlas: atlas_handle.clone(), + transform: Transform { + translation: Vec3 { + x: ((i as f32) * 16.0 * 3.5) - 320.0, + y: ((j as f32) * 16.0 * 3.5) - 170.0, + z: 0.0, + }, + scale: Vec3::splat(3.5), + ..Default::default() + }, + ..Default::default() + }); + } + } } pub struct GemsPlugin; impl Plugin for GemsPlugin { fn build(&self, app: &mut AppBuilder) { - app.add_startup_system(add_background.system()); - app.add_startup_system(add_cells.system()); + app.add_startup_system(setup.system()); } } |