use bevy::math::Vec3; use bevy::prelude::*; use gems::constants; enum Occupant { None, Green, } struct Cell { x: u8, y: u8, occupant: Occupant, } impl Cell { pub fn new(x: u8, y: u8) -> Cell { Cell { x, y, occupant: Occupant::None, } } } 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( commands: &mut Commands, asset_server: Res, mut materials: ResMut>, ) { let texture_handle = asset_server.load("background.png"); commands .spawn(Camera2dBundle { transform: Transform { translation: Vec3{ x: -40.0, y: 0.0, z: 0.0, }, scale: Vec3::splat(0.3), ..Default::default() }, ..Default::default() }) .spawn(SpriteBundle { material: materials.add(texture_handle.into()), ..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()); } } pub fn main() { App::build() .add_resource(WindowDescriptor { title: "gems".to_string(), width: 800.0, height: 600.0, resizable: false, ..Default::default() }) .add_plugins(DefaultPlugins) .add_plugin(GemsPlugin) .run(); }