Static World Gen and Display for the Overworld #5
2 changed files with 86 additions and 5 deletions
|
@ -1,9 +1,90 @@
|
||||||
|
use comfy::{IVec2, UVec2};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
enum MovementCost {
|
||||||
|
/// No movement possible - cost infinitely high.
|
||||||
|
Infinite,
|
||||||
|
/// There is a path for this movement - movement is cheap.
|
||||||
|
Path,
|
||||||
|
/// There is no path and no obstacle.
|
||||||
|
Default,
|
||||||
|
/// There is an obstacle (i.e. fence) - movement is expensive.
|
||||||
|
Obstacle
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Overworld;
|
struct Tile;
|
||||||
|
|
||||||
impl Default for Overworld {
|
impl Tile {
|
||||||
fn default() -> Self {
|
pub fn can_stand_inside(&self) -> bool {
|
||||||
Self
|
unimplemented!()
|
||||||
|
}
|
||||||
|
pub fn movement_cost_left(&self) -> MovementCost {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
pub fn movement_cost_right(&self) -> MovementCost {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
pub fn movement_cost_up(&self) -> MovementCost {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
pub fn movement_cost_down(&self) -> MovementCost {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
pub fn can_enter_house(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The size of a chunk (both width and height). This value squared gives the amount of
|
||||||
|
/// tiles in the chunk.
|
||||||
|
const CHUNK_SIZE: u32 = 100;
|
||||||
|
|
||||||
|
/// Chunks
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Chunk {
|
||||||
|
/// All tiles within this chunk.
|
||||||
|
tiles: [Tile; (CHUNK_SIZE * CHUNK_SIZE) as usize],
|
||||||
|
/// All paths that leave this chunk on the left hand side.
|
||||||
|
paths_left: Vec<u32>,
|
||||||
|
/// All paths that leave this chunk on the right hand side.
|
||||||
|
paths_right: Vec<u32>,
|
||||||
|
/// All paths that leave this chunk on the bottom side.
|
||||||
|
paths_bottom: Vec<u32>,
|
||||||
|
/// All paths that leave this chunk on the top side.
|
||||||
|
paths_top: Vec<u32>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Chunk {
|
||||||
|
fn get_tile(&self, local_chunk_coords: UVec2) -> Option<&Tile> {
|
||||||
|
self.tiles
|
||||||
|
.get((local_chunk_coords.y * CHUNK_SIZE + local_chunk_coords.x) as usize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Overworld {
|
||||||
|
chunks: HashMap<IVec2, Chunk>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Overworld {
|
||||||
|
/// Return a [`Tile`] at the given world coordinates, or `None` if that tile has not
|
||||||
|
/// been generated yet.
|
||||||
|
fn get_tile(&self, world_coords: IVec2) -> Option<&Tile> {
|
||||||
|
let tile_coords = IVec2 {
|
||||||
|
x: world_coords.x.div_euclid(CHUNK_SIZE as _),
|
||||||
|
y: world_coords.y.div_euclid(CHUNK_SIZE as _)
|
||||||
|
};
|
||||||
|
let local_coords = UVec2 {
|
||||||
|
x: world_coords.x.rem_euclid(CHUNK_SIZE as _) as _,
|
||||||
|
y: world_coords.y.rem_euclid(CHUNK_SIZE as _) as _
|
||||||
|
};
|
||||||
|
|
||||||
|
let chunk = self.chunks.get(&tile_coords)?;
|
||||||
|
chunk.get_tile(local_coords)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_or_generate_tile(&self, world_coords: IVec2) -> &Tile {
|
||||||
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ const GAME_NAME: &str = "Powercreep";
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct State {
|
struct State {
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
overworld: Overworld,
|
overworld: Overworld
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameLoop for State {
|
impl GameLoop for State {
|
||||||
|
|
Loading…
Reference in a new issue