-
Notifications
You must be signed in to change notification settings - Fork 0
/
ortho_tileset_static.rs
57 lines (45 loc) · 1.57 KB
/
ortho_tileset_static.rs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::path::Path;
use macroquad::color::LIGHTGRAY;
use macroquad::input::{is_key_down, is_key_pressed, KeyCode};
use macroquad::math::Rect;
use macroquad::window::{clear_background, next_frame};
use tiled::Loader;
use macroquad_tiled_redux::TileSet;
#[macroquad::main("Texture")]
async fn main() {
let path = Path::new("assets/tiled_base64_zlib.tmx");
let tileset = Loader::new()
.load_tsx_tileset(path)
.expect("Couldn't load tileset");
println!("{:?}", tileset);
let mqts = TileSet::new_async(tileset)
.await
.expect("Couldn't load Tileset");
let margin = 0.0;
let mut zoom = 3.0;
loop {
clear_background(LIGHTGRAY);
let tile_count = mqts.tileset.tilecount;
for i in 0..tile_count {
let w = mqts.tileset.tile_width as f32;
let h = mqts.tileset.tile_height as f32;
let x = (i % mqts.tileset.columns) as f32 * (w + margin);
let y = (i / mqts.tileset.columns) as f32 * (h + margin);
let dest = Rect::new(x * zoom, y * zoom, w * zoom, h * zoom);
mqts.spr(i, dest);
};
if is_key_down(KeyCode::Q) {
break;
}
if is_key_pressed(KeyCode::KpAdd) || is_key_pressed(KeyCode::KpMultiply) {
zoom += 1.0;
}
if (is_key_pressed(KeyCode::Minus) || is_key_pressed(KeyCode::KpSubtract)) && zoom >= 2.0 {
zoom -= 1.0;
}
if is_key_pressed(KeyCode::Key0) || is_key_pressed(KeyCode::Kp0) {
zoom = 1.0;
}
next_frame().await
}
}