Skip to content
Snippets Groups Projects
Verified Commit 639a822d authored by Louis's avatar Louis :fire:
Browse files

Outline floors with wall tiles, base offsets on enum

parent 0d149657
No related branches found
No related tags found
No related merge requests found
Pipeline #175 passed with stages
in 3 minutes and 5 seconds
...@@ -5,6 +5,7 @@ use iyes_loopless::state::NextState; ...@@ -5,6 +5,7 @@ use iyes_loopless::state::NextState;
use crate::assets::AssetHandles; use crate::assets::AssetHandles;
use crate::system::flow::AppState; use crate::system::flow::AppState;
use crate::world::generators::blobular::Blobular;
use crate::world::generators::drunkard_corridor::DrunkardGenerator; use crate::world::generators::drunkard_corridor::DrunkardGenerator;
use crate::world::level_map::LevelMapBundle; use crate::world::level_map::LevelMapBundle;
......
extern crate core;
pub mod assets; pub mod assets;
pub mod control; pub mod control;
pub mod debug; pub mod debug;
......
use bevy::math::uvec2; use bevy::math::uvec2;
use fastrand::Rng; use fastrand::Rng;
use crate::world::generators::utils::{draw_box, GenerationDirection}; use crate::world::generators::utils::{draw_box, outline_floors, GenerationDirection};
use crate::world::generators::{MapGenerator, TMP_FLOOR_GROUP}; use crate::world::generators::{MapGenerator, TMP_FLOOR_GROUP};
use crate::world::level_map::{Indexer, LevelMap, MapLayer, MapTile}; use crate::world::level_map::{Indexer, LevelMap, MapLayer, MapLayerType, MapTile};
pub struct Blobular; pub struct Blobular;
impl MapGenerator for Blobular { impl MapGenerator for Blobular {
...@@ -111,6 +111,8 @@ impl MapGenerator for Blobular { ...@@ -111,6 +111,8 @@ impl MapGenerator for Blobular {
} }
} }
outline_floors(&floor_layer, &mut wall_layer, indexer);
LevelMap { LevelMap {
spawn: uvec2(initial_x as u32, initial_y as u32), spawn: uvec2(initial_x as u32, initial_y as u32),
width, width,
...@@ -126,6 +128,7 @@ impl MapGenerator for Blobular { ...@@ -126,6 +128,7 @@ impl MapGenerator for Blobular {
rest => Some(MapTile::new_floor(rest)), rest => Some(MapTile::new_floor(rest)),
}) })
.collect(), .collect(),
MapLayerType::Floor,
), ),
MapLayer::from_sized_list( MapLayer::from_sized_list(
width, width,
...@@ -137,6 +140,7 @@ impl MapGenerator for Blobular { ...@@ -137,6 +140,7 @@ impl MapGenerator for Blobular {
rest => Some(MapTile::new_wall(rest)), rest => Some(MapTile::new_wall(rest)),
}) })
.collect(), .collect(),
MapLayerType::Wall,
), ),
MapLayer::from_sized_list( MapLayer::from_sized_list(
width, width,
...@@ -148,6 +152,7 @@ impl MapGenerator for Blobular { ...@@ -148,6 +152,7 @@ impl MapGenerator for Blobular {
rest => Some(MapTile::new_obstacle(rest)), rest => Some(MapTile::new_obstacle(rest)),
}) })
.collect(), .collect(),
MapLayerType::None,
), ),
], ],
} }
......
use bevy::math::uvec2; use bevy::math::uvec2;
use fastrand::Rng; use fastrand::Rng;
use crate::world::generators::utils::outline_floors;
use crate::world::generators::{MapGenerator, TMP_FLOOR_GROUP}; use crate::world::generators::{MapGenerator, TMP_FLOOR_GROUP};
use crate::world::level_map::{Indexer, LevelMap, MapLayer, MapTile}; use crate::world::level_map::{Indexer, LevelMap, MapLayer, MapLayerType, MapTile};
pub struct DrunkardGenerator; pub struct DrunkardGenerator;
impl MapGenerator for DrunkardGenerator { impl MapGenerator for DrunkardGenerator {
...@@ -47,24 +48,45 @@ impl MapGenerator for DrunkardGenerator { ...@@ -47,24 +48,45 @@ impl MapGenerator for DrunkardGenerator {
} }
} }
let mut walls = vec![0; floor.len()];
outline_floors(&floor, &mut walls, &indexer);
LevelMap::new( LevelMap::new(
map_width, map_width,
map_height, map_height,
start, start,
vec![MapLayer::from_sized_list( vec![
map_width, MapLayer::from_sized_list(
map_height, map_width,
floor map_height,
.into_iter() floor
.map(|tile| { .into_iter()
if tile == 0 { .map(|tile| {
None if tile == 0 {
} else { None
Some(MapTile::new_floor(tile)) } else {
} Some(MapTile::new_floor(tile))
}) }
.collect(), })
)], .collect(),
MapLayerType::Floor,
),
MapLayer::from_sized_list(
map_width,
map_height,
walls
.into_iter()
.map(|tile| {
if tile == 0 {
None
} else {
Some(MapTile::new_floor(tile))
}
})
.collect(),
MapLayerType::Wall,
),
],
) )
} }
} }
use crate::world::generators::TMP_WALL_GROUP;
use crate::world::level_map::Indexer; use crate::world::level_map::Indexer;
#[derive(Copy, Clone, Debug, Default)] #[derive(Copy, Clone, Debug, Default)]
...@@ -61,3 +62,32 @@ pub fn validate_box( ...@@ -61,3 +62,32 @@ pub fn validate_box(
true true
} }
pub fn outline_floors(floors: &Vec<usize>, walls: &mut Vec<usize>, indexer: &Indexer) {
if floors.len() != walls.len() {
panic!("Trying to work with irregular lists");
}
let max_index = floors.len() - 1;
for (idx, value) in floors.iter().enumerate() {
if value == &0 {
let (x, y) = indexer.reverse(idx);
if floors[max_index.min(indexer.index(x.saturating_sub(1), y))] != 0
|| floors[max_index.min(indexer.index(x.saturating_add(1), y))] != 0
|| floors[max_index.min(indexer.index(x, y.saturating_sub(1)))] != 0
|| floors[max_index.min(indexer.index(x, y.saturating_add(1)))] != 0
|| floors[max_index.min(indexer.index(x.saturating_sub(1), y.saturating_sub(1)))]
!= 0 || floors
[max_index.min(indexer.index(x.saturating_add(1), y.saturating_add(1)))]
!= 0 || floors
[max_index.min(indexer.index(x.saturating_sub(1), y.saturating_add(1)))]
!= 0 || floors
[max_index.min(indexer.index(x.saturating_add(1), y.saturating_sub(1)))]
!= 0
{
walls[idx] = TMP_WALL_GROUP;
}
}
}
}
...@@ -26,8 +26,10 @@ pub fn spawn_new_world( ...@@ -26,8 +26,10 @@ pub fn spawn_new_world(
.spawn_bundle(SpriteSheetBundle { .spawn_bundle(SpriteSheetBundle {
texture_atlas: assets.atlas("environs"), texture_atlas: assets.atlas("environs"),
sprite: TextureAtlasSprite::new( sprite: TextureAtlasSprite::new(
data.tile_group layer.layer_type.transform_adjacency(
+ get_floor_sprite_offset(layer.get_tile_adjacency(x, y)), data.tile_group,
layer.get_tile_adjacency(x, y),
),
), ),
transform: Transform::from_xyz( transform: Transform::from_xyz(
x as f32 * WORLD_TILE_SIZE, x as f32 * WORLD_TILE_SIZE,
......
...@@ -5,7 +5,9 @@ use bevy::math::UVec2; ...@@ -5,7 +5,9 @@ use bevy::math::UVec2;
use bevy::prelude::*; use bevy::prelude::*;
use fastrand::Rng; use fastrand::Rng;
use crate::world::adjacency::{BOTTOM, LEFT, NONE, RIGHT, TOP}; use crate::world::adjacency::{
get_floor_sprite_offset, get_wall_sprite_offset, BOTTOM, LEFT, NONE, RIGHT, TOP,
};
use crate::world::generators::MapGenerator; use crate::world::generators::MapGenerator;
pub const WORLD_TILE_SIZE: f32 = 16.0; pub const WORLD_TILE_SIZE: f32 = 16.0;
...@@ -82,6 +84,23 @@ impl MapTile { ...@@ -82,6 +84,23 @@ impl MapTile {
} }
} }
#[derive(Clone, Eq, PartialEq)]
pub enum MapLayerType {
Wall,
Floor,
None,
}
impl MapLayerType {
pub fn transform_adjacency(&self, value: usize, adjacency: u8) -> usize {
match self {
MapLayerType::Wall => value + get_wall_sprite_offset(adjacency),
MapLayerType::Floor => value + get_floor_sprite_offset(adjacency),
MapLayerType::None => value,
}
}
}
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq)]
pub struct MapLayer { pub struct MapLayer {
pub width: usize, pub width: usize,
...@@ -89,16 +108,23 @@ pub struct MapLayer { ...@@ -89,16 +108,23 @@ pub struct MapLayer {
pub offset_horizontal: usize, pub offset_horizontal: usize,
pub offset_vertical: usize, pub offset_vertical: usize,
pub tiles: Vec<Option<MapTile>>, pub tiles: Vec<Option<MapTile>>,
pub layer_type: MapLayerType,
} }
impl MapLayer { impl MapLayer {
pub fn from_sized_list(width: usize, height: usize, tiles: Vec<Option<MapTile>>) -> Self { pub fn from_sized_list(
width: usize,
height: usize,
tiles: Vec<Option<MapTile>>,
layer_type: MapLayerType,
) -> Self {
MapLayer { MapLayer {
width, width,
height, height,
offset_horizontal: 0, offset_horizontal: 0,
offset_vertical: 0, offset_vertical: 0,
tiles, tiles,
layer_type,
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment