diff --git a/assets/ldtk/test.ldtk b/assets/ldtk/test.ldtk index 0f34a77..862a1ca 100644 --- a/assets/ldtk/test.ldtk +++ b/assets/ldtk/test.ldtk @@ -11,7 +11,7 @@ "iid": "597a0d00-4ce0-11ef-8b7f-6b3358d89566", "jsonVersion": "1.5.3", "appBuildId": 473703, - "nextUid": 35, + "nextUid": 43, "identifierStyle": "Capitalize", "toc": [], "worldLayout": "Free", @@ -947,6 +947,264 @@ "pivotX": 0, "pivotY": 0, "fieldDefs": [] + }, + { + "identifier": "ScrappySpawn", + "uid": 35, + "tags": [], + "exportToToc": false, + "allowOutOfBounds": false, + "doc": null, + "width": 16, + "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": "#BE4A2F", + "renderMode": "Tile", + "showName": true, + "tilesetId": 42, + "tileRenderMode": "FitInside", + "tileRect": { "tilesetUid": 42, "x": 0, "y": 0, "w": 16, "h": 16 }, + "uiTileRect": null, + "nineSliceBorders": [], + "maxCount": 0, + "limitScope": "PerLevel", + "limitBehavior": "MoveLastOne", + "pivotX": 0, + "pivotY": 0, + "fieldDefs": [ + { + "identifier": "door", + "doc": null, + "__type": "EntityRef", + "uid": 36, + "type": "F_EntityRef", + "isArray": false, + "canBeNull": true, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "RefLinkBetweenCenters", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "ZigZag", + "editorDisplayColor": "#37FF00", + "editorAlwaysShow": true, + "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": "OnlySpecificEntity", + "allowedRefsEntityUid": 14, + "allowedRefTags": [], + "tilesetUid": null + }, + { + "identifier": "SpawnName", + "doc": null, + "__type": "String", + "uid": 37, + "type": "F_String", + "isArray": false, + "canBeNull": true, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "ValueOnly", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "StraightArrow", + "editorDisplayColor": null, + "editorAlwaysShow": true, + "editorShowInWorld": true, + "editorCutLongValues": false, + "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 + }, + { + "identifier": "ActivationRadius", + "doc": null, + "__type": "Int", + "uid": 38, + "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": [30] }, + "textLanguageMode": null, + "symmetricalRef": false, + "autoChainRef": true, + "allowOutOfLevelRef": true, + "allowedRefs": "OnlySame", + "allowedRefsEntityUid": null, + "allowedRefTags": [], + "tilesetUid": null + }, + { + "identifier": "Collector", + "doc": null, + "__type": "EntityRef", + "uid": 39, + "type": "F_EntityRef", + "isArray": false, + "canBeNull": true, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "RefLinkBetweenCenters", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "CurvedArrow", + "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": "OnlySpecificEntity", + "allowedRefsEntityUid": 9, + "allowedRefTags": [], + "tilesetUid": null + }, + { + "identifier": "Gun", + "doc": null, + "__type": "String", + "uid": 40, + "type": "F_String", + "isArray": false, + "canBeNull": true, + "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 + }, + { + "identifier": "Boss", + "doc": null, + "__type": "EntityRef", + "uid": 41, + "type": "F_EntityRef", + "isArray": false, + "canBeNull": true, + "arrayMinLength": null, + "arrayMaxLength": null, + "editorDisplayMode": "RefLinkBetweenCenters", + "editorDisplayScale": 1, + "editorDisplayPos": "Above", + "editorLinkStyle": "CurvedArrow", + "editorDisplayColor": null, + "editorAlwaysShow": true, + "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": "Any", + "allowedRefsEntityUid": 11, + "allowedRefTags": [], + "tilesetUid": null + } + ] } ], "tilesets": [ { @@ -1014,6 +1272,28 @@ "opaqueTiles": "000000000000000000000000000000", "averageColors": "877687768776887788878777887786659665866586758675967586750000877787768776887687768777984498449844984498449844984498449844" } + }, + { + "__cWid": 6, + "__cHei": 6, + "identifier": "Scrappy", + "uid": 42, + "relPath": "../aseprite/scrappy.png", + "embedAtlas": null, + "pxWid": 96, + "pxHei": 96, + "tileGridSize": 16, + "spacing": 0, + "padding": 0, + "tags": [], + "tagsSourceEnumUid": null, + "enumTags": [], + "customData": [], + "savedSelections": [], + "cachedPixelData": { + "opaqueTiles": "000000000000000000000000000000000000", + "averageColors": "875487548754875487548754875486448644864486548654864486540000975497549754975497549644964496449644964496448865985598659865986588658855000000000000" + } } ], "enums": [], "externalEnums": [], "levelFields": [] }, "levels": [ @@ -7368,6 +7648,32 @@ "fieldInstances": [], "__worldX": 3920, "__worldY": -528 + }, + { + "__identifier": "ScrappySpawn", + "__grid": [22,23], + "__pivot": [0,0], + "__tags": [], + "__tile": { "tilesetUid": 42, "x": 0, "y": 0, "w": 16, "h": 16 }, + "__smartColor": "#BE4A2F", + "iid": "b6908290-4ce0-11ef-ab46-c79a256d888b", + "width": 16, + "height": 16, + "defUid": 35, + "px": [352,368], + "fieldInstances": [ + { "__identifier": "door", "__type": "EntityRef", "__value": null, "__tile": null, "defUid": 36, "realEditorValues": [] }, + { "__identifier": "SpawnName", "__type": "String", "__value": "Intro", "__tile": null, "defUid": 37, "realEditorValues": [{ + "id": "V_String", + "params": ["Intro"] + }] }, + { "__identifier": "ActivationRadius", "__type": "Int", "__value": 30, "__tile": null, "defUid": 38, "realEditorValues": [] }, + { "__identifier": "Collector", "__type": "EntityRef", "__value": null, "__tile": null, "defUid": 39, "realEditorValues": [] }, + { "__identifier": "Gun", "__type": "String", "__value": null, "__tile": null, "defUid": 40, "realEditorValues": [] }, + { "__identifier": "Boss", "__type": "EntityRef", "__value": null, "__tile": null, "defUid": 41, "realEditorValues": [] } + ], + "__worldX": 3728, + "__worldY": -656 } ] }, diff --git a/source/entities/Scrappy.hx b/source/entities/Scrappy.hx new file mode 100644 index 0000000..f4e4f7c --- /dev/null +++ b/source/entities/Scrappy.hx @@ -0,0 +1,153 @@ +package entities; + +import ui.WeaponUnlockOverlay; +import states.CreditsState; +import states.SplashScreenState; +import states.SplashScreenState.SplashImage; +import lime.tools.SplashScreen; +import flixel.util.FlxTimer; +import js.html.Console; +import echo.data.Data.CollisionData; +import states.PlayState; +import flixel.input.keyboard.FlxKey; +import flixel.math.FlxPoint; +import flixel.FlxG; +import bitdecay.flixel.spacial.Cardinal; +import flixel.FlxSprite; +import input.InputCalcuator; +import input.SimpleController; +import loaders.Aseprite; +import loaders.AsepriteMacros; +import echo.Body; +import haxe.Timer; +import ui.CharacterDialog; + +using echo.FlxEcho; + +class Scrappy extends Unibody { + public static var anims = AsepriteMacros.tagNames("assets/aseprite/scrappy.json"); + + // These need to match the strings attached to the spawns in LDTK + public static inline var SCRAPPY_INTRO = "Intro"; + + public var ogXY = FlxPoint.get(); + + var distanceToPlayer:Float; + + public var dialogIndex = 0; + + public var spawnPoint:String; + public var shutter:Shutter = null; + + public var readyTriggers:Array = []; + + var skipAllDialog = false; + var fireDashTipDisplayedHitCount = 0; + + var activationRadius = 30; + + var introDialogDone = false; + var introDialog2Done = false; + + public function new(x:Float, y:Float, spawnPoint:String, activationRadius:Int) { + #if skip_dialog + skipAllDialog = true; + #end + + super(x, y); + ogXY.set(x, y); + Aseprite.loadAllAnimations(this, AssetPaths.scrappy__json); + animation.play(anims.Idle); + this.spawnPoint = spawnPoint; + this.activationRadius = activationRadius; + + } + + override function makeBody():Body { + return this.add_body({ + x: x+8, + y: y+4, + max_velocity_x: 1000, + max_velocity_length: 1000, + drag_x: 0, + mass: 100, + shapes: [ + // Standard moving hitbox + { + type:RECT, + width: 16, + height: 16, + } + ] + }); + } + + function triggerDialog(dialog:CharacterDialog, ?callback:() -> Void) { + if (!skipAllDialog){ + PlayState.me.player.forceIdle(); + PlayState.me.openDialog(dialog); + } else { + if (callback != null) { + callback(); + } + } + } + + override public function update(delta:Float) { + super.update(delta); + updateCurrentAnimation(FlxG.mouse.getWorldPosition(tmp)); + + if (PlayState.me.dialogActive) { + // just a fail-safe to keep extra dialogs from opening up once we know one is open + return; + } + + distanceToPlayer = PlayState.me.player.getMidpoint().distanceTo(getMidpoint()); + FlxG.watch.addQuick("Distance to player", distanceToPlayer); + var checkDistance = activationRadius; + if (distanceToPlayer < checkDistance) { + + switch (spawnPoint) { + case SCRAPPY_INTRO: + switch(dialogIndex) { + case 0: + dialogIndex++; + introDialogDone = true; + + var endDialogCallback = () -> {} + + triggerDialog(new CharacterDialog(TINK, "Ah, a fellow scrapper. Nice to meet you, friend. The name's Scrappy", endDialogCallback), endDialogCallback); + } + } + } + } + + override function updateCurrentAnimation(reference:FlxPoint) { + var nextAnim = animation.curAnim.name; + + var upping = false; + var downing = false; + var lefting = false; + var righting = false; + var reversing = false; + var myPos = body.get_position(); + playAnimIfNotAlready(nextAnim, reversing, false); + } + + override function handleEnter(other:Body, data:Array) { + super.handleEnter(other, data); + if (other.object is Scrap) { + handleScrap(cast other.object); + } + } + + function handleScrap(scrap:Scrap) { + if (!scrap.collectible) { + return; + } + } + + override function draw() { + super.draw(); + } +} diff --git a/source/levels/ldtk/Level.hx b/source/levels/ldtk/Level.hx index 24ec430..8715aab 100644 --- a/source/levels/ldtk/Level.hx +++ b/source/levels/ldtk/Level.hx @@ -1,5 +1,6 @@ package levels.ldtk; +import entities.Scrappy; import entities.SimpleEnemy; import entities.TrashCan; import entities.Unibody; @@ -37,6 +38,7 @@ class Level { public var rawTerrainTilesWide = 0; public var rawTerrainTilesTall = 0; + public var scrappies:Array = []; public var tinks:Array = []; public var doors:Array = []; public var doorsBottom:Array = []; @@ -134,6 +136,13 @@ class Level { } } + if (level.l_Entities.all_ScrappySpawn.length > 0){ + for (scrappySpawn in level.l_Entities.all_ScrappySpawn) { + var scrappy = new Scrappy(scrappySpawn.pixelX, scrappySpawn.pixelY, scrappySpawn.f_SpawnName, scrappySpawn.f_ActivationRadius); + scrappies.push(scrappy); + } + } + for (t in level.l_Entities.all_PracticeTarget) { var target = new PracticeTarget(t.pixelX, t.pixelY); targets.push(target); diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index bf92cdc..1352c0c 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -290,6 +290,10 @@ class PlayState extends FlxTransitionableState { underGroup.add(tink); } + for (scrappy in level.scrappies) { + topGroup.add(scrappy); + } + for (target in level.targets) { AddInteractable(target); practiceTargets.push(target);