diff --git a/src/hexmap.rs b/src/hexmap.rs index 2cd23ad..f221522 100644 --- a/src/hexmap.rs +++ b/src/hexmap.rs @@ -53,6 +53,21 @@ impl HexMap { Vec2 { x, y } } + pub fn coord_to_pixel(&self, coord: Vec2) -> Vec2 { + Vec2 { + x: coord.x * self.pix_tile_off.x, + y: coord.y * self.tileset.tile_size().y + (coord.x % 2) * self.pix_tile_off.y, + } + } + + pub fn coord_to_pixel_center(&self, coord: Vec2) -> Vec2 { + let tilesize = self.tileset.tile_size(); + self.coord_to_pixel(Vec2 { + x: coord.x + tilesize.x / 2, + y: coord.y + tilesize.y / 2, + }) + } + pub fn set(&mut self, coord: Vec2, val: i32) { let idx = self.coord_to_idx(coord); self.data[idx] = val; @@ -69,10 +84,8 @@ impl HexMap { coord: Vec2, offset: Vec2, ) { - let x = coord.x * self.pix_tile_off.x; - let y = coord.y * self.tileset.tile_size().y + (coord.x % 2) * self.pix_tile_off.y; target.draw_image( - Vec2 { x, y } + offset, + self.coord_to_pixel(coord) + offset, self.tileset.get(self.data[self.coord_to_idx(coord)]), ) }