register and bundle EntityInstance, make PlayerBundle pub

This commit is contained in:
Roberto Maurizzi 2025-07-17 16:54:48 +08:00
parent 046cc8dba8
commit ff9007c0f2
Signed by: robm
GPG key ID: F26E59AFAAADEA55

View file

@ -19,6 +19,7 @@ use crate::{
pub(super) fn plugin(app: &mut App) {
app.register_type::<Player>();
app.register_type::<EntityInstance>();
app.register_type::<PlayerAssets>();
app.load_resource::<PlayerAssets>();
app.register_ldtk_entity::<PlayerBundle>("Player");
@ -72,16 +73,21 @@ pub(super) fn plugin(app: &mut App) {
pub struct Player;
#[derive(Default, Bundle, LdtkEntity)]
struct PlayerBundle {
pub struct PlayerBundle {
#[sprite_sheet]
sprite_sheet: Sprite,
pub sprite_sheet: Sprite,
#[worldly]
worldly: Worldly,
pub worldly: Worldly,
#[grid_coords]
grid_coords: GridCoords,
// non-ecsldtk-related components
player_comp: Player,
movement: MovementController,
pub grid_coords: GridCoords,
#[from_entity_instance]
pub entity: EntityInstance,
// EntityInstance gives access to entity-specific fields defined in LDtk as
// EntityInstance.field_instances.get("field_name")
// non-ecs-ldtk-related components
pub player: Player,
pub movement: MovementController,
}
fn record_player_directional_input(
@ -107,10 +113,6 @@ fn record_player_directional_input(
intent.x += 1.0;
}
// Normalize intent so that diagonal movement is the same speed as horizontal / vertical.
// This should be omitted if the input comes from an analog stick instead.
let intent = intent.normalize_or_zero();
// Apply movement intent to controllers.
for mut controller in &mut controller_query {
controller.intent = intent;