initial z axis tiles pass
This commit is contained in:
+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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user