feat: better (kinda) fonts

This commit is contained in:
YK 2024-07-14 03:33:16 +03:00
parent 3436bcf98d
commit 391ef7fd8b
5 changed files with 13 additions and 13 deletions

BIN
assets/proxima.ttf Normal file

Binary file not shown.

BIN
assets/proxima_thin.ttf Normal file

Binary file not shown.

View File

@ -24,7 +24,8 @@ impl Plugin for SqPlugin {
}
fn spawn_square_at (commands: &mut Commands, level: u32, position: usize) {
fn spawn_square_at (commands: &mut Commands, level: u32, position: usize, asset_server: AssetServer) {
let font = asset_server.load("proxima_thin.ttf");
let Some(&(x, y)) = sq_origins.get(position) else {
return;
};
@ -32,18 +33,16 @@ fn spawn_square_at (commands: &mut Commands, level: u32, position: usize) {
let text = 2i32.pow(level);
let label = Text2dBundle {
text: Text::from_section(text.to_string(), TextStyle {
font_size: 48.,
font,
font_size: 44.,
color: Color::WHITE,
..Default::default()
}),
transform: Transform {
translation: Vec3::new(x, y, 0.0),
..Default::default()
},
..Default::default()
}
;
};
commands.spawn(SpriteBundle {
sprite: Sprite {
@ -73,7 +72,7 @@ fn render_field (
) {
for (idx, &val) in field.iter().enumerate() {
if val > 0 {
spawn_square_at(&mut commands, val, idx);
spawn_square_at(&mut commands, val, idx, asset_server.clone());
}
}
}

View File

@ -15,7 +15,7 @@ pub struct Field (pub Vec<u32>);
pub const BG_COLOR: Color = Color::srgb(0.949, 0.937, 0.769);
pub const SCOREBOARD_FONT_SIZE: f32 = 44.0;
pub const TEXT_COLOR: Color = Color::BLACK;
pub const SCORE_COLOR: Color = Color::srgb(0.4, 0.05, 0.04);
pub const SCORE_COLOR: Color = Color::srgb(0.0, 0.05, 0.66);
pub const SCOREBOARD_TEXT_PADDING: Val = Val::Px(22.0);
pub struct SqPlugin;

View File

@ -4,25 +4,27 @@ pub fn setup (
mut commands: Commands,
mut _meshes: ResMut<Assets<Mesh>>,
mut _materials: ResMut<Assets<ColorMaterial>>,
_asset_server: Res<AssetServer>,
asset_server: Res<AssetServer>,
) {
let font = asset_server.load("proxima.ttf");
commands.spawn(Camera2dBundle::default());
commands.spawn((
ScoreboardUi,
TextBundle::from_sections([
TextSection::new(
"Score: ",
"score: ",
TextStyle {
font: font.clone(),
font_size: SCOREBOARD_FONT_SIZE,
color: TEXT_COLOR,
..default()
},
),
TextSection::from_style(TextStyle {
font,
font_size: SCOREBOARD_FONT_SIZE,
color: SCORE_COLOR,
..default()
}),
])
.with_style(Style {
@ -38,7 +40,6 @@ pub fn setup (
fn draw_board (commands: &mut Commands) {
let borders = [-305., 305.];
let lines = [-150., 0., 150.];