use std::{ collections::HashMap, fs::{read_dir, read_to_string}, }; use marble_engine::parse; use raylib::prelude::*; mod marble_engine; fn main() { let (mut rl, thread) = raylib::init() .resizable() .title("good window title") .build(); rl.set_target_fps(60); let board = parse(&read_to_string("boards/counter.mbl").unwrap()); let mut pos_offset = Vector2::zero(); let mut machine = marble_engine::Machine::new(board, "Vec::new()".bytes().collect()); let mut textures: HashMap = HashMap::new(); for d in read_dir("assets/tiles").unwrap().flatten() { let name = d.file_name(); if d.path().is_file() { let name = name.to_string_lossy(); let texture = rl .load_texture(&thread, &format!("assets/tiles/{name}")) .unwrap(); textures.insert(name.to_string(), texture); } } while !rl.window_should_close() { if rl.is_key_pressed(KeyboardKey::KEY_SPACE) { machine.step(); } if rl.is_mouse_button_down(MouseButton::MOUSE_BUTTON_MIDDLE) { pos_offset += rl.get_mouse_delta() } if rl.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_RIGHT) { pos_offset = Vector2::zero(); } let mut d = rl.begin_drawing(&thread); d.clear_background(Color::new(64, 64, 64, 255)); machine.draw(&mut d, &textures, pos_offset); d.draw_fps(2, 2); } }