Bloxel sandbox game similar to Minecraft "Classic" (2009) written in Rust with Bevy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

use bevy::prelude::*;
use lightyear::prelude::*;
use bevy::ecs::entity::MapEntities;
use lightyear::input::native::plugin::InputPlugin;
use serde::{Deserialize, Serialize};
use crate::block::Block;
use crate::player::Player;
#[derive(Default, Deserialize, Serialize, Reflect, Clone, PartialEq, Debug)]
pub struct Inputs {
pub movement: Vec2,
pub up: bool,
pub down: bool,
}
impl MapEntities for Inputs {
fn map_entities<E: EntityMapper>(&mut self, _entity_mapper: &mut E) {}
}
pub struct ProtocolPlugin;
impl Plugin for ProtocolPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(InputPlugin::<Inputs>::default());
// marker components
app.register_component::<Player>();
app.register_component::<Block>();
app.register_component::<Transform>()
.add_prediction()
.add_interpolation_with(interpolate_transform);
// unified update systems
app.add_systems(FixedUpdate, crate::player::movement);
}
}
fn interpolate_transform(start: Transform, other: Transform, t: f32) -> Transform {
Transform {
translation: start.translation.lerp(other.translation, t),
rotation: start.rotation.slerp(other.rotation, t),
scale: start.scale.lerp(other.scale, t),
}
}