register and bundle EntityInstance, make PlayerBundle pub
This commit is contained in:
parent
046cc8dba8
commit
ff9007c0f2
1 changed files with 13 additions and 11 deletions
|
@ -19,6 +19,7 @@ use crate::{
|
||||||
pub(super) fn plugin(app: &mut App) {
|
pub(super) fn plugin(app: &mut App) {
|
||||||
app.register_type::<Player>();
|
app.register_type::<Player>();
|
||||||
|
|
||||||
|
app.register_type::<EntityInstance>();
|
||||||
app.register_type::<PlayerAssets>();
|
app.register_type::<PlayerAssets>();
|
||||||
app.load_resource::<PlayerAssets>();
|
app.load_resource::<PlayerAssets>();
|
||||||
app.register_ldtk_entity::<PlayerBundle>("Player");
|
app.register_ldtk_entity::<PlayerBundle>("Player");
|
||||||
|
@ -72,16 +73,21 @@ pub(super) fn plugin(app: &mut App) {
|
||||||
pub struct Player;
|
pub struct Player;
|
||||||
|
|
||||||
#[derive(Default, Bundle, LdtkEntity)]
|
#[derive(Default, Bundle, LdtkEntity)]
|
||||||
struct PlayerBundle {
|
pub struct PlayerBundle {
|
||||||
#[sprite_sheet]
|
#[sprite_sheet]
|
||||||
sprite_sheet: Sprite,
|
pub sprite_sheet: Sprite,
|
||||||
#[worldly]
|
#[worldly]
|
||||||
worldly: Worldly,
|
pub worldly: Worldly,
|
||||||
#[grid_coords]
|
#[grid_coords]
|
||||||
grid_coords: GridCoords,
|
pub grid_coords: GridCoords,
|
||||||
// non-ecsldtk-related components
|
#[from_entity_instance]
|
||||||
player_comp: Player,
|
pub entity: EntityInstance,
|
||||||
movement: MovementController,
|
// 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(
|
fn record_player_directional_input(
|
||||||
|
@ -107,10 +113,6 @@ fn record_player_directional_input(
|
||||||
intent.x += 1.0;
|
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.
|
// Apply movement intent to controllers.
|
||||||
for mut controller in &mut controller_query {
|
for mut controller in &mut controller_query {
|
||||||
controller.intent = intent;
|
controller.intent = intent;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue