summaryrefslogtreecommitdiffstats
path: root/src/game.rs
blob: a9135968f8903f201b94e7fb10ada202b1052333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 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()),
	};

	// allow only orthogonal maps
	assert_eq!(demo_map.orientation, tiled::Orientation::Orthogonal);

	return State {
		running: true,
		map: demo_map
	};
}

pub fn update(_state: &mut State) {

}