diff --git a/assets/dirt.png b/assets/dirt.png new file mode 100644 index 0000000..76760e9 Binary files /dev/null and b/assets/dirt.png differ diff --git a/assets/sky.png b/assets/sky.png new file mode 100644 index 0000000..84f5256 Binary files /dev/null and b/assets/sky.png differ diff --git a/src/camera.rs b/src/camera.rs index e4bc697..a376ade 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -39,6 +39,7 @@ pub fn camera_movement( pub fn spawn_panning_camera(mut commands: Commands) { commands.spawn(( Camera2d::default(), + Transform::from_xyz(0.,0.,10.), PanningCamera { pan_speed: 5.0 } )); } \ No newline at end of file diff --git a/src/game.rs b/src/game.rs index bd62ecc..60e1c03 100644 --- a/src/game.rs +++ b/src/game.rs @@ -24,76 +24,88 @@ pub fn setup_level(mut commands: Commands, asset_server: Res) { fn setup_tilemap(commands: &mut Commands, asset_server: &Res) { for x in 0..25 { for y in 0..25 { - let position = Vec3::new( - x as f32 * 16. * PIXEL_RATIO, - y as f32 * 16. * PIXEL_RATIO, - -0.5, - ); + for z in 0..4 { + let position = Vec3::new( + x as f32 * 16. * PIXEL_RATIO, + y as f32 * 16. * PIXEL_RATIO, + -z as f32, + ); + let mut noitem: bool = false; - let texture = if random::() < 0.5 { - asset_server.load("grass.png") - } else { - asset_server.load("rock.png") - }; + let texture: Handle; + if random::() < 0.4 { + texture = asset_server.load("grass.png"); + } else if random::() < 0.2 { + texture = asset_server.load("dirt.png"); + } else if random::() < 0.1 { + texture = asset_server.load("rock.png"); + } else { + texture = asset_server.load("sky.png"); + noitem = true; + }; - let mut items: Vec = vec![]; + let mut items: Vec = vec![]; - if random::() < 0.1 { - items.push(ItemBundle { - transform: Transform::from_translation(Vec3::new(0., 0., 0.1)), - sprite: Sprite { - image: asset_server.load("beer.png"), - ..Default::default() - }, - item: Item::new(), - visibility: Visibility::Visible, - }); + if !noitem { + if random::() < 0.1 { + items.push(ItemBundle { + transform: Transform::from_translation(Vec3::new(0., 0., 0.1)), + sprite: Sprite { + image: asset_server.load("beer.png"), + ..Default::default() + }, + item: Item::new(), + visibility: Visibility::Visible, + }); + } + if random::() < 0.1 { + items.push(ItemBundle { + transform: Transform::from_translation(Vec3::new(0., 0., 0.1)), + sprite: Sprite { + image: asset_server.load("chalice.png"), + ..Default::default() + }, + item: Item::new(), + visibility: Visibility::Visible, + }); + } + if random::() < 0.1 { + items.push(ItemBundle { + transform: Transform::from_translation(Vec3::new(0., 0., 0.1)), + sprite: Sprite { + image: asset_server.load("fish.png"), + ..Default::default() + }, + item: Item::new(), + visibility: Visibility::Visible, + }); + } + } + + let tile_entity = commands + .spawn(( + Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)), + Sprite { + image: texture, + ..Default::default() + }, + FloorTile { + walkable: random::() < 0.7, + astar_weight: random::() % 10 + 1, + }, + Tile { position: position }, + TileState { + timer: Timer::from_seconds(1., TimerMode::Repeating), + }, + )) + .id(); + + let mut child_entities = Vec::new(); + for item in items { + child_entities.push(commands.spawn(item).id()); + } + commands.entity(tile_entity).add_children(&child_entities); } - if random::() < 0.1 { - items.push(ItemBundle { - transform: Transform::from_translation(Vec3::new(0., 0., 0.1)), - sprite: Sprite { - image: asset_server.load("chalice.png"), - ..Default::default() - }, - item: Item::new(), - visibility: Visibility::Visible, - }); - } - if random::() < 0.1 { - items.push(ItemBundle { - transform: Transform::from_translation(Vec3::new(0., 0., 0.1)), - sprite: Sprite { - image: asset_server.load("fish.png"), - ..Default::default() - }, - item: Item::new(), - visibility: Visibility::Visible, - }); - } - - - let tile_entity = commands - .spawn(( - Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)), - Sprite { - image: texture, - ..Default::default() - }, - FloorTile { - walkable: random::() < 0.7, - astar_weight: random::() % 10 + 1, - }, - Tile { position: position }, - TileState { timer: Timer::from_seconds(0.5, TimerMode::Repeating) } - )) - .id(); - - let mut child_entities = Vec::new(); - for item in items { - child_entities.push(commands.spawn(item).id()); - } - commands.entity(tile_entity).add_children(&child_entities); } } } diff --git a/src/main.rs b/src/main.rs index 9a5f113..63e28ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ fn main() { .add_systems(FixedUpdate, ( camera::camera_movement, citizen::citizen_movement, - tile::tile_update, + tile::tile_sprite_update, )) .run(); } \ No newline at end of file diff --git a/src/tile.rs b/src/tile.rs index 1fd0e99..d510f52 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -60,49 +60,23 @@ pub struct DoorTile { pub locked: bool, } -pub fn spawn_tile( - commands: &mut Commands, - position: Vec3, - floor_tile: FloorTile, - // fixture: Option, - items: Vec, -) { - let tile_entity = commands.spawn((Tile { position }, floor_tile)).id(); - - // if let Some(fixture) = fixture { - // commands.entity(tile_entity).add_children(&[ - // commands - // .spawn((fixture,)) - // .id(), - // ]); - // } - - let mut child_entities = Vec::new(); - for item in items { - child_entities.push(commands.spawn(item).id()); - } - commands.entity(tile_entity).add_children(&child_entities); -} - -pub fn tile_update( +pub fn tile_sprite_update( time: Res