diff --git a/assets/fonts/CozetteVector.ttf b/assets/fonts/CozetteVector.ttf new file mode 100644 index 0000000..ff273b7 Binary files /dev/null and b/assets/fonts/CozetteVector.ttf differ diff --git a/src/config.rs b/src/config.rs index 626b8e9..990a6c8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,8 +6,8 @@ pub const SCREEN_HEIGHT: f32 = 1080.0; pub const SCREEN_ASPECT: f32 = SCREEN_WIDTH / SCREEN_HEIGHT; // 2:3 // Grid -pub const CELL_SIZE: f32 = 32.0; -pub const TERRAIN_COLS: i32 = 21; +pub const CELL_SIZE: f32 = 24.0; +pub const TERRAIN_COLS: i32 = 30; pub const CHUNK_ROWS: i32 = 32; pub const TERRAIN_WIDTH: f32 = CELL_SIZE * TERRAIN_COLS as f32; @@ -19,7 +19,7 @@ pub const MARGIN_ABOVE: f32 = 400.0; pub const MARGIN_BELLOW: f32 = 400.0; // Player -pub const PLAYER_HITBOX: Vec2 = Vec2::new(20.0, 40.0); +pub const PLAYER_HITBOX: Vec2 = Vec2::new(16.0, 32.0); pub const FALL_SPEED: f32 = 500.0; pub const DIVE_SPEED: f32 = 2000.0; pub const HORIZONTAL_SPEED: f32 = 400.0; diff --git a/src/font.rs b/src/font.rs new file mode 100644 index 0000000..4d559ce --- /dev/null +++ b/src/font.rs @@ -0,0 +1,21 @@ +use bevy::{asset::AssetApp, prelude::*, text::Font}; + +const COZETTE_BYTES: &[u8] = include_bytes!("../assets/fonts/CozetteVector.ttf"); + +#[derive(Resource)] +pub struct GameFont(pub Handle); + +pub struct FontPlugin; + +impl Plugin for FontPlugin { + fn build(&self, app: &mut App) { + app.init_asset::(); + + let handle = { + let mut fonts = app.world_mut().resource_mut::>(); + fonts.add(Font::from_bytes(COZETTE_BYTES.to_vec())) + }; + + app.insert_resource(GameFont(handle)); + } +} diff --git a/src/gameplay/score.rs b/src/gameplay/score.rs index fcdac09..ac7144b 100644 --- a/src/gameplay/score.rs +++ b/src/gameplay/score.rs @@ -2,6 +2,7 @@ use bevy::prelude::*; use crate::{ config::START_POSITION, + font::GameFont, gameplay::player::{Player, move_player}, states::GameState, }; @@ -18,11 +19,12 @@ fn update_depth(mut depth: ResMut, player: Single<&Transform, With) { commands.spawn(( - Text::new("0"), + Text::new(""), TextFont { - font_size: FontSize::Px(50.0), + font: FontSource::Handle(game_font.0.clone()), + font_size: FontSize::Px(60.0), ..default() }, TextColor(Color::WHITE), @@ -39,7 +41,7 @@ fn spawn_depth_text(mut commands: Commands) { // Update depth score texts fn update_depth_text(depth: Res, texts: Query<&mut Text, With>) { for mut text in texts { - text.0 = format!("Score: {}", (depth.0 / 100.0).floor()); + text.0 = format!("{}", (depth.0 / 100.0).floor()); } } diff --git a/src/main.rs b/src/main.rs index afeb48f..aee91e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ +use std::time::UNIX_EPOCH; + use bevy::{prelude::*, window::PresentMode}; use bevy_egui::{EguiGlobalSettings, EguiPlugin}; use crate::config::{SCREEN_HEIGHT, SCREEN_WIDTH}; use crate::debug::DebugPlugin; +use crate::font::FontPlugin; use crate::gameplay::bounds::BoundsPlugin; use crate::gameplay::camera::CameraPlugin; use crate::gameplay::collision::CollisionPlugin; @@ -17,6 +20,7 @@ use crate::world::WorldPlugin; mod config; mod debug; +mod font; mod gameplay; mod screen; mod states; @@ -38,6 +42,7 @@ fn main() { }), ..default() })) + .add_plugins(FontPlugin) // Font .add_plugins(PlayerPlugin) // Player .add_plugins(ScreenPlugin) // Virtual screen .add_plugins(CameraPlugin) // Camera @@ -48,6 +53,7 @@ fn main() { .add_plugins(GameStatePlugin) // Game states .add_plugins(MainMenuPlugin) // Main Menu .add_plugins(GameOverPlugin) // GameOver + // Debug UI .insert_resource(EguiGlobalSettings { auto_create_primary_context: false, ..default() diff --git a/src/states/game_over.rs b/src/states/game_over.rs index f1f6776..cdcd4f9 100644 --- a/src/states/game_over.rs +++ b/src/states/game_over.rs @@ -1,12 +1,16 @@ use bevy::prelude::*; -use crate::{gameplay::camera::MainCamera, states::GameState, world::RunSeed}; +use crate::{font::GameFont, gameplay::camera::MainCamera, states::GameState, world::RunSeed}; // To delete game over's components #[derive(Component)] pub struct GameOver; -fn game_over(mut commands: Commands, mut main_camera: Single<&mut Camera, With>) { +fn game_over( + mut commands: Commands, + mut main_camera: Single<&mut Camera, With>, + game_font: Res, +) { main_camera.is_active = true; commands.spawn(( @@ -27,6 +31,7 @@ fn game_over(mut commands: Commands, mut main_camera: Single<&mut Camera, With) { commands.spawn(( MainMenu, Node { @@ -23,19 +23,62 @@ fn main_menu(mut commands: Commands) { // Texts children![ ( - Text::new("DOWN INTO THE VOID"), + Text::new("DOWN INTO"), TextFont { - font_size: FontSize::Px(120.0), + font: FontSource::Handle(game_font.0.clone()), + font_size: FontSize::Px(100.0), + ..default() + }, + Node { + margin: UiRect::bottom(Val::Px(-30.0)), ..default() }, ), ( - Text::new("Press Enter to fall into the void"), + Text::new("THE VOID"), TextFont { - font_size: FontSize::Px(40.0), + font: FontSource::Handle(game_font.0.clone()), + font_size: FontSize::Px(100.0), ..default() - } - ) + }, + Node { + margin: UiRect::bottom(Val::Px(40.0)), + ..default() + }, + ), + ( + Node { + flex_direction: FlexDirection::Row, + ..default() + }, + children![ + ( + Text::new("Press "), + TextFont { + font: FontSource::Handle(game_font.0.clone()), + font_size: FontSize::Px(40.0), + ..default() + }, + ), + ( + Text::new("Enter"), + TextFont { + font: FontSource::Handle(game_font.0.clone()), + font_size: FontSize::Px(40.0), + ..default() + }, + TextColor(Color::srgb(1.0, 1.0, 0.0)), + ), + ( + Text::new(" to fall"), + TextFont { + font: FontSource::Handle(game_font.0.clone()), + font_size: FontSize::Px(40.0), + ..default() + }, + ), + ], + ), ], )); }