Add setup system with camera and empty map

This commit is contained in:
Daniel Lynn 2021-07-16 21:52:57 -05:00
parent b7b89b801b
commit 89ddbd2483
Signed by: daniel
GPG Key ID: 28496A140E180A9D
2 changed files with 32 additions and 1 deletions

View File

@ -16,6 +16,6 @@ use prelude::*;
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.add_startup_system(setup.system())
.run();
}

View File

@ -1,5 +1,36 @@
use crate::prelude::*;
pub fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
// Camera
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
// Map
let grass_material = materials.add(asset_server.load("grass.png").into());
let tile_size = Vec2::new(32.0, 32.0);
let sprite = Sprite::new(tile_size);
let map_size = Vec2::new(80.0, 50.0);
let half_x = (map_size.x / 2.0) as i32;
let half_y = (map_size.y / 2.0) as i32;
for y in -half_y..half_y {
for x in -half_x..half_x {
let position = Vec2::new(x as f32, y as f32);
let translation = (position * tile_size).extend(0.0);
commands.spawn_bundle(SpriteBundle {
material: grass_material.clone(),
sprite: sprite.clone(),
transform: Transform::from_translation(translation),
..Default::default()
});
}
}
}
pub fn add_player(mut commands: Commands) {
commands
.spawn()