Tilemap chunking part 2
This commit is contained in:
+70
-5
@@ -1,5 +1,5 @@
|
||||
use crate::constants::*;
|
||||
use crate::tile::{FixtureTile, FloorTile, TileState};
|
||||
use crate::tile::{FixtureTile, FloorTile, NeedsOccluded, TileState};
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Bundle)]
|
||||
@@ -8,15 +8,16 @@ pub struct FloorTilePrefab {
|
||||
sprite: Sprite,
|
||||
tile: FloorTile,
|
||||
tile_state: TileState,
|
||||
visibility: Visibility
|
||||
visibility: Visibility,
|
||||
needs_occluded: NeedsOccluded,
|
||||
}
|
||||
|
||||
impl FloorTilePrefab {
|
||||
pub fn dirt(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
||||
pub fn grass(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
||||
FloorTilePrefab {
|
||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("dirt_floor.png"),
|
||||
image: asset_server.load("grass_floor.png"),
|
||||
..Default::default()
|
||||
},
|
||||
tile: FloorTile {
|
||||
@@ -27,6 +28,30 @@ impl FloorTilePrefab {
|
||||
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dirt(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
||||
FloorTilePrefab {
|
||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("dirt_floor.png"),
|
||||
..Default::default()
|
||||
},
|
||||
tile: FloorTile {
|
||||
id: 2,
|
||||
..Default::default()
|
||||
},
|
||||
tile_state: TileState {
|
||||
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +70,9 @@ impl FloorTilePrefab {
|
||||
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +92,9 @@ impl FloorTilePrefab {
|
||||
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +113,22 @@ impl FloorTilePrefab {
|
||||
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn(self, commands: &mut Commands) {
|
||||
commands.spawn((
|
||||
self.tile,
|
||||
self.transform,
|
||||
self.sprite,
|
||||
self.tile_state,
|
||||
self.visibility,
|
||||
self.needs_occluded,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
@@ -91,7 +136,8 @@ pub struct FixtureTilePrefab {
|
||||
transform: Transform,
|
||||
sprite: Sprite,
|
||||
tile: FixtureTile,
|
||||
visibility: Visibility
|
||||
visibility: Visibility,
|
||||
needs_occluded: NeedsOccluded,
|
||||
}
|
||||
|
||||
impl FixtureTilePrefab {
|
||||
@@ -107,6 +153,9 @@ impl FixtureTilePrefab {
|
||||
..Default::default()
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +171,9 @@ impl FixtureTilePrefab {
|
||||
..Default::default()
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +189,19 @@ impl FixtureTilePrefab {
|
||||
..Default::default()
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
needs_occluded: NeedsOccluded {
|
||||
has_been_occluded: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn(self, commands: &mut Commands) {
|
||||
commands.spawn((
|
||||
self.tile,
|
||||
self.transform,
|
||||
self.sprite,
|
||||
self.visibility,
|
||||
self.needs_occluded,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user