initial z axis tiles pass
This commit is contained in:
@@ -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 }
|
||||
));
|
||||
}
|
||||
+78
-66
@@ -24,76 +24,88 @@ pub fn setup_level(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
||||
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::<f32>() < 0.5 {
|
||||
asset_server.load("grass.png")
|
||||
} else {
|
||||
asset_server.load("rock.png")
|
||||
};
|
||||
let texture: Handle<Image>;
|
||||
if random::<f32>() < 0.4 {
|
||||
texture = asset_server.load("grass.png");
|
||||
} else if random::<f32>() < 0.2 {
|
||||
texture = asset_server.load("dirt.png");
|
||||
} else if random::<f32>() < 0.1 {
|
||||
texture = asset_server.load("rock.png");
|
||||
} else {
|
||||
texture = asset_server.load("sky.png");
|
||||
noitem = true;
|
||||
};
|
||||
|
||||
let mut items: Vec<ItemBundle> = vec![];
|
||||
let mut items: Vec<ItemBundle> = vec![];
|
||||
|
||||
if random::<f32>() < 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::<f32>() < 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::<f32>() < 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::<f32>() < 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::<f32>() < 0.7,
|
||||
astar_weight: random::<u8>() % 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::<f32>() < 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::<f32>() < 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::<f32>() < 0.7,
|
||||
astar_weight: random::<u8>() % 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ fn main() {
|
||||
.add_systems(FixedUpdate, (
|
||||
camera::camera_movement,
|
||||
citizen::citizen_movement,
|
||||
tile::tile_update,
|
||||
tile::tile_sprite_update,
|
||||
))
|
||||
.run();
|
||||
}
|
||||
+2
-29
@@ -60,49 +60,23 @@ pub struct DoorTile {
|
||||
pub locked: bool,
|
||||
}
|
||||
|
||||
pub fn spawn_tile(
|
||||
commands: &mut Commands,
|
||||
position: Vec3,
|
||||
floor_tile: FloorTile,
|
||||
// fixture: Option<Fixture>,
|
||||
items: Vec<Item>,
|
||||
) {
|
||||
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<Time>,
|
||||
mut query_tile: Query<(Entity, &Children, &mut TileState), With<Tile>>,
|
||||
mut query_item: Query<(&mut Visibility, &Item)>,
|
||||
) {
|
||||
for (tile_entity, children, mut state) in query_tile.iter_mut() {
|
||||
for (_, children, mut state) in query_tile.iter_mut() {
|
||||
state.timer.tick(time.delta());
|
||||
if !state.timer.finished() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut visible_index: Option<usize> = None;
|
||||
let mut visible_child: Option<Entity> = None;
|
||||
|
||||
for (i, &child) in children.iter().enumerate() {
|
||||
if let Ok((mut visibility, _)) = query_item.get_mut(child) {
|
||||
if matches!(*visibility, Visibility::Visible) {
|
||||
visible_index = Some(i);
|
||||
visible_child = Some(child);
|
||||
*visibility = Visibility::Hidden;
|
||||
break;
|
||||
}
|
||||
@@ -118,7 +92,6 @@ pub fn tile_update(
|
||||
if let Some(&next_child) = children.get(next_index) {
|
||||
if let Ok((mut visibility, _)) = query_item.get_mut(next_child) {
|
||||
*visibility = Visibility::Visible;
|
||||
// println!("{}",next_index.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub enum Tiles{
|
||||
air,
|
||||
grass,
|
||||
dirt,
|
||||
rock,
|
||||
}
|
||||
// BUNDLES!!
|
||||
Reference in New Issue
Block a user