forked from octotep/bevy_crossterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.rs
53 lines (48 loc) · 2.03 KB
/
window.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
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("Window example");
App::build()
// Add our window settings
.add_resource(settings)
// Set some options in bevy to make our program a little less resource intensive - it's just a terminal game
// no need to try and go nuts
.add_resource(bevy::core::DefaultTaskPoolOptions::with_num_threads(1))
// The Crossterm runner respects the schedulerunnersettings. No need to run as fast as humanly
// possible - 20 fps should be more than enough for a scene that never changes
.add_resource(bevy::app::ScheduleRunnerSettings::run_loop(
std::time::Duration::from_millis(50),
))
// Add the DefaultPlugins before the CrosstermPlugin. The crossterm plugin needs bevy's asset server, and if it's
// not available you'll trigger an assert
.add_plugins(DefaultPlugins)
.add_plugin(CrosstermPlugin)
.add_startup_system(startup_system.system())
.run();
}
fn startup_system(
commands: &mut Commands,
mut sprites: ResMut<Assets<Sprite>>,
mut stylemaps: ResMut<Assets<StyleMap>>,
) {
// Create our resources - two sprites and the default colors that we'll use for both
let text = sprites.add(Sprite::new("This is an example which creates a crossterm window,\nsets a title, and displays some text."));
let ctrlc = sprites.add(Sprite::new("Press Control-C to quit"));
let color = stylemaps.add(StyleMap::default());
// Spawn two sprites into the world
commands
.spawn(SpriteBundle {
sprite: text,
stylemap: color.clone(),
..Default::default()
})
.spawn(SpriteBundle {
sprite: ctrlc,
position: Position { x: 0, y: 3, z: 0 },
stylemap: color,
..Default::default()
});
}