diff options
Diffstat (limited to '')
-rw-r--r-- | src/game.rs | 27 | ||||
-rw-r--r-- | src/main.rs | 11 |
2 files changed, 32 insertions, 6 deletions
diff --git a/src/game.rs b/src/game.rs index ab04b21..335e9da 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,15 +1,36 @@ +use std::error::Error; + +use tiled::Map; + +// embedded resources +#[derive(RustEmbed)] +#[folder = "res/maps"] +pub struct MapAssets; + +// game state pub struct State { - pub running: bool + pub running: bool, + pub map: Map, } +pub fn new() -> State { + // load demo map + let demo_map_asset = match MapAssets::get("demo.tmx") { + Some(asset) => asset, + None => panic!("Failed to load demo map asset"), + }; + let demo_map = match tiled::parse(demo_map_asset.as_ref()) { + Ok(map) => map, + Err(e) => panic!("Failed to parse demo map: {}", e.description()), + }; -pub fn new() -> State { return State { running: true, + map: demo_map }; } -pub fn update(state: &mut State) { +pub fn update(_state: &mut State) { }
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e2353e7..4d32b95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate rust_embed; + mod game; mod graphics; @@ -5,9 +8,9 @@ use std::thread; use std::sync::{Arc, Mutex}; fn main() { - let state_ = Arc::new(Mutex::new(game::new())); + let state_mutex = Arc::new(Mutex::new(game::new())); - let state = state_.clone(); + let state = state_mutex.clone(); let game_thread = thread::spawn(move || { loop { // aquire state resource @@ -25,7 +28,7 @@ fn main() { }); - let state = state_.clone(); + let state = state_mutex.clone(); let graphics_thread = thread::spawn(move || { let mut window = graphics::start(); @@ -40,9 +43,11 @@ fn main() { Err(poisoned) => poisoned.into_inner(), }; + // stop game thread state.running = false; }); + // wait for both thread to die graphics_thread.join().unwrap(); game_thread.join().unwrap(); } |