summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-20 12:35:38 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-20 12:35:38 +0100
commitec95776771d061c21af17686491181c78b7955c9 (patch)
tree3b7558079f3c72664b4109e51872d17ffe2aed69
parente131d553d2526edb7cffbe9f4ba48d9c6ae4e44f (diff)
draw grid
-rw-r--r--assets/cosmonaut.pngbin1066 -> 0 bytes
-rw-r--r--assets/tileset.pngbin2662 -> 18168 bytes
-rw-r--r--src/constants.rs2
-rw-r--r--src/main.rs89
4 files changed, 61 insertions, 30 deletions
diff --git a/assets/cosmonaut.png b/assets/cosmonaut.png
deleted file mode 100644
index a4fd017..0000000
--- a/assets/cosmonaut.png
+++ /dev/null
Binary files differ
diff --git a/assets/tileset.png b/assets/tileset.png
index d519715..1d190d8 100644
--- a/assets/tileset.png
+++ b/assets/tileset.png
Binary files differ
diff --git a/src/constants.rs b/src/constants.rs
index f9a5003..5952fa5 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -1,5 +1,5 @@
pub const TILE_SCALE: f32 = 3.0;
-pub const TILE_HEIGHT: f32 = 16.0;
+pub const TILE_SIZE: f32 = 16.0;
pub const TILE_WIDTH: f32 = 16.0;
pub const BORDER_SIZE: f32 = 3.0;
pub const SHIFT_X: f32 = 50.0;
diff --git a/src/main.rs b/src/main.rs
index c4e40f9..acecaad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,55 +23,86 @@ impl Cell {
}
}
-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(
+pub fn setup(
commands: &mut Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
+ mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
- let texture_handle = asset_server.load("background.png");
+ let background = asset_server.load("background.png");
+ let tileset = asset_server.load("tileset.png");
+
+ let atlas = TextureAtlas::from_grid(tileset, Vec2::new(16.0, 16.0), 4, 4);
+ let atlas_handle = texture_atlases.add(atlas);
+
commands
- .spawn(Camera2dBundle {
+ .spawn(Camera2dBundle::default())
+ .spawn(SpriteBundle {
+ material: materials.add(background.into()),
transform: Transform {
- translation: Vec3{
- x: -40.0,
+ translation: Vec3 {
+ x: 50.0,
y: 0.0,
z: 0.0,
},
- scale: Vec3::splat(0.3),
+ scale: Vec3::splat(3.5),
..Default::default()
},
..Default::default()
})
- .spawn(SpriteBundle {
- material: materials.add(texture_handle.into()),
+ .spawn(SpriteSheetBundle {
+ sprite: TextureAtlasSprite::new(8),
+ texture_atlas: atlas_handle.clone(),
+ transform: Transform {
+ translation: Vec3 {
+ x: 225.0,
+ y: -200.0,
+ z: 0.0,
+ },
+ scale: Vec3::splat(3.5),
+ ..Default::default()
+ },
+ ..Default::default()
+ })
+ .spawn(SpriteSheetBundle {
+ sprite: TextureAtlasSprite::new(12),
+ texture_atlas: atlas_handle.clone(),
+ transform: Transform {
+ translation: Vec3 {
+ x: 225.0,
+ y: -200.0 + (-16.0) * 3.5,
+ z: 0.0,
+ },
+ scale: Vec3::splat(3.5),
+ ..Default::default()
+ },
..Default::default()
});
+
+ for i in 0..8 {
+ for j in 0..8 {
+ commands.spawn(SpriteSheetBundle {
+ sprite: TextureAtlasSprite::new(1),
+ texture_atlas: atlas_handle.clone(),
+ transform: Transform {
+ translation: Vec3 {
+ x: ((i as f32) * 16.0 * 3.5) - 320.0,
+ y: ((j as f32) * 16.0 * 3.5) - 170.0,
+ z: 0.0,
+ },
+ scale: Vec3::splat(3.5),
+ ..Default::default()
+ },
+ ..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());
+ app.add_startup_system(setup.system());
}
}