trying to figure out how i want hexmap to work

This commit is contained in:
dani 2023-07-01 21:12:44 +00:00
parent 799f679be6
commit 10f6dc1a05
3 changed files with 15 additions and 12 deletions

View File

@ -1,33 +1,28 @@
use crate::Vec2; use crate::Vec2;
//odd-q vertical layout https://www.redblobgames.com/grids/hexagons //odd-q vertical layout https://www.redblobgames.com/grids/hexagons
pub struct HexMap<T: Default> { pub struct HexMap {
size: Vec2<i32>, size: Vec2<i32>,
data: Vec<T>, data: Vec<i32>,
tile_size: Vec2<i32>, tile_size: Vec2<i32>,
} }
impl<T: Default + Clone> HexMap<T> { impl HexMap {
//pub static //pub static
pub fn new(size: Vec2<i32>, tile_size: Vec2<i32>) -> Self { pub fn new(size: Vec2<i32>, tile_size: Vec2<i32>) -> Self {
HexMap { HexMap {
size, size,
data: vec![T::default(); size.size()], data: vec![0; size.size()],
tile_size, tile_size,
} }
} }
//pub //pub
pub fn get(&self, coord: Vec2<i32>) -> &T { pub fn get(&self, coord: Vec2<i32>) -> i32 {
&self.data[self.coord_to_idx(coord)] self.data[self.coord_to_idx(coord)]
} }
pub fn get_mut(&mut self, coord: Vec2<i32>) -> &mut T { pub fn set(&mut self, coord: Vec2<i32>, val: i32) {
let idx = self.coord_to_idx(coord);
&mut self.data[idx]
}
pub fn set(&mut self, coord: Vec2<i32>, val: T) {
let idx = self.coord_to_idx(coord); let idx = self.coord_to_idx(coord);
self.data[idx] = val; self.data[idx] = val;
} }

View File

@ -3,6 +3,7 @@ mod image;
mod rect; mod rect;
mod vec2; mod vec2;
mod window; mod window;
mod tileset;
pub use hexmap::*; pub use hexmap::*;
pub use image::*; pub use image::*;

7
src/tileset.rs Normal file
View File

@ -0,0 +1,7 @@
use crate::{Image, Vec2};
struct Tileset {
count: i32,
size: Vec2<i32>,
images: Vec<Image>,
}