diff --git a/assets/level.ldtk b/assets/level.ldtk index 1181faa..3a7086f 100644 --- a/assets/level.ldtk +++ b/assets/level.ldtk @@ -11,7 +11,7 @@ "iid": "e1f10300-fec0-11ee-aa65-4dc22f7ac0b0", "jsonVersion": "1.5.3", "appBuildId": 476670, - "nextUid": 71, + "nextUid": 84, "identifierStyle": "Capitalize", "toc": [], "worldLayout": "Free", @@ -76,6 +76,41 @@ "tilePivotY": 0, "biomeFieldUid": null }, + { + "__type": "Entities", + "identifier": "Platforms", + "type": "Entities", + "uid": 79, + "doc": null, + "uiColor": null, + "gridSize": 32, + "guideGridWid": 0, + "guideGridHei": 0, + "displayOpacity": 1, + "inactiveOpacity": 0.6, + "hideInList": false, + "hideFieldsWhenInactive": true, + "canSelectWhenInactive": true, + "renderInWorldView": true, + "pxOffsetX": 0, + "pxOffsetY": 0, + "parallaxFactorX": 0, + "parallaxFactorY": 0, + "parallaxScaling": true, + "requiredTags": [], + "excludedTags": [], + "autoTilesKilledByOtherLayerUid": null, + "uiFilterTags": [], + "useAsyncRender": false, + "intGridValues": [], + "intGridValuesGroups": [], + "autoRuleGroups": [], + "autoSourceLayerDefUid": null, + "tilesetDefUid": null, + "tilePivotX": 0, + "tilePivotY": 0, + "biomeFieldUid": null + }, { "__type": "Tiles", "identifier": "Decoration", @@ -578,7 +613,45 @@ "limitBehavior": "MoveLastOne", "pivotX": 0, "pivotY": 0, - "fieldDefs": [] + "fieldDefs": [ + { + "identifier": "ZIndex", + "doc": null, + "__type": "Int", + "uid": 82, + "type": "F_Int", + "isArray": false, + "canBeNull": false, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "Hidden", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "StraightArrow", + "editorDisplayColor": null, + "editorAlwaysShow": false, + "editorShowInWorld": true, + "editorCutLongValues": true, + "editorTextSuffix": null, + "editorTextPrefix": null, + "useForSmartColor": false, + "exportToToc": false, + "searchable": false, + "min": null, + "max": null, + "regex": null, + "acceptFileTypes": null, + "defaultOverride": { "id": "V_Int", "params": [0] }, + "textLanguageMode": null, + "symmetricalRef": false, + "autoChainRef": true, + "allowOutOfLevelRef": true, + "allowedRefs": "OnlySame", + "allowedRefsEntityUid": null, + "allowedRefTags": [], + "tilesetUid": null + } + ] }, { "identifier": "PurpleSlime", @@ -792,6 +865,119 @@ "tilesetUid": null } ] + }, + { + "identifier": "OneWayPlatform", + "uid": 80, + "tags": [], + "exportToToc": false, + "allowOutOfBounds": false, + "doc": null, + "width": 32, + "height": 16, + "resizableX": false, + "resizableY": false, + "minWidth": null, + "maxWidth": null, + "minHeight": null, + "maxHeight": null, + "keepAspectRatio": false, + "tileOpacity": 1, + "fillOpacity": 0.08, + "lineOpacity": 0, + "hollow": false, + "color": "#FEAE34", + "renderMode": "Tile", + "showName": true, + "tilesetId": 8, + "tileRenderMode": "Cover", + "tileRect": { "tilesetUid": 8, "x": 16, "y": 0, "w": 32, "h": 16 }, + "uiTileRect": null, + "nineSliceBorders": [], + "maxCount": 0, + "limitScope": "PerLevel", + "limitBehavior": "MoveLastOne", + "pivotX": 0, + "pivotY": 0, + "fieldDefs": [ + { + "identifier": "Collision", + "doc": null, + "__type": "LocalEnum.Collision", + "uid": 81, + "type": "F_Enum(78)", + "isArray": false, + "canBeNull": false, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "Hidden", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "StraightArrow", + "editorDisplayColor": null, + "editorAlwaysShow": false, + "editorShowInWorld": true, + "editorCutLongValues": true, + "editorTextSuffix": null, + "editorTextPrefix": null, + "useForSmartColor": false, + "exportToToc": false, + "searchable": false, + "min": null, + "max": null, + "regex": null, + "acceptFileTypes": null, + "defaultOverride": { + "id": "V_String", + "params": ["OneWay"] + }, + "textLanguageMode": null, + "symmetricalRef": false, + "autoChainRef": true, + "allowOutOfLevelRef": true, + "allowedRefs": "OnlySame", + "allowedRefsEntityUid": null, + "allowedRefTags": [], + "tilesetUid": null + }, + { + "identifier": "ZIndex", + "doc": null, + "__type": "Int", + "uid": 83, + "type": "F_Int", + "isArray": false, + "canBeNull": false, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "Hidden", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "StraightArrow", + "editorDisplayColor": null, + "editorAlwaysShow": false, + "editorShowInWorld": true, + "editorCutLongValues": true, + "editorTextSuffix": null, + "editorTextPrefix": null, + "useForSmartColor": false, + "exportToToc": false, + "searchable": false, + "min": null, + "max": null, + "regex": null, + "acceptFileTypes": null, + "defaultOverride": null, + "textLanguageMode": null, + "symmetricalRef": false, + "autoChainRef": true, + "allowOutOfLevelRef": true, + "allowedRefs": "OnlySame", + "allowedRefsEntityUid": null, + "allowedRefTags": [], + "tilesetUid": null + } + ] } ], "tilesets": [ { @@ -955,7 +1141,11 @@ "averageColors": "00004b344233459b423349a959a9379c688769758ca4bc9489aab9aa58cc58bc42d74d2244ce428f4c7e4ff74abb45564ffe7dda7888a899889900000000000069a969a97a99999999989a85998699767a7579667ccc7ccc7bcb7caa7ccc7ccc22d72d2224ce228f2c7e2ff72abb25562ffeba444955ab55974300000000000059764b97599868ac679a69ab4a84477756787688475347532a932a934a837a83f2b6fb22f3acf15afa6cfdc6f899f334fccca778a7440000000000000000000059aa49aa59996999699969aa489949995999799a499949992999299948997889a385a823a379a248a749aa85a667a223a8880000000000000000000000000000189919991999199939994778166727772889289948993aaa389949a959a959a932b63b2233ad315a395c3ec6389933343ccc00000000000000000000000000008aaa8aaa8aaa8aaa8aaa7bbb8aaa7bbb8bcb7aaa8bcb7bcb69aa8aaa8aaa69aa6abb6abb6abb6abb6a226a226a226a2261a661a661a661a600000000000000006c526c426c926c91659b649c66a566a46a7b6a7b667766776aba6abb676367636da46da46da46da4616c616c616c616c8abb8abb8abb8abb00000000000000006ba5579a6689598658875cb66abb9aa989aa98ac7abc6678968a88877c87cba952755823536952475648598454455223599900000000000000000000000000003ec63da76db79dc7554885498969b4377fa29e8289cdb9ce5ade5ade49ce49ce82a68a22839b8259885b8cb5855683238aab00000000000000000000000000005d745d867da87e75448c458b86ad76ae68ac679c779b78ce3c9378867ca6adb784858933847a844788498b94854584348989000000000000000000000000000057a668b899b8449396534493858364836853697769436667755667776c73498862b66b22639c615a695c6dc5655663346bbc00000000000000000000000000006bba79b87d9679ad776a7b988abc8abc4aceaace4bba4bba6b8c4c9c4cac5b7c62a66a22639c6159695b6db5655663236abb000000000000000000000000000059aaada7a9bdcdbd59aaada7a9bdcdbd8cb8a9b98ac889b8aabaacc79ea498bd82b68b2283ad815a8a5c8ec5856783348ccc000000000000000000000000000057ac596b55946abb5abb8ca65d8677ac437b5a3368886934547a595897a57b2372957923738a7258784a7c9474557323799a0000000000000000000000000000799a5c817b9b3a886abb8464676a7a967a857a857977898889882a954a956b9562d76d2264ce628f6c7e6ff76abb65566ffe0000000000000000000000000000499977997868799579875a6465995a8957a66a735ba53a935969479a576a467732d73d2234ce328f3c7e3ff73abb35563ffe00000000000000000000000000005744985596659b747a659a76768a7a567675477738873566597698779445946572d77d2274ce728f7c7e7ff77abb75567ffe000000000000000000000000000088668a66868a9b8577666a4467846987778a7789797a87888b8676667a767ca562d76d2264ce628f6c7e6ff76abb65566ffe0000000000000000000000000000449374934c957c9574847a438475a3958695768565956853b9447a777493a493000000000000000000000000000000000000000000000000000000000000000079547a838394689a49547a6357636975786383848997b384655873748974588400000000000000000000000000000000000000000000000000000000000000007da48ca769768b554b976cba3a824a82696259526a758c986963694268478b850000000000000000000000000000000000000000000000000000000000000000696559555579557458598674573353635677575579667a8758538b848a44838b0000000000000000000000000000000000000000000000000000000000000000385437883b95534549555a855877997598772b953b9529a939a95aa84b949a840000000000000000000000000000000000000000000000000000000000000000897687898776878578998485878b789a847b8b6579998a55886998788a879b9700000000000000000000000000000000000000000000000000000000000000006ba97988897469646b987a876a997a987b987955766777765c958a858777867700000000000000000000000000000000000000000000000000000000000000005a747b947b967866a855788928884566578879a98864a579233433343334633400000000000000000000000000000000000000000000000000000000000000006a747b846a844997598669987bb8b8aabaa96ba67cba9854687669864a864b86000000000000000000000000000000000000000000000000000000000000000038ab389b48ab47ac49ab48ac579b48ac49ab38ab58bc4b8659aa5c8457ac586a0000000000000000000000000000000000000000000000000000000000000000299b2999389a379b38893955589a79bc8c9588bc7a8c599a689a5b8558ac597a00000000000000000000000000000000000000000000000000000000000000002888378936773975579b389a579b488938884b74469a465747785b75568b586a000000000000000000000000000000000000000000000000000000000000000038553865285428444755566455763a64356746743779397445674c63469b585a0000000000000000000000000000000000000000000000000000000000000000284437643a7629641555297938874879385438664665355536775a85569a785a00000000000000000000000000000000000000000000000000000000000000005789789b779b6a75668a897b64558555876576798855845694749b74a68a986a000000000000000000000000000000000000000000000000000000000000000047776766678867667799798698768866976685673755387638763b74358b387a00000000000000000000000000000000000000000000000000000000000000005777686569874944498846774677685568646987677778775a456a65ab66ca550000000000000000000000000000000000000000000000000000000000000000355656666656455546455345634558655854aa749854775577737b64777a7a7900000000000000000000000000000000000000000000000000000000000000005955895598546c758c75ba76b88797749b75a98967888789978857888788a78800000000000000000000000000000000000000000000000000000000000000006977897799776a748a749a747987ba97aa998ba8a78bab75a87ab89cbb74b97b000000000000000000000000000000000000000000000000000000000000000059645788598858546a7569996a767a766887649c767476797a54766977667976000000000000000000000000000000000000000000000000000000000000000078887a75796577777a869976987799865777667787668a53857a885a98659546000000000000000000000000000000000000000000000000000000000000000087559877a96586779788b9769866888899877576777879647759a8659888a7440000000000000000000000000000000000000000000000000000000000000000785477887a55747b7585795b7999a9667456878889aa58997888797b56776855000000000000000000000000000000000000000000000000000000000000000048545854617b644557448744537b85565899899a39994a7a58998999a5558988000000000000000000000000000000000000000000000000000000000000000089659744a6559555a55698889486a57aab43a96b9556a665a854a579a744a5550000000000000000000000000000000000000000000000000000000000000000596587556677777777778578876687778974867787668876988897779876a744000000000000000000000000000000000000000000000000000000000000000067536556875448225922415851595456654587459456947b48997a86764585560000000000000000000000000000000000000000000000000000000000000000a854a89989998556a7559766a7779976a975997596749a64968a9779a55595450000000000000000000000000000000000000000000000000000000000000000674487549854885594558445a777a7778373579b5a32675584456975958b9944000000000000000000000000000000000000000000000000000000000000000077449754b674b469b964b658a766a864a777a975a566a754a677a875b777b9650000000000000000000000000000000000000000000000000000000000000000775577547445755676558744697377637766785334556566577859755877887600000000000000000000000000000000000000000000000000000000000000002789287328772a7436793a9457795a84368a3334323364555a757b856aaa9a5500000000000000000000000000000000000000000000000000000000000000005888516b5a3349a95964797778987a5375696a536668796577887a847a74797500000000000000000000000000000000000000000000000000000000000000007b537a53767b6769748775767a9a7988759c768a7b957a847775776478647854000000000000000000000000000000000000000000000000000000000000000098999788988998889b879a869a869a86696565676965667767446854677877880000000000000000000000000000000000000000000000000000000000000000678a77997ba647887a7589999ca59ba889aa9999655667bd6ba979a967bc6c7300000000000000000000000000000000000000000000000000000000000000006aaa6556518566775965485438985888576546854ca547775999699989997a9900000000000000000000000000000000000000000000000000000000000000006678526466335644769c5a7888547a785c4454a658885c946285627b6c54674a000000000000000000000000000000000000000000000000000000000000000033843b33359c337c395c3b853899355653745a33558b536b585b5a7557885445000000000000000000000000000000000000000000000000000000000000000026551566274525664a85486546564656377756664655465545454656516a656700000000000000000000000000000000000000000000000000000000000000004964696468553a86485437443645896588548856895477446a7569547a757954000000000000000000000000000000000000000000000000000000000000000036678566399988993b968b955ba658995566588859645a986ca7796477887ca6000000000000000000000000000000000000000000000000000000000000000019562a554c665c55156a256a468c557b1a8429744a845a83196b285a496b595b00000000000000000000000000000000000000000000000000000000000000001486248645a7549615782578469a5689187629764a875a861a692a694b7a5b79000000000000000000000000000000000000000000000000000000000000000017772777489858881555255546665556199528854884588411122112411251120000000000000000000000000000000000000000000000000000000000000000" } } - ], "enums": [], "externalEnums": [], "levelFields": [] }, + ], "enums": [{ "identifier": "Collision", "uid": 78, "values": [ + { "id": "None", "tileRect": null, "color": 12470831 }, + { "id": "Solid", "tileRect": null, "color": 14120515 }, + { "id": "OneWay", "tileRect": null, "color": 15389866 } + ], "iconTilesetUid": null, "externalRelPath": null, "externalFileChecksum": null, "tags": [] }], "externalEnums": [], "levelFields": [] }, "levels": [ { "identifier": "Level_0", @@ -1014,7 +1204,7 @@ "height": 16, "defUid": 6, "px": [80,128], - "fieldInstances": [], + "fieldInstances": [{ "__identifier": "ZIndex", "__type": "Int", "__value": 0, "__tile": null, "defUid": 82, "realEditorValues": [] }], "__worldX": 80, "__worldY": 128 }, @@ -1044,6 +1234,51 @@ } ] }, + { + "__identifier": "Platforms", + "__type": "Entities", + "__cWid": 20, + "__cHei": 8, + "__gridSize": 32, + "__opacity": 1, + "__pxTotalOffsetX": 0, + "__pxTotalOffsetY": 0, + "__tilesetDefUid": null, + "__tilesetRelPath": null, + "iid": "5f999850-fec0-11ee-b019-db1a8bd99705", + "levelId": 0, + "layerDefUid": 79, + "pxOffsetX": 0, + "pxOffsetY": 0, + "visible": true, + "optionalRules": [], + "intGridCsv": [], + "autoLayerTiles": [], + "seed": 2035355, + "overrideTilesetUid": null, + "gridTiles": [], + "entityInstances": [ + { + "__identifier": "OneWayPlatform", + "__grid": [3,3], + "__pivot": [0,0], + "__tags": [], + "__tile": { "tilesetUid": 8, "x": 16, "y": 0, "w": 32, "h": 16 }, + "__smartColor": "#FEAE34", + "iid": "3e392c10-fec0-11ee-b019-c1c35fa09360", + "width": 32, + "height": 16, + "defUid": 80, + "px": [96,96], + "fieldInstances": [ + { "__identifier": "Collision", "__type": "LocalEnum.Collision", "__value": "OneWay", "__tile": null, "defUid": 81, "realEditorValues": [] }, + { "__identifier": "ZIndex", "__type": "Int", "__value": 0, "__tile": null, "defUid": 83, "realEditorValues": [] } + ], + "__worldX": 96, + "__worldY": 96 + } + ] + }, { "__identifier": "Decoration", "__type": "Tiles", diff --git a/src/level/mod.rs b/src/level/mod.rs index 1e770c9..7a67706 100644 --- a/src/level/mod.rs +++ b/src/level/mod.rs @@ -2,6 +2,25 @@ use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; use bevy_xpbd_2d::prelude::*; +#[derive(Component, Default, Reflect)] +pub struct ZIndex(i32); + +impl ZIndex { + pub fn from_field(instance: &EntityInstance) -> ZIndex { + Self( + *instance + .get_int_field("ZIndex") + .expect("expected entity to have Z Index field") + ) + } +} + +impl> From for ZIndex { + fn from(value: T) -> Self { + ZIndex(value.into()) + } +} + #[derive(Component, Default)] pub struct Tile; @@ -27,9 +46,29 @@ pub struct TileIntCell { tile_bundle: TileBundle, } + +#[derive(Default, Bundle, LdtkEntity)] +pub struct PlatformEntity { + #[with(ZIndex::from_field)] + z_index: ZIndex, + #[sprite_sheet_bundle] + sprite_sheet_bundle: SpriteSheetBundle +} + + pub struct LevelPlugin; impl Plugin for LevelPlugin { fn build(&self, app: &mut App) { - app.register_default_ldtk_int_cell_for_layer::("Ground"); + app + .register_type::() + .add_systems(Last, update_z_index) + .register_ldtk_entity::("Platforms") + .register_default_ldtk_int_cell_for_layer::("Ground"); + } +} + +fn update_z_index(mut query: Query<(&mut Transform, &ZIndex), Changed>) { + for (mut transform, z_index) in query.iter_mut() { + transform.translation.z = z_index.0 as f32; } } diff --git a/src/player/mod.rs b/src/player/mod.rs index aabf923..766e298 100644 --- a/src/player/mod.rs +++ b/src/player/mod.rs @@ -2,15 +2,16 @@ mod controller; mod input; mod movement; -use bevy::prelude::*; +use bevy::{prelude::*, render::view::RenderLayers}; use bevy_ecs_ldtk::prelude::*; use leafwing_input_manager::{action_state::ActionState, InputManagerBundle}; use self::{ controller::{CharacterControllerBundle, CharacterControllerPlugin, Jumping}, input::{InputPlugin, PlayerAction}, - movement::MovementDirection, + movement::MovementDirection }; +use crate::level::ZIndex; #[derive(Component, Deref)] pub struct Animation(benimator::Animation); @@ -48,6 +49,8 @@ impl Default for PlayerBundle { #[derive(Default, Bundle, LdtkEntity)] pub struct PlayerEntity { player_bundle: PlayerBundle, + #[with(ZIndex::from_field)] + z_index: ZIndex, #[sprite_sheet_bundle] sprite_sheet_bundle: SpriteSheetBundle, } @@ -56,7 +59,14 @@ pub struct PlayerPlugin; impl Plugin for PlayerPlugin { fn build(&self, app: &mut App) { app.add_plugins((InputPlugin, CharacterControllerPlugin)) - .add_systems(Update, (apply_movement_input, apply_jumping_input, animate)) + .add_systems( + Update, + ( + apply_movement_input, + apply_jumping_input, + animate, + ), + ) .register_ldtk_entity::("Player"); } }