initial commit
This commit is contained in:
118
src/main.rs
Normal file
118
src/main.rs
Normal file
@@ -0,0 +1,118 @@
|
||||
use bevy::{
|
||||
//bevy_dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin},
|
||||
prelude::*
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(GreetTimer(Timer::from_seconds(2.5, TimerMode::Repeating)))
|
||||
.add_systems(Update, (close_on_esc, spawn_block))
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
PhysicsPlugins::default(),
|
||||
/*FpsOverlayPlugin {
|
||||
config: FpsOverlayConfig {
|
||||
text_config: TextStyle {
|
||||
// Here we define size of our overlay
|
||||
font_size: 50.0,y
|
||||
// We can also change color of the overlay
|
||||
color: Color::srgb(0.0, 1.0, 0.0),
|
||||
// If we want, we can use a custom font
|
||||
font: default(),
|
||||
},
|
||||
},
|
||||
},*/
|
||||
))
|
||||
//.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_systems(Startup, setup)
|
||||
.run();
|
||||
}
|
||||
|
||||
//#[derive(Component)]
|
||||
//struct Ground;
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GreetTimer(Timer);
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// floor
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Plane3d::default().mesh().size(20., 20.)),
|
||||
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
|
||||
..default()
|
||||
},
|
||||
RigidBody::Static,
|
||||
Collider::cuboid(20.0, 0.0, 20.0),
|
||||
//Ground,
|
||||
));
|
||||
|
||||
// Dynamic physics object with a collision shape and initial angular velocity
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 5.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
RigidBody::Dynamic,
|
||||
Collider::cuboid(1.0, 1.0, 1.0),
|
||||
AngularVelocity(Vec3::new(1.5, 2.5, 0.5)),
|
||||
));
|
||||
|
||||
// light
|
||||
commands.spawn(DirectionalLightBundle {
|
||||
transform: Transform::from_translation(Vec3::ONE).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
|
||||
// camera
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(15.0, 5.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
}
|
||||
|
||||
pub fn close_on_esc(
|
||||
mut commands: Commands,
|
||||
focused_windows: Query<(Entity, &Window)>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
for (window, focus) in focused_windows.iter() {
|
||||
if !focus.focused {
|
||||
continue;
|
||||
}
|
||||
|
||||
if input.just_pressed(KeyCode::Escape) {
|
||||
commands.entity(window).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_block(
|
||||
time: Res<Time>,
|
||||
mut timer: ResMut<GreetTimer>,
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
if timer.0.tick(time.delta()).just_finished() {
|
||||
// Dynamic physics object with a collision shape and initial angular velocity every 2.5 Seconds
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 5.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
RigidBody::Dynamic,
|
||||
Collider::cuboid(1.0, 1.0, 1.0),
|
||||
AngularVelocity(Vec3::new(1.5, 2.5, 0.5)),
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user