use bevy::{ core::{Time, Timer}, diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, ecs::prelude::*, input::Input, math::Vec3, prelude::{info, App, AssetServer, Handle, MouseButton, Transform}, render2::{camera::OrthographicCameraBundle, color::Color, texture::Image}, sprite2::{PipelinedSpriteBundle, Sprite}, window::WindowDescriptor, PipelinedDefaultPlugins, }; use rand::{random, Rng}; const BIRDS_PER_SECOND: u32 = 10000; const _BASE_COLOR: Color = Color::rgb(5.0, 5.0, 5.0); const GRAVITY: f32 = -9.8 * 100.0; const MAX_VELOCITY: f32 = 750.; const BIRD_SCALE: f32 = 0.15; const HALF_BIRD_SIZE: f32 = 256. * BIRD_SCALE * 0.5; struct BevyCounter { pub count: u128, pub color: Color, } struct Bird { velocity: Vec3, } // struct BirdMaterial(Handle); // impl FromWorld for BirdMaterial { // fn from_world(world: &mut World) -> Self { // let world = world.cell(); // let mut color_materials = world.get_resource_mut::>().unwrap(); // let asset_server = world.get_resource_mut::().unwrap(); // BirdMaterial(color_materials.add(asset_server.load("branding/icon.png").into())) // } // } fn main() { App::new() .insert_resource(WindowDescriptor { title: "BevyMark".to_string(), width: 800., height: 600., vsync: false, resizable: true, ..Default::default() }) .add_plugins(PipelinedDefaultPlugins) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(LogDiagnosticsPlugin::default()) // .add_plugin(WgpuResourceDiagnosticsPlugin::default()) .insert_resource(BevyCounter { count: 0, color: Color::WHITE, }) // .init_resource::() .add_startup_system(setup) .add_system(mouse_handler) .add_system(movement_system) .add_system(collision_system) .add_system(counter_system) .run(); } struct BirdTexture(Handle); fn setup( mut commands: Commands, window: Res, mut counter: ResMut, asset_server: Res, ) { let texture = asset_server.load("branding/icon.png"); if let Some(initial_count) = std::env::args() .nth(1) .and_then(|arg| arg.parse::().ok()) { spawn_birds( &mut commands, &window, &mut counter, initial_count, texture.clone_weak(), ); } commands.spawn_bundle(OrthographicCameraBundle::new_2d()); // commands.spawn_bundle(UiCameraBundle::default()); // commands.spawn_bundle(TextBundle { // text: Text { // sections: vec![ // TextSection { // value: "Bird Count: ".to_string(), // style: TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), // font_size: 40.0, // color: Color::rgb(0.0, 1.0, 0.0), // }, // }, // TextSection { // value: "".to_string(), // style: TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), // font_size: 40.0, // color: Color::rgb(0.0, 1.0, 1.0), // }, // }, // TextSection { // value: "\nAverage FPS: ".to_string(), // style: TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), // font_size: 40.0, // color: Color::rgb(0.0, 1.0, 0.0), // }, // }, // TextSection { // value: "".to_string(), // style: TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), // font_size: 40.0, // color: Color::rgb(0.0, 1.0, 1.0), // }, // }, // ], // ..Default::default() // }, // style: Style { // position_type: PositionType::Absolute, // position: Rect { // top: Val::Px(5.0), // left: Val::Px(5.0), // ..Default::default() // }, // ..Default::default() // }, // ..Default::default() // }); commands.insert_resource(BirdTexture(texture)); } #[allow(clippy::too_many_arguments)] fn mouse_handler( mut commands: Commands, _asset_server: Res, time: Res