diff options
-rw-r--r-- | assets/background.png | bin | 0 -> 3910 bytes | |||
-rw-r--r-- | assets/cosmonaut.png (renamed from resources/cosmonaut.png) | bin | 1066 -> 1066 bytes | |||
-rw-r--r-- | assets/tileset.png (renamed from resources/tileset.png) | bin | 2662 -> 2662 bytes | |||
-rw-r--r-- | resources/background.png | bin | 332251 -> 0 bytes | |||
-rw-r--r-- | src/main.rs | 90 |
5 files changed, 86 insertions, 4 deletions
diff --git a/assets/background.png b/assets/background.png Binary files differnew file mode 100644 index 0000000..060989b --- /dev/null +++ b/assets/background.png diff --git a/resources/cosmonaut.png b/assets/cosmonaut.png Binary files differindex a4fd017..a4fd017 100644 --- a/resources/cosmonaut.png +++ b/assets/cosmonaut.png diff --git a/resources/tileset.png b/assets/tileset.png Binary files differindex d519715..d519715 100644 --- a/resources/tileset.png +++ b/assets/tileset.png diff --git a/resources/background.png b/resources/background.png Binary files differdeleted file mode 100644 index 6ad2950..0000000 --- a/resources/background.png +++ /dev/null diff --git a/src/main.rs b/src/main.rs index 30df8fb..c4e40f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,90 @@ -use bevy::prelude::App; +use bevy::math::Vec3; +use bevy::prelude::*; +use gems::constants; -struct Gem; -struct Position { x: f32, y: f32} +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<AssetServer>, + mut materials: ResMut<Assets<ColorMaterial>>, +) { + 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().run(); + 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(); } |