initial commit: bevy setup, background, score counter
This commit is contained in:
commit
138476111c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
4318
Cargo.lock
generated
Normal file
4318
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
Cargo.toml
Normal file
29
Cargo.toml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
cargo-features = ["codegen-backend"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "game4096"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0.86"
|
||||||
|
bevy = { version = "0.14.0", features = ["dynamic_linking"] }
|
||||||
|
itertools = "0.13.0"
|
||||||
|
log = { version = "*", features = ["max_level_debug", "release_max_level_warn"] }
|
||||||
|
|
||||||
|
# Enable a small amount of optimization in debug mode.
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
codegen-backend = "cranelift"
|
||||||
|
|
||||||
|
# Enable a large amount of optimization in debug mode for dependencies.
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
codegen-backend = "llvm"
|
||||||
|
|
||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
linker = "clang"
|
||||||
|
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
codegen-backend = true
|
||||||
82
src/main.rs
Normal file
82
src/main.rs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
// This resource tracks the game's score
|
||||||
|
#[derive(Resource, Deref, DerefMut)]
|
||||||
|
struct Score (usize);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct ScoreboardUi;
|
||||||
|
|
||||||
|
const BG_COLOR: Color = Color::srgb(0.949, 0.937, 0.769);
|
||||||
|
const SCOREBOARD_FONT_SIZE: f32 = 44.0;
|
||||||
|
const TEXT_COLOR: Color = Color::BLACK;
|
||||||
|
const SCORE_COLOR: Color = Color::srgb(0.4, 0.05, 0.04);
|
||||||
|
const SCOREBOARD_TEXT_PADDING: Val = Val::Px(22.0);
|
||||||
|
|
||||||
|
pub struct SqPlugin;
|
||||||
|
|
||||||
|
impl Plugin for SqPlugin {
|
||||||
|
fn build (&self, app: &mut App) {
|
||||||
|
// add things to your app here
|
||||||
|
app
|
||||||
|
.insert_resource(Score(0))
|
||||||
|
.insert_resource(ClearColor(BG_COLOR))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup (
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
ScoreboardUi,
|
||||||
|
TextBundle::from_sections([
|
||||||
|
TextSection::new(
|
||||||
|
"Score: ",
|
||||||
|
TextStyle {
|
||||||
|
font_size: SCOREBOARD_FONT_SIZE,
|
||||||
|
color: TEXT_COLOR,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSection::from_style(TextStyle {
|
||||||
|
font_size: SCOREBOARD_FONT_SIZE,
|
||||||
|
color: SCORE_COLOR,
|
||||||
|
..default()
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
.with_style(Style {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
top: SCOREBOARD_TEXT_PADDING,
|
||||||
|
left: SCOREBOARD_TEXT_PADDING,
|
||||||
|
..default()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_scoreboard (score: Res<Score>, mut query: Query<&mut Text, With<ScoreboardUi>>) {
|
||||||
|
let mut text = query.single_mut();
|
||||||
|
text.sections[1].value = score.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main () {
|
||||||
|
App::new()
|
||||||
|
.add_plugins((DefaultPlugins.set(WindowPlugin {
|
||||||
|
primary_window: Some(Window {
|
||||||
|
title: String::from("4096GAME"),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
}), SqPlugin))
|
||||||
|
.add_systems(Startup, setup)
|
||||||
|
.add_systems(Update, update_scoreboard)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user