Singular tiles resource
This commit is contained in:
+13
-14
@@ -1,6 +1,6 @@
|
||||
use crate::constants::{ITILE_SIZE, TILE_SIZE};
|
||||
use crate::tile::{self, FixtureTile, FloorTile, NeedsOccluded, TileMap};
|
||||
use crate::tiles::{FixtureTilePrefab, FloorTilePrefab};
|
||||
use crate::tiles::{FixtureTilePrefab, FloorTilePrefab, Textures};
|
||||
use bevy::prelude::*;
|
||||
use noise::{NoiseFn, Perlin};
|
||||
use std::collections::HashMap;
|
||||
@@ -30,7 +30,6 @@ fn setup_chunk_system(mut commands: Commands) {
|
||||
commands.insert_resource(ChunkMap::default());
|
||||
}
|
||||
|
||||
// System to handle tile occlusion updates
|
||||
pub fn handle_tile_occlusion_updates(
|
||||
mut commands: Commands,
|
||||
tilemap: Res<TileMap>,
|
||||
@@ -163,7 +162,7 @@ pub fn generate_surface_noise(x: i32, y: i32) -> f32 {
|
||||
|
||||
fn handle_chunk_loading(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
textures: Res<Textures>,
|
||||
mut events: EventReader<LoadChunkEvent>,
|
||||
mut chunk_map: ResMut<ChunkMap>,
|
||||
mut tilemap: ResMut<TileMap>,
|
||||
@@ -212,19 +211,19 @@ fn handle_chunk_loading(
|
||||
z as f64 * 0.05,
|
||||
]);
|
||||
if noise_value < -0.5 {
|
||||
FloorTilePrefab::air(position, &asset_server).spawn(&mut commands);
|
||||
FloorTilePrefab::air(position, &textures).spawn(&mut commands);
|
||||
tilemap
|
||||
.floor_tiles
|
||||
.insert(pos_ivec, (0, false, true, 0, [0; 8])); // Air tile
|
||||
floor_positions.push((position, "air"));
|
||||
} else if noise_value < 0.8 {
|
||||
FloorTilePrefab::rock(position, &asset_server).spawn(&mut commands);
|
||||
FloorTilePrefab::rock(position, &textures).spawn(&mut commands);
|
||||
tilemap
|
||||
.floor_tiles
|
||||
.insert(pos_ivec, (2, true, false, 50, [0; 8])); // Rock tile
|
||||
floor_positions.push((position, "rock"));
|
||||
} else {
|
||||
FloorTilePrefab::dirt(position, &asset_server).spawn(&mut commands);
|
||||
FloorTilePrefab::dirt(position, &textures).spawn(&mut commands);
|
||||
tilemap
|
||||
.floor_tiles
|
||||
.insert(pos_ivec, (1, true, true, 85, [0; 8])); // Dirt tile
|
||||
@@ -234,20 +233,20 @@ fn handle_chunk_loading(
|
||||
if (generate_surface_noise(world_x, world_y) * TILE_SIZE).round()
|
||||
<= position.z + TILE_SIZE
|
||||
{
|
||||
FloorTilePrefab::grass(position, &asset_server).spawn(&mut commands);
|
||||
FloorTilePrefab::grass(position, &textures).spawn(&mut commands);
|
||||
tilemap
|
||||
.floor_tiles
|
||||
.insert(pos_ivec, (1, true, true, 100, [0; 8])); // Dirt tile (grass)
|
||||
floor_positions.push((position, "dirt"));
|
||||
} else {
|
||||
FloorTilePrefab::dirt(position, &asset_server).spawn(&mut commands);
|
||||
FloorTilePrefab::dirt(position, &textures).spawn(&mut commands);
|
||||
tilemap
|
||||
.floor_tiles
|
||||
.insert(pos_ivec, (1, true, true, 85, [0; 8])); // Dirt tile
|
||||
floor_positions.push((position, "dirt"));
|
||||
}
|
||||
} else {
|
||||
FloorTilePrefab::air(position, &asset_server).spawn(&mut commands);
|
||||
FloorTilePrefab::air(position, &textures).spawn(&mut commands);
|
||||
tilemap
|
||||
.floor_tiles
|
||||
.insert(pos_ivec, (0, false, true, 0, [0; 8])); // Air tile
|
||||
@@ -264,17 +263,17 @@ fn handle_chunk_loading(
|
||||
|
||||
match *floor_type {
|
||||
"dirt" => {
|
||||
FixtureTilePrefab::dirt_wall(above_pos, &asset_server).spawn(&mut commands);
|
||||
FixtureTilePrefab::dirt_wall(above_pos, &textures).spawn(&mut commands);
|
||||
tilemap.fixture_tiles.insert(above_ivec, (1, true, [0; 8]));
|
||||
// Dirt wall
|
||||
}
|
||||
"rock" => {
|
||||
FixtureTilePrefab::rock_wall(above_pos, &asset_server).spawn(&mut commands);
|
||||
FixtureTilePrefab::rock_wall(above_pos, &textures).spawn(&mut commands);
|
||||
tilemap.fixture_tiles.insert(above_ivec, (2, true, [0; 8]));
|
||||
// Rock wall
|
||||
}
|
||||
"bedrock" => {
|
||||
FixtureTilePrefab::bedrock_wall(above_pos, &asset_server).spawn(&mut commands);
|
||||
FixtureTilePrefab::bedrock_wall(above_pos, &textures).spawn(&mut commands);
|
||||
tilemap.fixture_tiles.insert(above_ivec, (3, true, [0; 8]));
|
||||
// Bedrock wall
|
||||
}
|
||||
@@ -286,8 +285,8 @@ fn handle_chunk_loading(
|
||||
|
||||
fn setup_initial_chunks(mut event_writer: EventWriter<LoadChunkEvent>) {
|
||||
println!("setup_initial_chunks");
|
||||
for x in -9..=9 {
|
||||
for y in -2..=2 {
|
||||
for x in -6..=6 {
|
||||
for y in -3..=3 {
|
||||
event_writer.send(LoadChunkEvent {
|
||||
chunk_position: IVec2::new(x, y),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user