feat: better (kinda) fonts
This commit is contained in:
parent
3436bcf98d
commit
391ef7fd8b
BIN
assets/proxima.ttf
Normal file
BIN
assets/proxima.ttf
Normal file
Binary file not shown.
BIN
assets/proxima_thin.ttf
Normal file
BIN
assets/proxima_thin.ttf
Normal file
Binary file not shown.
13
src/main.rs
13
src/main.rs
@ -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 {
|
let Some(&(x, y)) = sq_origins.get(position) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -32,18 +33,16 @@ fn spawn_square_at (commands: &mut Commands, level: u32, position: usize) {
|
|||||||
let text = 2i32.pow(level);
|
let text = 2i32.pow(level);
|
||||||
let label = Text2dBundle {
|
let label = Text2dBundle {
|
||||||
text: Text::from_section(text.to_string(), TextStyle {
|
text: Text::from_section(text.to_string(), TextStyle {
|
||||||
font_size: 48.,
|
font,
|
||||||
|
font_size: 44.,
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
..Default::default()
|
|
||||||
}),
|
}),
|
||||||
transform: Transform {
|
transform: Transform {
|
||||||
translation: Vec3::new(x, y, 0.0),
|
translation: Vec3::new(x, y, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
commands.spawn(SpriteBundle {
|
commands.spawn(SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
@ -73,7 +72,7 @@ fn render_field (
|
|||||||
) {
|
) {
|
||||||
for (idx, &val) in field.iter().enumerate() {
|
for (idx, &val) in field.iter().enumerate() {
|
||||||
if val > 0 {
|
if val > 0 {
|
||||||
spawn_square_at(&mut commands, val, idx);
|
spawn_square_at(&mut commands, val, idx, asset_server.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 BG_COLOR: Color = Color::srgb(0.949, 0.937, 0.769);
|
||||||
pub const SCOREBOARD_FONT_SIZE: f32 = 44.0;
|
pub const SCOREBOARD_FONT_SIZE: f32 = 44.0;
|
||||||
pub const TEXT_COLOR: Color = Color::BLACK;
|
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 const SCOREBOARD_TEXT_PADDING: Val = Val::Px(22.0);
|
||||||
|
|
||||||
pub struct SqPlugin;
|
pub struct SqPlugin;
|
||||||
|
|||||||
11
src/setup.rs
11
src/setup.rs
@ -4,25 +4,27 @@ pub fn setup (
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut _meshes: ResMut<Assets<Mesh>>,
|
mut _meshes: ResMut<Assets<Mesh>>,
|
||||||
mut _materials: ResMut<Assets<ColorMaterial>>,
|
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(Camera2dBundle::default());
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
ScoreboardUi,
|
ScoreboardUi,
|
||||||
TextBundle::from_sections([
|
TextBundle::from_sections([
|
||||||
TextSection::new(
|
TextSection::new(
|
||||||
"Score: ",
|
"score: ",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
|
font: font.clone(),
|
||||||
font_size: SCOREBOARD_FONT_SIZE,
|
font_size: SCOREBOARD_FONT_SIZE,
|
||||||
color: TEXT_COLOR,
|
color: TEXT_COLOR,
|
||||||
..default()
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
TextSection::from_style(TextStyle {
|
TextSection::from_style(TextStyle {
|
||||||
|
font,
|
||||||
font_size: SCOREBOARD_FONT_SIZE,
|
font_size: SCOREBOARD_FONT_SIZE,
|
||||||
color: SCORE_COLOR,
|
color: SCORE_COLOR,
|
||||||
..default()
|
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
.with_style(Style {
|
.with_style(Style {
|
||||||
@ -38,7 +40,6 @@ pub fn setup (
|
|||||||
|
|
||||||
|
|
||||||
fn draw_board (commands: &mut Commands) {
|
fn draw_board (commands: &mut Commands) {
|
||||||
|
|
||||||
let borders = [-305., 305.];
|
let borders = [-305., 305.];
|
||||||
let lines = [-150., 0., 150.];
|
let lines = [-150., 0., 150.];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user