summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: c4e40f93e3e2f75bbac1f3acf524fc5b2b1968f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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<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()
        .add_resource(WindowDescriptor {
            title: "gems".to_string(),
            width: 800.0,
            height: 600.0,
            resizable: false,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_plugin(GemsPlugin)
        .run();
}