Add setup system with camera and empty map
This commit is contained in:
parent
b7b89b801b
commit
89ddbd2483
@ -16,6 +16,6 @@ use prelude::*;
|
|||||||
fn main() {
|
fn main() {
|
||||||
App::build()
|
App::build()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(PlayerPlugin)
|
.add_startup_system(setup.system())
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,36 @@
|
|||||||
use crate::prelude::*;
|
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) {
|
pub fn add_player(mut commands: Commands) {
|
||||||
commands
|
commands
|
||||||
.spawn()
|
.spawn()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user