diff --git a/Cargo.lock b/Cargo.lock index 99446b9..e5a247f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1312,6 +1312,7 @@ dependencies = [ "bevy", "enumset", "rand", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2771225..ba45ed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2024" bevy = "0.17.3" enumset = "1.1.10" rand = "0.9.2" +serde = { version = "1.0.228", features = ["derive"] } diff --git a/src/gameplay/mod.rs b/src/gameplay/mod.rs new file mode 100644 index 0000000..8665b62 --- /dev/null +++ b/src/gameplay/mod.rs @@ -0,0 +1 @@ +pub mod navi; diff --git a/src/gameplay/navi.rs b/src/gameplay/navi.rs new file mode 100644 index 0000000..77c65b2 --- /dev/null +++ b/src/gameplay/navi.rs @@ -0,0 +1,120 @@ +use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor}; +use rand::Rng; + +use crate::{ + GameState, PauseState, + utils::input::{GameInputPlugin, InputButton, InputPressStatus}, +}; + +const PLAYER_SPEED: f32 = 100.; + +pub struct NaviGameplayPlugin; + +impl Plugin for NaviGameplayPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, (setup_scene, spawn_bus, spawn_enemy)) + .add_systems( + Update, + ( + move_player + .run_if(in_state(GameState::Navi).and(in_state(PauseState::Running))), + follow_player, + ), + ); + } +} +#[derive(Component)] +pub struct PlayerVWBus; + +pub 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)); +} + +pub 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, + )); +} + +pub 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., + ), + )); + } +} + +pub fn move_player( + mut player: Single<&mut Transform, With>, + mut player_sprite: Single<&mut Sprite, With>, + time: Res