use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor}; use rand::Rng; use crate::utils::input::{GameInputPlugin, InputButton, InputPressStatus}; mod utils; #[derive(Component)] pub struct PlayerVWBus; #[derive(States, Default, Debug, Clone, PartialEq, Eq, Hash)] pub enum GameState { #[default] Navi, Pause, Combat, } const PLAYER_SPEED: f32 = 100.; fn main() { println!("Hello, world!"); App::new() .add_plugins((DefaultPlugins, GameInputPlugin)) .init_state::() .add_systems(Startup, (setup_scene, spawn_bus, spawn_enemy)) .add_systems( Update, (move_player.run_if(in_state(GameState::Navi)), follow_player), ) .run(); } fn setup_scene( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(( Mesh2d(meshes.add(Rectangle::new(1000., 70.))), MeshMaterial2d(materials.add(Color::srgb(0.2, 0.2, 0.3))), )); commands.spawn((Camera2d, Bloom::NATURAL)); } fn spawn_bus(mut commands: Commands, asset_server: Res) { let texture = asset_server.load("bus/basicbus.png"); commands.spawn(( PlayerVWBus, Sprite { image: texture, custom_size: Some(Vec2::new(192., 133.)), ..default() }, Transform::from_xyz(2., 0., 3.), Anchor::CENTER, )); } fn spawn_enemy( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { let mut rng = rand::rng(); for _ in 0..10 { commands.spawn(( Mesh2d(meshes.add(Circle::new(10.))), MeshMaterial2d(materials.add(Color::srgb(1.1, 0.2, 0.3))), Transform::from_xyz( rng.random_range(-600..600) as f32, rng.random_range(-600..600) as f32, 1., ), )); } } fn move_player( mut player: Single<&mut Transform, With>, mut player_sprite: Single<&mut Sprite, With>, time: Res