you can quit the app and that is good

main
Jordan Orelli 1 year ago
commit 0a3916c7a4

@ -0,0 +1,40 @@
# Add the contents of this file to `config.toml` to enable "fast build"
# configuration. Please read the notes below.
# NOTE: For maximum performance, build using a nightly compiler
# If you are using rust stable, remove the "-Zshare-generics=y" below.
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
# NOTE: you must install
# [Mach-O LLD Port](https://lld.llvm.org/MachO/index.html) on mac. you can
# easily do this by installing llvm which includes lld with the "brew" package
# manager:
# `brew install llvm`
[target.x86_64-apple-darwin]
rustflags = [
"-C",
"link-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld",
"-Zshare-generics=y",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C",
"link-arg=-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld",
"-Zshare-generics=y",
]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=n"]
# Optional: Uncommenting the following improves compile times, but reduces the
# amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow
# compile times you should see significant gains.
[profile.dev]
debug = 1

1
.gitignore vendored

@ -0,0 +1 @@
/target

3658
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,19 @@
# [workspace]
# resolver = "2"
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
[package]
name = "rps"
version = "0.1.0"
edition = "2021"
# see more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = { version = "0.11.2", features = [ ] }
tracing = "0.1.37"

@ -0,0 +1,5 @@
#!/usr/bin/env bash
cargo run -q --features bevy/dynamic_linking
# cargo watch -c -q -s ./dev-watch

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

@ -0,0 +1,57 @@
use bevy::prelude::*;
use tracing::info;
use crate::start_menu::StartMenu;
/// The top-level structure of our game, which is a bevy plugin
pub struct Game {}
#[derive(Component)]
struct Person;
#[derive(Component)]
struct Name(String);
#[derive(Resource)]
struct Greeter {
timer: Timer,
}
fn register_people(mut commands: Commands) {
commands.spawn((Person, Name(String::from("Alice"))));
commands.spawn((Person, Name(String::from("Bob"))));
commands.spawn((Person, Name(String::from("Carol"))));
}
fn greet(time: Res<Time>, mut timer: ResMut<Greeter>, query: Query<&Name, With<Person>>) {
timer.timer.tick(time.delta());
if timer.timer.just_finished() {
for name in &query {
info!(
"Hello, {name}! elapsed: {elapsed:.2?} delta: {delta:.2?}",
name = name.0,
elapsed = time.elapsed(),
delta = time.delta(),
);
}
}
}
impl Plugin for Game {
fn build(&self, app: &mut App) {
info!("Building rps Plugin");
let timer = Greeter {
timer: Timer::from_seconds(2.0, TimerMode::Repeating),
};
app.add_plugins(StartMenu {});
app.insert_resource(timer)
.add_systems(Startup, register_people)
.add_systems(Update, greet);
}
}
impl Default for Game {
fn default() -> Self {
Self {}
}
}

@ -0,0 +1,10 @@
mod game;
mod start_menu;
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, game::Game::default()))
.run();
}

@ -0,0 +1,74 @@
use bevy::prelude::*;
use tracing::info;
pub struct StartMenu {}
#[derive(Component)]
struct Title;
#[derive(Component)]
struct QuitButton;
fn title_text() -> TextBundle {
TextBundle::from_section("Rock, Paper, Scissors", TextStyle::default())
}
fn quit_button() -> ButtonBundle {
ButtonBundle {
style: Style {
width: Val::Px(150.0),
height: Val::Px(65.0),
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor::from(Color::rgb(1.0, 0.0, 0.0)),
..default()
}
}
fn click_quit(
mut actions: Query<&Interaction, (Changed<Interaction>, With<QuitButton>)>,
mut quit: ResMut<Events<bevy::app::AppExit>>,
) {
for interaction in &mut actions {
match interaction {
Interaction::Pressed => {
info!("Quit button clicked");
quit.send_default();
}
Interaction::Hovered => {}
Interaction::None => {}
}
}
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor(Color::BLACK),
..default()
})
.with_children(|column| {
column.spawn((Title, title_text()));
column
.spawn((QuitButton, quit_button()))
.with_children(|button| {
button.spawn(TextBundle::from_section("Quit", TextStyle::default()));
});
});
}
impl Plugin for StartMenu {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, click_quit);
}
}

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cargo run -q --features bevy/dynamic_linking
Loading…
Cancel
Save