use rand::Rng; use skunk2d::*; use std::rc::Rc; const WIDTH: i32 = 1920 / 3; const HEIGHT: i32 = 1080 / 3; struct World { img: Rc, font: Rc, pos: Vec2, map: HexMap, } fn main() { rand::thread_rng().gen::(); run::(WIDTH, HEIGHT); } impl Game for World { fn new(window_state: &mut WindowState) -> Self { window_state.set_palette(0, 0xc0, 0xf0, 0xd0); window_state.scramble_palette(); Self { img: Image::load_data(include_bytes!("assets/test.gif")), font: Tileset::load_data(include_bytes!("assets/ega-8x14.gif"), Vec2 { x: 16, y: 16 }), pos: Vec2::zero(), map: HexMap::new( Vec2 { x: 27, y: 13 }, Tileset::load_data(include_bytes!("assets/hex2.gif"), Vec2 { x: 2, y: 1 }), Vec2 { 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 Image) { target.clear(); target.draw_hexmap(Vec2 { x: 0, y: 0 }, &self.map); /*target.draw_image(Vec2 { x: 200, y: 100 }, &self.img); target.draw_image(self.pos, self.font.get(68)); target.draw_line( Vec2 { x: WIDTH / 2, y: HEIGHT / 2, }, self.pos, 10, ); */ } }