From e131d553d2526edb7cffbe9f4ba48d9c6ae4e44f Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sat, 20 Mar 2021 11:17:52 +0100 Subject: draw background --- assets/background.png | Bin 0 -> 3910 bytes assets/cosmonaut.png | Bin 0 -> 1066 bytes assets/tileset.png | Bin 0 -> 2662 bytes resources/background.png | Bin 332251 -> 0 bytes resources/cosmonaut.png | Bin 1066 -> 0 bytes resources/tileset.png | Bin 2662 -> 0 bytes src/main.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 assets/background.png create mode 100644 assets/cosmonaut.png create mode 100644 assets/tileset.png delete mode 100644 resources/background.png delete mode 100644 resources/cosmonaut.png delete mode 100644 resources/tileset.png diff --git a/assets/background.png b/assets/background.png new file mode 100644 index 0000000..060989b Binary files /dev/null and b/assets/background.png differ diff --git a/assets/cosmonaut.png b/assets/cosmonaut.png new file mode 100644 index 0000000..a4fd017 Binary files /dev/null and b/assets/cosmonaut.png differ diff --git a/assets/tileset.png b/assets/tileset.png new file mode 100644 index 0000000..d519715 Binary files /dev/null and b/assets/tileset.png differ diff --git a/resources/background.png b/resources/background.png deleted file mode 100644 index 6ad2950..0000000 Binary files a/resources/background.png and /dev/null differ diff --git a/resources/cosmonaut.png b/resources/cosmonaut.png deleted file mode 100644 index a4fd017..0000000 Binary files a/resources/cosmonaut.png and /dev/null differ diff --git a/resources/tileset.png b/resources/tileset.png deleted file mode 100644 index d519715..0000000 Binary files a/resources/tileset.png and /dev/null differ 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, + 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().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(); } -- cgit v1.2.3