Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use bevy::{
- app::{App, Startup, Update},
- core_pipeline::core_2d::{Camera2d, Camera2dBundle},
- ecs::system::{Commands, Res},
- input::{keyboard::KeyCode, Input},
- math::{UVec2, Vec2, Vec3, Vec4},
- render::color::Color,
- sprite::{Sprite, SpriteBundle},
- transform::{components::Transform, TransformBundle},
- DefaultPlugins,
- };
- use bevy_entitiles::{
- math::FillArea,
- tilemap::{
- layer::TileLayer,
- map::TilemapBuilder,
- tile::{TileBuilder, TileType},
- },
- EntiTilesPlugin,
- };
- use bevy_xpbd_2d::{
- components::{Collider, Friction, Mass, RigidBody},
- resources::Gravity,
- };
- use helpers::EntiTilesDebugPlugin;
- mod helpers;
- fn main() {
- App::new()
- .add_plugins((DefaultPlugins, EntiTilesPlugin, EntiTilesDebugPlugin))
- .add_systems(Startup, setup)
- .add_systems(Update, tilemap)
- .insert_resource(Gravity(Vec2::new(0., -98.)))
- .run();
- }
- fn setup(mut commands: Commands) {
- commands.spawn(Camera2dBundle::default());
- }
- fn tilemap(mut commands: Commands, input: Res<Input<KeyCode>>) {
- if !input.just_pressed(KeyCode::Space) {
- return;
- }
- let mut tilemap = TilemapBuilder::new(
- TileType::Square,
- UVec2::new(8, 1),
- Vec2::new(16., 16.),
- "".to_string(),
- )
- .build(&mut commands);
- tilemap.fill_rect(
- &mut commands,
- FillArea::full(&tilemap),
- TileBuilder::new().with_layer(0, TileLayer::new().with_texture_index(0)),
- );
- commands.entity(tilemap.id()).insert(tilemap);
- commands.spawn((
- Collider::cuboid(128., 16.),
- TransformBundle {
- local: Transform::from_translation(Vec3::new(64., 8., 0.)),
- ..Default::default()
- },
- RigidBody::Static,
- Friction {
- dynamic_coefficient: 0.5,
- static_coefficient: 0.5,
- ..Default::default()
- },
- ));
- commands.spawn((
- SpriteBundle {
- sprite: Sprite {
- color: Color::BLUE,
- custom_size: Some(Vec2::new(16., 16.)),
- ..Default::default()
- },
- transform: Transform::from_translation(Vec3::new(64., 64., 0.)),
- ..Default::default()
- },
- RigidBody::Dynamic,
- Friction {
- dynamic_coefficient: 0.5,
- static_coefficient: 0.5,
- ..Default::default()
- },
- Mass(20.),
- Collider::cuboid(16., 16.),
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement