gravity and floor. TODO: send level data to clients

This commit is contained in:
Magnus von Wachenfeldt 2022-08-13 21:59:09 +02:00
parent 46ebcdcafc
commit f24d13458a
Signed by: magnus
GPG Key ID: A469F7D71D09F795
2 changed files with 25 additions and 7 deletions

View File

@ -168,7 +168,7 @@ fn client_sync_players(
let mut client_entity = commands.spawn_bundle(SpriteBundle { let mut client_entity = commands.spawn_bundle(SpriteBundle {
sprite: Sprite { sprite: Sprite {
color: Color::rgb(0., 0.47, 1.), color: Color::rgb(0., 0.47, 1.),
custom_size: Some(Vec2::new(1., 1.)), custom_size: Some(Vec2::new(5., 5.)),
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
@ -207,7 +207,7 @@ fn client_sync_players(
let projectile_entity = commands.spawn_bundle(SpriteBundle { let projectile_entity = commands.spawn_bundle(SpriteBundle {
sprite: Sprite { sprite: Sprite {
color: Color::rgb(0.25, 0.25, 0.75), color: Color::rgb(0.25, 0.25, 0.75),
custom_size: Some(Vec2::new(50.0, 100.0)), custom_size: Some(Vec2::new(5., 5.0)),
..default() ..default()
}, },
..default() ..default()

View File

@ -66,13 +66,15 @@ fn main() {
app.add_system(server_network_sync); app.add_system(server_network_sync);
app.add_system(move_players_system); app.add_system(move_players_system);
app.add_system(update_projectiles_system); app.add_system(update_projectiles_system);
app.add_system(update_visulizer_system); app.add_system(update_visualizer_system);
app.add_system(despawn_projectile_system); app.add_system(despawn_projectile_system);
app.add_system_to_stage(CoreStage::PostUpdate, projectile_on_removal_system); app.add_system_to_stage(CoreStage::PostUpdate, projectile_on_removal_system);
app.add_startup_system(setup_level); app.add_startup_system(setup_level);
app.add_startup_system(setup_simple_camera); app.add_startup_system(setup_simple_camera);
app.add_startup_stage("floor_setup", SystemStage::single(spawn_floor));
app.run(); app.run();
} }
@ -108,14 +110,13 @@ fn server_update_system(
.spawn_bundle(SpriteBundle { .spawn_bundle(SpriteBundle {
sprite: Sprite { sprite: Sprite {
color: Color::rgb(0., 0.47, 1.), color: Color::rgb(0., 0.47, 1.),
custom_size: Some(Vec2::new(1., 1.)), custom_size: Some(Vec2::new(5., 5.)),
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
}) })
.insert(RigidBody::Dynamic) .insert(RigidBody::Dynamic)
.insert(LockedAxes::ROTATION_LOCKED | LockedAxes::TRANSLATION_LOCKED_Y) .insert(Collider::cuboid(5., 5.))
.insert(Collider::capsule_y(0.5, 0.5))
.insert(PlayerInput::default()) .insert(PlayerInput::default())
.insert(Velocity::default()) .insert(Velocity::default())
.insert(Player { .insert(Player {
@ -214,7 +215,7 @@ fn update_projectiles_system(
} }
} }
fn update_visulizer_system( fn update_visualizer_system(
mut egui_context: ResMut<EguiContext>, mut egui_context: ResMut<EguiContext>,
mut visualizer: ResMut<RenetServerVisualizer<200>>, mut visualizer: ResMut<RenetServerVisualizer<200>>,
server: Res<RenetServer>, server: Res<RenetServer>,
@ -294,3 +295,20 @@ fn projectile_on_removal_system(
server.broadcast_message(ServerChannel::ServerMessages.id(), message); server.broadcast_message(ServerChannel::ServerMessages.id(), message);
} }
} }
fn spawn_floor(mut commands: Commands) {
let width = 300.;
let height = 3.;
commands
.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0., 0.47, 1.),
custom_size: Some(Vec2::new(width, height)),
..Default::default()
},
..Default::default()
})
.insert(RigidBody::Fixed)
.insert(Collider::cuboid(width / 2., height / 2.));
}