2024-10-04 01:21:52 +02:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
fs::{read_dir, read_to_string},
|
|
|
|
};
|
2024-10-03 22:59:49 +02:00
|
|
|
|
|
|
|
use marble_engine::parse;
|
|
|
|
use raylib::prelude::*;
|
|
|
|
|
|
|
|
mod marble_engine;
|
|
|
|
|
|
|
|
fn main() {
|
2024-10-04 01:21:52 +02:00
|
|
|
let (mut rl, thread) = raylib::init()
|
|
|
|
.resizable()
|
|
|
|
.title("good window title")
|
|
|
|
.build();
|
2024-10-03 22:59:49 +02:00
|
|
|
rl.set_target_fps(60);
|
|
|
|
|
2024-10-04 01:21:52 +02:00
|
|
|
let board = parse(&read_to_string("boards/counter.mbl").unwrap());
|
2024-10-03 22:59:49 +02:00
|
|
|
let mut pos_offset = Vector2::zero();
|
|
|
|
let mut machine = marble_engine::Machine::new(board, "Vec::new()".bytes().collect());
|
|
|
|
|
2024-10-04 01:21:52 +02:00
|
|
|
let mut textures: HashMap<String, Texture2D> = 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-03 22:59:49 +02:00
|
|
|
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));
|
|
|
|
|
2024-10-04 01:21:52 +02:00
|
|
|
machine.draw(&mut d, &textures, pos_offset);
|
2024-10-03 22:59:49 +02:00
|
|
|
|
|
|
|
d.draw_fps(2, 2);
|
|
|
|
}
|
|
|
|
}
|