diff --git a/assets/Spaceship.glb b/assets/Spaceship.glb new file mode 100644 index 0000000..66eca6d Binary files /dev/null and b/assets/Spaceship.glb differ diff --git a/readme.md b/readme.md index f168512..f473807 100644 --- a/readme.md +++ b/readme.md @@ -1,45 +1 @@ -Collection of useful docs to quickly start developing with bevy using RustRover on Ubuntu. - -# Setup - -- Install dependencies - - For ubuntu: - - ``` - sudo apt update - sudo apt install g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0 - ``` - - > More on this: https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md - -- Add bevy dependency to `Cargo.toml` - -- Run `cargo build` and check if compilation succeed - -- Enable Query support for RustRover - - `org.rust.cargo.evaluate.build.scripts` - - `org.rust.macros.proc` - - > More on this: https://bevy-cheatbook.github.io/setup/editor/jetbrains.html - -- Enable Reformat Code & Optimize Import on Save - - Open Setting > Tools > Action on Save and check `Reformat Code` and `Optimize Import` - -- Enable dynamic linking for faster compile in development - - On Run configuration, append `--features bevy/dynamic_linking` inside the command - - On Settings > Rust > External Linters, add `--features bevy/dynamic_linking` on Additional arguments - - > More on this: https://bevyengine.org/learn/quick-start/getting-started/setup/#dynamic-linking - -# Testing - -See [test.rs](src/people/tests.rs) for examples. - -> More on this: https://bevy-cheatbook.github.io/patterns/system-tests.html - -# References - -- [Bevy opinionated best practices](https://github.com/tbillington/bevy_best_practices) -- Bevy basic by [Jacques](https://www.youtube.com/playlist?list=PLVnntJRoP85JHGX7rGDu6LaF3fmDDbqyd) +Bevy spaceship from [Zymartu Games](https://www.youtube.com/playlist?list=PL2wAo2qwCxGDp9fzBOTy_kpUTSwM1iWWd) \ No newline at end of file diff --git a/src/camera.rs b/src/camera.rs new file mode 100644 index 0000000..b44a050 --- /dev/null +++ b/src/camera.rs @@ -0,0 +1,19 @@ +use bevy::app::App; +use bevy::prelude::{Camera3dBundle, Commands, default, Plugin, Startup, Transform, Vec3}; + +const CAMERA_DISTANCE: f32 = 80.0; + +pub struct CameraPlugin; + +impl Plugin for CameraPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, spawn_camera); + } +} + +fn spawn_camera(mut commands: Commands) { + commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(0.0, CAMERA_DISTANCE, 0.0).looking_at(Vec3::ZERO, Vec3::Z), + ..default() + }); +} diff --git a/src/debug.rs b/src/debug.rs new file mode 100644 index 0000000..39e8e06 --- /dev/null +++ b/src/debug.rs @@ -0,0 +1,20 @@ +use bevy::prelude::{App, Entity, info, Plugin, Query, Transform, Update}; + +use crate::movement::Velocity; + +pub struct DebugPlugin; + +impl Plugin for crate::DebugPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Update, print_position); + } +} + +fn print_position(query: Query<(Entity, &Velocity, &Transform)>) { + for (entity, velocity, transform) in query.iter() { + info!( + "Entity {:?} Velocity {:?} Position {:?}", + entity, velocity, transform.translation + ); + } +} diff --git a/src/main.rs b/src/main.rs index bb482fc..3475c88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,58 +1,28 @@ use bevy::DefaultPlugins; -use bevy::prelude::{App, Commands, Component, Entity, info, Query, Startup, Update}; +use bevy::prelude::{AmbientLight, App, ClearColor, Color}; + +use debug::DebugPlugin; +use movement::MovementPlugin; +use spaceship::SpaceshipPlugin; + +use crate::camera::CameraPlugin; + +mod camera; +mod debug; +mod movement; +mod spaceship; fn main() { App::new() + .insert_resource(ClearColor(Color::rgb(0.1, 0.0, 0.15))) + .insert_resource(AmbientLight { + color: Color::default(), + brightness: 750.0, + }) .add_plugins(DefaultPlugins) - .add_systems(Startup, spawn_spaceship) - .add_systems(Update, ( - apply_velocity, - print_position - )) + .add_plugins(CameraPlugin) + .add_plugins(MovementPlugin) + .add_plugins(DebugPlugin) + .add_plugins(SpaceshipPlugin) .run(); } - - -#[derive(Component, Debug)] -struct Position { - x: f32, - y: f32, -} - -#[derive(Component, Debug)] -struct Velocity { - x: f32, - y: f32, -} - -fn spawn_spaceship( - mut commands: Commands -) { - commands.spawn(( - Position { - x: 0.0, - y: 0.0, - }, - Velocity { - x: 0.2, - y: 0.1, - } - )); -} - -fn apply_velocity( - mut query: Query<(&Velocity, &mut Position)> -) { - for (velocity, mut position) in query.iter_mut() { - position.x += velocity.x; - position.y += velocity.y; - } -} - -fn print_position( - mut query: Query<(Entity, &Position, &Velocity)> -) { - for (entity, position, velocity) in query.iter_mut() { - info!("Entity {:?} Position {:?} Velocity {:?}", entity, position, velocity); - } -} diff --git a/src/movement.rs b/src/movement.rs new file mode 100644 index 0000000..e9bd170 --- /dev/null +++ b/src/movement.rs @@ -0,0 +1,20 @@ +use bevy::prelude::{App, Component, Plugin, Query, Res, Time, Transform, Update, Vec3}; + +pub struct MovementPlugin; + +impl Plugin for MovementPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Update, apply_velocity); + } +} + +fn apply_velocity(mut query: Query<(&Velocity, &mut Transform)>, time: Res