56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
use glam::IVec2;
|
|
use rand::Rng;
|
|
use skunk2d::*;
|
|
|
|
const WIDTH: i32 = 1920 / 3;
|
|
const HEIGHT: i32 = 1080 / 3;
|
|
|
|
struct World {
|
|
pos: IVec2,
|
|
map: HexMap,
|
|
}
|
|
|
|
fn main() {
|
|
rand::thread_rng().gen::<Direction>();
|
|
run::<Image8, World>(WIDTH, HEIGHT, 10000);
|
|
}
|
|
|
|
impl Game<Image8> for World {
|
|
fn new(window_state: &mut WindowState) -> Self {
|
|
window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
|
|
window_state.scramble_palette();
|
|
Self {
|
|
pos: IVec2::ZERO,
|
|
map: HexMap::new(
|
|
IVec2 { x: 27, y: 13 },
|
|
Tileset::load_data(include_bytes!("assets/hex2.gif"), IVec2 { x: 2, y: 1 }),
|
|
IVec2 { x: 23, y: 13 },
|
|
),
|
|
}
|
|
}
|
|
|
|
fn update(&mut self, window_state: &mut WindowState) {
|
|
self.pos = window_state.mouse_pos();
|
|
let coord = self.map.pixel_to_coord(self.pos);
|
|
window_state.log(format!("{}x{}", coord.x, coord.y).as_str());
|
|
}
|
|
|
|
fn on_event(&mut self, window_state: &mut WindowState, event: Event) {
|
|
match event {
|
|
Event::MouseClick(MouseButton::Left, _) => {
|
|
window_state.scramble_palette();
|
|
}
|
|
Event::MouseClick(MouseButton::Right, _) => {
|
|
self.map
|
|
.set(self.map.pixel_to_coord(window_state.mouse_pos()), 1);
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
fn draw(&self, target: &mut Image8) {
|
|
target.clear();
|
|
target.draw_hexmap(IVec2 { x: 0, y: 0 }, &self.map);
|
|
}
|
|
}
|