use std::time::Duration;
use bevy::app::ScheduleRunnerPlugin;
use bevy::prelude::*;
use bevy::sprite::Anchor;
use bevy::window::{ExitCondition, WindowPlugin};
use bevy_kitty::prelude::*;
const VIRTUAL: UVec2 = UVec2::new(320, 180);
#[derive(Component)]
struct Ticker;
fn main() {
App::new()
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
primary_window: None,
exit_condition: ExitCondition::DontExit,
close_when_requested: false,
..default()
})
.disable::<bevy::winit::WinitPlugin>(),
)
.add_plugins(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(
1.0 / 10.0,
)))
.add_plugins(KittyPlugin {
config: KittyConfig {
virtual_size: VIRTUAL,
text_scale: 4.0,
..default()
},
})
.add_systems(Startup, setup)
.add_systems(Update, tick)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn((
Camera2d,
Projection::Orthographic(OrthographicProjection {
scaling_mode: bevy::camera::ScalingMode::FixedVertical {
viewport_height: VIRTUAL.y as f32,
},
..OrthographicProjection::default_2d()
}),
KittyCamera,
));
commands.spawn((
Sprite {
color: Color::srgb(0.05, 0.05, 0.09),
custom_size: Some(Vec2::new(VIRTUAL.x as f32, VIRTUAL.y as f32)),
..default()
},
Transform::from_xyz(0.0, 0.0, -1.0),
));
let line = |text: &str, y: f32, size: f32, color: Color| {
(
Text2d::new(text),
TextFont {
font_size: FontSize::Px(size),
..default()
},
TextColor(color),
Anchor::CENTER,
Transform::from_xyz(0.0, y, 1.0),
)
};
commands.spawn(line("bevy_kitty", 60.0, 24.0, Color::WHITE));
commands.spawn(line(
"Text2d, rendered as kitty glyphs",
36.0,
10.0,
Color::srgb(0.7, 0.8, 1.0),
));
commands.spawn(line(
"every letter uploaded once, placed many",
20.0,
10.0,
Color::srgb(0.6, 0.65, 0.75),
));
commands.spawn(line(
"a different colour costs new uploads",
-8.0,
10.0,
Color::srgb(1.0, 0.5, 0.4),
));
commands.spawn((
Text2d::new("tick 0"),
TextFont {
font_size: FontSize::Px(14.0),
..default()
},
TextColor(Color::srgb(1.0, 0.85, 0.3)),
Anchor::CENTER,
Transform::from_xyz(0.0, -40.0, 1.0),
Ticker,
));
commands.spawn(line(
"Ctrl-C to quit",
-66.0,
8.0,
Color::srgb(0.45, 0.45, 0.5),
));
}
fn tick(mut q: Query<&mut Text2d, With<Ticker>>, mut n: Local<u32>) {
*n += 1;
for mut text in q.iter_mut() {
text.0 = format!("tick {}", *n);
}
}