213 lines
6.6 KiB
Rust
213 lines
6.6 KiB
Rust
use crate::constants::*;
|
|
use crate::tile::{FixtureTile, FloorTile, NeedsOccluded, TileState};
|
|
use bevy::prelude::*;
|
|
|
|
#[derive(Bundle)]
|
|
pub struct FloorTilePrefab {
|
|
transform: Transform,
|
|
sprite: Sprite,
|
|
tile: FloorTile,
|
|
tile_state: TileState,
|
|
visibility: Visibility,
|
|
needs_occluded: NeedsOccluded,
|
|
}
|
|
|
|
impl FloorTilePrefab {
|
|
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("grass_floor.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FloorTile {
|
|
id: 1,
|
|
astar_weight: 100,
|
|
..Default::default()
|
|
},
|
|
tile_state: TileState {
|
|
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,
|
|
astar_weight: 85,
|
|
..Default::default()
|
|
},
|
|
tile_state: TileState {
|
|
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
|
},
|
|
visibility: Visibility::Hidden,
|
|
needs_occluded: NeedsOccluded {
|
|
has_been_occluded: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn rock(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("rock_floor.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FloorTile {
|
|
id: 3,
|
|
astar_weight: 50,
|
|
..Default::default()
|
|
},
|
|
tile_state: TileState {
|
|
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
|
},
|
|
visibility: Visibility::Hidden,
|
|
needs_occluded: NeedsOccluded {
|
|
has_been_occluded: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn air(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("sky.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FloorTile {
|
|
id: 0,
|
|
opaque: false,
|
|
walkable: false,
|
|
..Default::default()
|
|
},
|
|
tile_state: TileState {
|
|
timer: Timer::from_seconds(1.0, TimerMode::Repeating),
|
|
},
|
|
visibility: Visibility::Hidden,
|
|
needs_occluded: NeedsOccluded {
|
|
has_been_occluded: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn bedrock(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("bedrock_floor.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FloorTile {
|
|
id: 4,
|
|
astar_weight: 150,
|
|
..Default::default()
|
|
},
|
|
tile_state: TileState {
|
|
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)]
|
|
pub struct FixtureTilePrefab {
|
|
transform: Transform,
|
|
sprite: Sprite,
|
|
tile: FixtureTile,
|
|
visibility: Visibility,
|
|
needs_occluded: NeedsOccluded,
|
|
}
|
|
|
|
impl FixtureTilePrefab {
|
|
pub fn dirt_wall(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
|
FixtureTilePrefab {
|
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
|
sprite: Sprite {
|
|
image: asset_server.load("dirt_wall.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FixtureTile {
|
|
id: 1,
|
|
..Default::default()
|
|
},
|
|
visibility: Visibility::Hidden,
|
|
needs_occluded: NeedsOccluded {
|
|
has_been_occluded: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn rock_wall(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
|
FixtureTilePrefab {
|
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
|
sprite: Sprite {
|
|
image: asset_server.load("rock_wall.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FixtureTile {
|
|
id: 2,
|
|
..Default::default()
|
|
},
|
|
visibility: Visibility::Hidden,
|
|
needs_occluded: NeedsOccluded {
|
|
has_been_occluded: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn bedrock_wall(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
|
FixtureTilePrefab {
|
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
|
sprite: Sprite {
|
|
image: asset_server.load("bedrock_wall.png"),
|
|
..Default::default()
|
|
},
|
|
tile: FixtureTile {
|
|
id: 0,
|
|
..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,
|
|
));
|
|
}
|
|
}
|