summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-20 11:17:52 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-20 11:17:52 +0100
commite131d553d2526edb7cffbe9f4ba48d9c6ae4e44f (patch)
tree6d864941162e959847b57186264ee95fa02660c4 /src/main.rs
parentd2c59a4d07efa3ec4418d7e82352a1cdf38e1518 (diff)
draw background
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs90
1 files changed, 86 insertions, 4 deletions
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();
}