Last active
March 8, 2023 16:42
-
-
Save RomainMazB/7b4ffdb43ae807f354aa85e0e2a9ae0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bevy::prelude::*; | |
use bevy_editor_pls::*; | |
fn main() { | |
App::new() | |
.add_plugins(DefaultPlugins) | |
.add_plugin(EditorPlugin) | |
.add_plugin(bevy::diagnostic::FrameTimeDiagnosticsPlugin) | |
.add_plugin(bevy::diagnostic::EntityCountDiagnosticsPlugin) | |
.add_startup_system(startup_system) | |
.add_system(cube_move) | |
.run() | |
} | |
#[derive(Component)] | |
struct Cube; | |
fn startup_system( | |
mut commands: Commands, | |
mut mesh_assets: ResMut<Assets<Mesh>>, | |
mut materials_asstes: ResMut<Assets<StandardMaterial>>, | |
){ | |
let mut cam = Camera3dBundle::default(); | |
cam.transform.translation = Vec3::ONE * 5.0; | |
cam.transform.look_at(Vec3::ZERO, Vec3::Y); | |
commands.spawn(cam); | |
commands.spawn(PbrBundle{ | |
mesh: mesh_assets.add(Mesh::from(shape::Cube { size: 1.0 })), | |
material: materials_asstes.add(StandardMaterial { | |
base_color: Color::rgb(1.0, 0.5, 0.5), | |
..Default::default() | |
}), | |
..Default::default() | |
}).insert(Cube); | |
} | |
fn cube_move( | |
input: Res<Input<KeyCode>>, | |
mut cubes: Query<&mut Transform, With<Cube>> | |
){ | |
let mut change = Vec3::ZERO; | |
if input.just_pressed(KeyCode::Z) { | |
change.z -= 1.0; | |
} | |
if input.just_pressed(KeyCode::S) { | |
change.z += 1.0; | |
} | |
if input.just_pressed(KeyCode::Q) { | |
change.x -= 1.0; | |
} | |
if input.just_pressed(KeyCode::D) { | |
change.x += 1.0; | |
} | |
if input.just_pressed(KeyCode::PageDown) { | |
change.y -= 1.0; | |
} | |
if input.just_pressed(KeyCode::PageUp) { | |
change.y += 1.0; | |
} | |
for mut cube in cubes.iter_mut() { | |
cube.translation += change; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment