trying to figure out how i want hexmap to work
This commit is contained in:
parent
799f679be6
commit
10f6dc1a05
|
@ -1,33 +1,28 @@
|
|||
use crate::Vec2;
|
||||
|
||||
//odd-q vertical layout https://www.redblobgames.com/grids/hexagons
|
||||
pub struct HexMap<T: Default> {
|
||||
pub struct HexMap {
|
||||
size: Vec2<i32>,
|
||||
data: Vec<T>,
|
||||
data: Vec<i32>,
|
||||
tile_size: Vec2<i32>,
|
||||
}
|
||||
|
||||
impl<T: Default + Clone> HexMap<T> {
|
||||
impl HexMap {
|
||||
//pub static
|
||||
pub fn new(size: Vec2<i32>, tile_size: Vec2<i32>) -> Self {
|
||||
HexMap {
|
||||
size,
|
||||
data: vec![T::default(); size.size()],
|
||||
data: vec![0; size.size()],
|
||||
tile_size,
|
||||
}
|
||||
}
|
||||
|
||||
//pub
|
||||
pub fn get(&self, coord: Vec2<i32>) -> &T {
|
||||
&self.data[self.coord_to_idx(coord)]
|
||||
pub fn get(&self, coord: Vec2<i32>) -> i32 {
|
||||
self.data[self.coord_to_idx(coord)]
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, coord: Vec2<i32>) -> &mut T {
|
||||
let idx = self.coord_to_idx(coord);
|
||||
&mut self.data[idx]
|
||||
}
|
||||
|
||||
pub fn set(&mut self, coord: Vec2<i32>, val: T) {
|
||||
pub fn set(&mut self, coord: Vec2<i32>, val: i32) {
|
||||
let idx = self.coord_to_idx(coord);
|
||||
self.data[idx] = val;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ mod image;
|
|||
mod rect;
|
||||
mod vec2;
|
||||
mod window;
|
||||
mod tileset;
|
||||
|
||||
pub use hexmap::*;
|
||||
pub use image::*;
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
use crate::{Image, Vec2};
|
||||
|
||||
struct Tileset {
|
||||
count: i32,
|
||||
size: Vec2<i32>,
|
||||
images: Vec<Image>,
|
||||
}
|
Loading…
Reference in New Issue