54 lines
2.2 KiB
Rust
54 lines
2.2 KiB
Rust
|
|
use fyrox::{
|
|
asset::manager::ResourceManager,
|
|
resource::texture::Texture,
|
|
core::{algebra::Vector3, math::Rect},
|
|
scene::{
|
|
base::BaseBuilder,
|
|
graph::Graph,
|
|
transform::TransformBuilder,
|
|
rigidbody::RigidBodyType,
|
|
dim2::{
|
|
collider::{ColliderBuilder, ColliderShape, CuboidShape}, rectangle::RectangleBuilder, rigidbody::RigidBodyBuilder,
|
|
},
|
|
},
|
|
};
|
|
// /mnt/23154027-2dd3-43ea-93f1-02a8df7a3c5a/projects/fyrox/platformer/assets/data/tiles/
|
|
//
|
|
pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager) {
|
|
let ground_texture = resource_manager.request::<Texture, _>("assets/data/tiles/2.png");
|
|
|
|
for x in -100..100 {
|
|
let rb_transform = TransformBuilder::new()
|
|
.with_local_position(Vector3::new(
|
|
x as f32,
|
|
-5.0,
|
|
0.0,
|
|
))
|
|
.build();
|
|
|
|
RigidBodyBuilder::new(
|
|
BaseBuilder::new()
|
|
.with_children(&[
|
|
// Collider to prevent player from moving past boundary
|
|
RectangleBuilder::new(BaseBuilder::new())
|
|
.with_texture(ground_texture.clone())
|
|
// Sprite is located in top left corner of sprite sheet
|
|
.with_uv_rect(Rect::new(0.0, 0.0, 1.0, 1.0))
|
|
.build(graph),
|
|
ColliderBuilder::new(BaseBuilder::new()).with_shape(ColliderShape::Cuboid(CuboidShape::default())).build(graph),
|
|
])
|
|
// Optional, set name of tile
|
|
.with_name(format!("Boundary ({x}, 0)",))
|
|
// Set position of tile
|
|
.with_local_transform(rb_transform),
|
|
)
|
|
// Turn off gravity for tile
|
|
.with_gravity_scale(0.)
|
|
// Set tile to be static and not rotate
|
|
.with_rotation_locked(true)
|
|
.with_body_type(RigidBodyType::Static)
|
|
.build(graph);
|
|
|
|
}
|
|
} |