mirror of
https://git.kittycat.homes/zoe/codename-routes.git
synced 2024-08-15 03:18:26 +00:00
random world generation lmao (it is just entirely random)
This commit is contained in:
parent
1de09f7014
commit
f2d449a827
7 changed files with 46 additions and 23 deletions
|
@ -13,9 +13,7 @@ gdnative = {version = "0.10", features = ["async"]}
|
|||
strum = { version = "0.24", features = ["derive"] }
|
||||
strum_macros = "0.24"
|
||||
derive_builder = "0.11.2"
|
||||
# tokio = {version = "1.18.0", features = ["sync"]}
|
||||
# lazy_static = "1.4.0"
|
||||
# pathfinding = "3.0.12"
|
||||
rand = "0.8.5"
|
||||
toml = "0.5.9"
|
||||
|
||||
[profile.dev.package."*"]
|
||||
|
|
|
@ -41,7 +41,11 @@ impl StateServer {
|
|||
|
||||
#[export]
|
||||
fn get_world_size(&self, _ownser: &Node) -> Vector3 {
|
||||
Vector3::new(self.world.xsize as f32, self.world.ysize as f32, self.world.zsize as f32)
|
||||
Vector3::new(
|
||||
self.world.xsize as f32,
|
||||
self.world.ysize as f32,
|
||||
self.world.zsize as f32,
|
||||
)
|
||||
}
|
||||
|
||||
#[export]
|
||||
|
@ -50,7 +54,7 @@ impl StateServer {
|
|||
}
|
||||
|
||||
#[export]
|
||||
fn is_tile_hidden(&self, _owner: &Node, x: usize, y: usize, z: usize) -> bool{
|
||||
fn is_tile_hidden(&self, _owner: &Node, x: usize, y: usize, z: usize) -> bool {
|
||||
self.world.is_tile_hidden(x, y, z)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use gdnative::prelude::*;
|
||||
use rand::prelude::*;
|
||||
use strum::{EnumCount, IntoEnumIterator};
|
||||
|
||||
mod tiles;
|
||||
|
||||
|
@ -10,25 +12,34 @@ pub struct World {
|
|||
}
|
||||
|
||||
impl World {
|
||||
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> u16{
|
||||
//TODO: error handling, or maybe just do that in godot
|
||||
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> u16 {
|
||||
self.tiles[x][y][z] as u16
|
||||
}
|
||||
pub fn is_tile_hidden(&self, x: usize, y: usize, z: usize) -> bool{
|
||||
if x == self.xsize - 1 || y == self.ysize -1 || z == self.zsize - 1{
|
||||
pub fn is_tile_hidden(&self, x: usize, y: usize, z: usize) -> bool {
|
||||
if x == self.xsize - 1 || y == self.ysize - 1 || z == self.zsize - 1 {
|
||||
return false;
|
||||
}
|
||||
if !tiles::Tile::new(self.tiles[x + 1][y][z]).hide_top_left
|
||||
|| !tiles::Tile::new(self.tiles[x][y + 1][z]).hide_top_right
|
||||
|| !tiles::Tile::new(self.tiles[x][y][z + 1]).hide_below
|
||||
{
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn generate(&mut self) -> Vector3Array{
|
||||
pub fn generate(&mut self) -> Vector3Array {
|
||||
let mut rng = thread_rng();
|
||||
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
|
||||
let mut ret: Vector3Array = Vector3Array::new();
|
||||
for x in 0..self.xsize {
|
||||
for y in 0..self.ysize {
|
||||
for z in 0..self.zsize {
|
||||
ret.push(Vector3::new(x as f32, y as f32, z as f32));
|
||||
self.tiles[x][y][z] = tiles::Tiletypes::Grass;
|
||||
self.tiles[x][y][z] = tiles::Tiletypes::from_repr(
|
||||
rng.gen_range(0..tiles::Tiletypes::COUNT) as u8,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use derive_builder::Builder;
|
||||
use strum::{AsRefStr, EnumDiscriminants, EnumIter, FromRepr};
|
||||
use strum::{AsRefStr, EnumCount, EnumDiscriminants, EnumIter, FromRepr};
|
||||
|
||||
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone, Copy)]
|
||||
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone, Copy, PartialEq, EnumCount)]
|
||||
#[repr(u8)]
|
||||
pub enum Tiletypes {
|
||||
Air,
|
||||
|
@ -24,16 +24,30 @@ pub struct Tile {
|
|||
#[builder(default = "vec![]")]
|
||||
can_be_next_to: Vec<Tiletypes>,
|
||||
#[builder(default = "true")]
|
||||
hide_top_left: bool,
|
||||
pub hide_top_left: bool,
|
||||
#[builder(default = "true")]
|
||||
hide_top_right: bool,
|
||||
pub hide_top_right: bool,
|
||||
#[builder(default = "true")]
|
||||
hide_below: bool,
|
||||
pub hide_below: bool,
|
||||
}
|
||||
|
||||
impl Tile {
|
||||
pub fn new(kind: Tiletypes) -> Tile {
|
||||
TileBuilder::default().kind(kind).is_support(false).build().unwrap()
|
||||
let tile: Tile;
|
||||
match kind {
|
||||
Tiletypes::Air => {
|
||||
tile = TileBuilder::default()
|
||||
.kind(kind)
|
||||
.is_support(false)
|
||||
.hide_below(false)
|
||||
.hide_top_right(false)
|
||||
.hide_top_left(false)
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
_ => tile = TileBuilder::default().kind(kind).build().unwrap(),
|
||||
};
|
||||
tile
|
||||
}
|
||||
pub fn kind_to_string(&self) -> String {
|
||||
self.kind.as_ref().to_string()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue