Drawing text

This commit is contained in:
Daniel Flanagan 2024-02-03 21:15:30 -06:00
parent a70e59fdf8
commit 5db15f5bc0
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
7 changed files with 81 additions and 4 deletions

Binary file not shown.

View file

@ -24,6 +24,11 @@ the heavy-lifting for me _plus_ it's a fun excuse to write more Rust.
- https://github.com/bevyengine/bevy/blob/main/examples/audio/spatial_audio_2d.rs - https://github.com/bevyengine/bevy/blob/main/examples/audio/spatial_audio_2d.rs
- [X] Y-sort - [X] Y-sort
- Layers? - Layers?
- [ ] UI stuff
- [ ] Multiplayer
- Ambient game engine?
- I _would_ like in-browser (and mobile) playability and multiplayer
- Lightyear?
- [ ] Tile system - [ ] Tile system
- [ ] Basic map - [ ] Basic map
- In-game editing? - In-game editing?
@ -36,8 +41,5 @@ the heavy-lifting for me _plus_ it's a fun excuse to write more Rust.
- Navmesh may be super overkill and astar may be sufficient? - Navmesh may be super overkill and astar may be sufficient?
- [ ] Smart pathfinding - [ ] Smart pathfinding
- `pathfinding` crate? - `pathfinding` crate?
- [ ] Multiplayer
- [ ] Ambient game engine?
- I _would_ like in-browser (and mobile) playability and multiplayer
- [ ] ??? - [ ] ???
- [ ] Profit - [ ] Profit

View file

@ -4,6 +4,7 @@ use bevy::prelude::*;
pub struct AssetLoader { pub struct AssetLoader {
pub images: Sprites, pub images: Sprites,
pub sounds: Sounds, pub sounds: Sounds,
pub fonts: Fonts,
} }
#[derive(Resource, Debug, Default)] #[derive(Resource, Debug, Default)]
@ -17,6 +18,11 @@ pub struct Sounds {
pub meow: Handle<AudioSource>, pub meow: Handle<AudioSource>,
} }
#[derive(Resource, Debug, Default)]
pub struct Fonts {
pub iosevkalytemin: Handle<Font>,
}
pub struct AssetPlugin; pub struct AssetPlugin;
impl Plugin for AssetPlugin { impl Plugin for AssetPlugin {
@ -63,5 +69,9 @@ fn load_assets(
sounds: Sounds { sounds: Sounds {
meow: asset_server.load("sfx/meow.wav"), meow: asset_server.load("sfx/meow.wav"),
}, },
fonts: Fonts {
iosevkalytemin: asset_server.load("font/iosevka-lyteterm-regular.subset.ttf"),
},
}; };
} }

View file

@ -23,7 +23,9 @@ fn focus(
player: Query<&Transform, With<Player>>, player: Query<&Transform, With<Player>>,
mut camera: Query<&mut Transform, (With<BevyCamera>, Without<Player>)>, mut camera: Query<&mut Transform, (With<BevyCamera>, Without<Player>)>,
) { ) {
camera.single_mut().translation = player.single().translation let newpos = player.single().translation;
// println!("Cam pos: {newpos}");
camera.single_mut().translation = newpos
} }
fn y_sort(mut q: Query<&mut Transform>) { fn y_sort(mut q: Query<&mut Transform>) {

View file

@ -3,6 +3,7 @@ use bevy::prelude::*;
mod assets; mod assets;
mod camera; mod camera;
mod main_menu;
mod movement; mod movement;
mod player; mod player;
mod statue; mod statue;
@ -32,6 +33,7 @@ fn main() {
camera::Camera, camera::Camera,
assets::AssetPlugin, assets::AssetPlugin,
player::Player, player::Player,
main_menu::MainMenu,
movement::Movement, movement::Movement,
)) ))
.insert_resource(ClearColor(Color::rgb(0.3, 0., 0.5))) .insert_resource(ClearColor(Color::rgb(0.3, 0., 0.5)))

61
src/main_menu.rs Normal file
View file

@ -0,0 +1,61 @@
use bevy::prelude::*;
use crate::assets::AssetLoader;
#[derive(Component, Debug)]
pub struct MainMenu;
impl Plugin for MainMenu {
fn build(&self, app: &mut App) {
app.add_systems(PostStartup, setup_main_menu);
}
}
fn setup_main_menu(mut commands: Commands, assets: Res<AssetLoader>) {
commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::SpaceBetween,
..default()
},
..default()
})
.with_children(|parent| {
// text
parent.spawn((
TextBundle::from_section(
"Text Example",
TextStyle {
font: assets.fonts.iosevkalytemin.clone(),
font_size: 30.0,
..default()
},
)
.with_style(Style {
margin: UiRect::all(Val::Px(12.)),
..default()
}),
// Because this is a distinct label widget and
// not button/list item text, this is necessary
// for accessibility to treat the text accordingly.
Label,
));
parent.spawn(NodeBundle {
style: Style {
width: Val::Px(200.0),
height: Val::Px(200.0),
position_type: PositionType::Absolute,
left: Val::Px(210.),
bottom: Val::Px(10.),
border: UiRect::all(Val::Px(20.)),
..default()
},
border_color: Color::GREEN.into(),
background_color: Color::rgb(0.4, 0.4, 1.).into(),
..default()
});
});
}