initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
4618
Cargo.lock
generated
Normal file
4618
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
Cargo.toml
Normal file
34
Cargo.toml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[package]
|
||||||
|
name = "my_first_bevy_game"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
avian3d = "0.1.2"
|
||||||
|
bevy = "0.14.2"
|
||||||
|
log = { version = "*", features = ["max_level_debug", "release_max_level_warn"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["dynamic_linking"]
|
||||||
|
dynamic_linking = ["bevy/dynamic_linking"]
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
lto = "thin"
|
||||||
|
|
||||||
|
[profile.wasm-release]
|
||||||
|
inherits = "release"
|
||||||
|
opt-level = "s"
|
||||||
|
strip = "debuginfo"
|
||||||
|
|
||||||
|
#[workspace.metadata.cross.target.x86_64-unknown-linux-gnu]
|
||||||
|
#pre-build = [
|
||||||
|
# "dpkg --add-architecture $CROSS_DEB_ARCH",
|
||||||
|
# "apt-get update && apt-get --assume-yes install libudev-dev:$CROSS_DEB_ARCH libssl-dev:$CROSS_DEB_ARCH libasound2-dev:$CROSS_DEB_ARCH"
|
||||||
|
#]
|
||||||
5
Cross.toml
Normal file
5
Cross.toml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
pre-build = [
|
||||||
|
"dpkg --add-architecture $CROSS_DEB_ARCH",
|
||||||
|
"apt-get update && apt-get --assume-yes install libudev-dev:$CROSS_DEB_ARCH libssl-dev:$CROSS_DEB_ARCH libasound2-dev:$CROSS_DEB_ARCH"
|
||||||
|
]
|
||||||
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