forked from octotep/bevy_crossterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransparency.rs
68 lines (61 loc) · 2.08 KB
/
transparency.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
58
59
60
61
62
63
64
65
66
67
68
use bevy::prelude::*;
use bevy_crossterm::prelude::*;
use std::default::Default;
pub fn main() {
// Window settings must happen before the crossterm Plugin
let mut settings = CrosstermWindowSettings::default();
settings.set_title("Transparency example");
App::build()
.add_resource(settings)
.add_resource(bevy::core::DefaultTaskPoolOptions::with_num_threads(1))
.add_resource(bevy::app::ScheduleRunnerSettings::run_loop(
std::time::Duration::from_millis(50),
))
.add_resource(Timer::new(std::time::Duration::from_millis(250), true))
.add_plugins(DefaultPlugins)
.add_plugin(CrosstermPlugin)
.add_startup_system(startup_system.system())
.run();
}
// 5x5 box of spaces
static BIG_BOX: &str = " \n \n \n \n ";
static SMALL_BOX: &str = r##"@@@@@
@ @ @
@ @
@ @ @
@@@@@"##;
fn startup_system(
commands: &mut Commands,
window: Res<CrosstermWindow>,
mut cursor: ResMut<Cursor>,
mut sprites: ResMut<Assets<Sprite>>,
mut stylemaps: ResMut<Assets<StyleMap>>,
) {
cursor.hidden = true;
// Create our resources
let plain = stylemaps.add(StyleMap::default());
let white_bg = stylemaps.add(StyleMap::with_bg(Color::White));
// Spawn two sprites into the world
commands
.spawn(SpriteBundle {
sprite: sprites.add(Sprite::new(BIG_BOX)),
position: Position {
x: window.x_center() as i32 - 3,
y: window.y_center() as i32 - 1,
z: 0,
},
stylemap: white_bg.clone(),
..Default::default()
})
// Moving entity that ensures the box will get redrawn each step the entity passes over it
.spawn(SpriteBundle {
sprite: sprites.add(Sprite::new(SMALL_BOX)),
position: Position {
x: window.x_center() as i32 - 1,
y: window.y_center() as i32 - 1,
z: 1,
},
stylemap: plain.clone(),
visible: Visible::transparent(),
});
}