2023-07-10 16:32:33 +02:00
|
|
|
use glam::IVec2;
|
2023-07-06 16:13:55 +02:00
|
|
|
use rand::Rng;
|
2023-07-01 12:44:21 +02:00
|
|
|
use skunk2d::*;
|
2023-07-02 10:54:24 +02:00
|
|
|
use std::rc::Rc;
|
2023-07-01 12:44:21 +02:00
|
|
|
|
2023-07-01 22:33:39 +02:00
|
|
|
const WIDTH: i32 = 1920 / 3;
|
|
|
|
const HEIGHT: i32 = 1080 / 3;
|
2023-07-01 12:44:21 +02:00
|
|
|
|
|
|
|
struct World {
|
2023-07-02 10:54:24 +02:00
|
|
|
img: Rc<Image>,
|
|
|
|
font: Rc<Tileset>,
|
2023-07-10 16:32:33 +02:00
|
|
|
pos: IVec2,
|
2023-07-02 22:16:18 +02:00
|
|
|
map: HexMap,
|
2023-07-01 12:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2023-07-06 16:13:55 +02:00
|
|
|
rand::thread_rng().gen::<Direction>();
|
2023-07-10 01:45:12 +02:00
|
|
|
run::<World>(WIDTH, HEIGHT, 10000);
|
2023-07-01 12:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Game for World {
|
|
|
|
fn new(window_state: &mut WindowState) -> Self {
|
2023-07-01 20:25:09 +02:00
|
|
|
window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
|
2023-07-01 20:42:02 +02:00
|
|
|
window_state.scramble_palette();
|
2023-07-01 12:44:21 +02:00
|
|
|
Self {
|
2023-07-01 20:42:02 +02:00
|
|
|
img: Image::load_data(include_bytes!("assets/test.gif")),
|
2023-07-10 16:32:33 +02:00
|
|
|
font: Tileset::load_data(
|
|
|
|
include_bytes!("assets/ega-8x14.gif"),
|
|
|
|
IVec2 { x: 16, y: 16 },
|
|
|
|
),
|
|
|
|
pos: IVec2::ZERO,
|
2023-07-02 22:16:18 +02:00
|
|
|
map: HexMap::new(
|
2023-07-10 16:32:33 +02:00
|
|
|
IVec2 { x: 27, y: 13 },
|
|
|
|
Tileset::load_data(include_bytes!("assets/hex2.gif"), IVec2 { x: 2, y: 1 }),
|
|
|
|
IVec2 { x: 23, y: 13 },
|
2023-07-02 22:16:18 +02:00
|
|
|
),
|
2023-07-01 12:44:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update(&mut self, window_state: &mut WindowState) {
|
|
|
|
self.pos = window_state.mouse_pos();
|
2023-07-03 16:41:34 +02:00
|
|
|
let coord = self.map.pixel_to_coord(self.pos);
|
|
|
|
window_state.log(format!("{}x{}", coord.x, coord.y).as_str());
|
2023-07-01 12:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn on_event(&mut self, window_state: &mut WindowState, event: Event) {
|
|
|
|
match event {
|
|
|
|
Event::MouseClick(MouseButton::Left, _) => {
|
|
|
|
window_state.scramble_palette();
|
|
|
|
}
|
2023-07-03 16:41:34 +02:00
|
|
|
Event::MouseClick(MouseButton::Right, _) => {
|
|
|
|
self.map
|
|
|
|
.set(self.map.pixel_to_coord(window_state.mouse_pos()), 1);
|
|
|
|
}
|
2023-07-01 12:44:21 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw(&self, target: &mut Image) {
|
|
|
|
target.clear();
|
2023-07-10 16:32:33 +02:00
|
|
|
target.draw_hexmap(IVec2 { x: 0, y: 0 }, &self.map);
|
2023-07-02 22:16:18 +02:00
|
|
|
/*target.draw_image(Vec2 { x: 200, y: 100 }, &self.img);
|
2023-07-02 09:40:29 +02:00
|
|
|
target.draw_image(self.pos, self.font.get(68));
|
2023-07-01 12:44:21 +02:00
|
|
|
|
2023-07-01 16:36:51 +02:00
|
|
|
target.draw_line(
|
|
|
|
Vec2 {
|
|
|
|
x: WIDTH / 2,
|
|
|
|
y: HEIGHT / 2,
|
|
|
|
},
|
|
|
|
self.pos,
|
|
|
|
10,
|
|
|
|
);
|
2023-07-02 22:16:18 +02:00
|
|
|
|
|
|
|
*/
|
2023-07-01 12:44:21 +02:00
|
|
|
}
|
2023-07-01 16:36:51 +02:00
|
|
|
}
|