| Name | Message | Date |
|---|---|---|
| 📁 bunnies | 1 month ago | |
| 📄 dog.rs | 1 month ago | |
| 📄 goal.rs | 1 month ago | |
| 📄 main.rs | 1 month ago | |
| 📄 obstacles.rs | 1 month ago |
📄
src/main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
mod bunnies; mod dog; mod goal; mod obstacles; use bevy::{ DefaultPlugins, app::{App, Startup}, asset::{AssetServer, Assets}, camera::{Camera3d, OrthographicProjection, Projection, ScalingMode}, ecs::{ resource::Resource, system::{Commands, Res, ResMut}, }, gltf::GltfAssetLabel, light::{AmbientLight, DirectionalLight}, math::{Quat, Vec3, primitives::Cuboid}, mesh::{Mesh, Mesh3d, MeshBuilder, Meshable}, prelude::{Deref, DerefMut}, scene::SceneRoot, transform::components::Transform, }; use rand::SeedableRng; use rand_chacha::ChaCha8Rng; use crate::{bunnies::BunnySystems, dog::DogSystems, goal::GoalSystems}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, (setup, setup_fences)) .init_resource::<Rng>() .add_dog_systems() .add_bunny_systems() .add_goal_systems() .run(); } fn setup(mut commands: Commands) { commands.spawn(( Camera3d::default(), Projection::from(OrthographicProjection { scaling_mode: ScalingMode::FixedVertical { viewport_height: 30.0, }, ..OrthographicProjection::default_3d() }), AmbientLight { brightness: 1000.0, ..Default::default() }, Transform::from_xyz(0.0, 10.0, -5.0).looking_at(Vec3::ZERO, Vec3::Z), )); commands.spawn(( DirectionalLight { illuminance: 15000.0, ..Default::default() }, Transform::from_xyz(0.0, 0.0, 0.0).looking_to(Vec3::NEG_Y, Vec3::Z), )); } fn setup_fences( mut commands: Commands, asset_server: Res<AssetServer>, mut meshes: ResMut<Assets<Mesh>>, ) { let model = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/fantasy-town-kit/fence.glb")); let mesh = meshes.add( Cuboid::from_length(1.0) .mesh() .build() .translated_by(Vec3::new(0.5, 0.0, 0.0)), ); const SIDE: usize = 30; for offset in 0..SIDE { commands.spawn(( SceneRoot(model.clone()), Transform::from_xyz( offset as f32 - (SIDE as f32 / 2.0 - 0.5), 0.0, SIDE as f32 / 2.0 + 0.5, ) .with_rotation(Quat::from_rotation_y(std::f32::consts::FRAC_PI_2)), Mesh3d(mesh.clone()), )); commands.spawn(( SceneRoot(model.clone()), Transform::from_xyz( offset as f32 - (SIDE as f32 / 2.0 - 0.5), 0.0, -(SIDE as f32 / 2.0 - 0.5), ) .with_rotation(Quat::from_rotation_y(std::f32::consts::FRAC_PI_2)), Mesh3d(mesh.clone()), )); commands.spawn(( SceneRoot(model.clone()), Transform::from_xyz( SIDE as f32 / 2.0 - 0.5, 0.0, offset as f32 - (SIDE as f32 / 2.0 - 0.5), ), Mesh3d(mesh.clone()), )); commands.spawn(( SceneRoot(model.clone()), Transform::from_xyz( -(SIDE as f32 / 2.0 + 0.5), 0.0, offset as f32 - (SIDE as f32 / 2.0 - 0.5), ), Mesh3d(mesh.clone()), )); } } #[derive(Resource, Deref, DerefMut)] struct Rng(ChaCha8Rng); impl Default for Rng { fn default() -> Self { Self(ChaCha8Rng::seed_from_u64(0)) } }