FullControl for stage positions

This commit is contained in:
2022-01-10 14:19:16 -07:00
parent a0e65fb4c1
commit 3ecb4cd479
2 changed files with 66 additions and 43 deletions

View File

@@ -40,39 +40,53 @@
(set character.actor.flipX ?!(= character.stageFacing character.actor.defaultFacing)) (set character.actor.flipX ?!(= character.stageFacing character.actor.defaultFacing))
(character.actor.setGraphicSize ACTOR_WIDTH) (character.actor.setGraphicSize ACTOR_WIDTH)
(character.actor.updateHitbox) (character.actor.updateHitbox)
(set character.actor.x (ifLet [(FullControl layer rpos) character.stagePosition]
(- (case character.stagePosition {
(Left (assert (<= 0 layer SceneFlxState.LAYER_MAX) "Layer $layer is out of range 0-$SceneFlxState.LAYER_MAX")
(set currentState.actorOnLeft character.actor) (let [[x y] (SpriteTools.positionOn character.actor (canvas) rpos)]
(set currentState.characterOnLeft character) (SpriteTools.scaleStampOn character.actor (canvas) rpos)
STAGE_LEFT_X) (set character.actor.x x)
(LeftBehind (set character.actor.y y)
STAGE_LEFT_X) (if (= layer SceneFlxState.LAYER_MAX)
(Right // In front of everything:
(set currentState.actorOnRight character.actor) (currentState.add character.actor)
(set currentState.characterOnRight character) (.add (nth currentState.spriteLayers layer) character.actor)))
STAGE_RIGHT_X) }
(RightBehind {
STAGE_RIGHT_X) (set character.actor.x
(otherwise (throw "unsupported stage position"))) (- (case character.stagePosition
(/ character.actor.width 2))) (Left
(set character.actor.y ACTOR_Y) (set currentState.actorOnLeft character.actor)
(let [bottom (+ character.actor.y character.actor.height)] (set currentState.characterOnLeft character)
(when (> bottom 720) STAGE_LEFT_X)
(-= character.actor.y (- bottom 720)))) (LeftBehind
(let [&mut reAddFront false] STAGE_LEFT_X)
(case character.stagePosition (Right
((or LeftBehind RightBehind) (set currentState.actorOnRight character.actor)
(set reAddFront true) (set currentState.characterOnRight character)
(+= character.actor.y STAGE_BEHIND_DY)) STAGE_RIGHT_X)
(otherwise)) (RightBehind
(when reAddFront STAGE_RIGHT_X)
(when currentState.actorOnLeft (currentState.remove currentState.actorOnLeft)) (otherwise (throw "unsupported stage position")))
(when currentState.actorOnRight (currentState.remove currentState.actorOnRight))) (/ character.actor.width 2)))
(currentState.add character.actor) (set character.actor.y ACTOR_Y)
(when reAddFront (let [bottom (+ character.actor.y character.actor.height)]
(when currentState.actorOnLeft (currentState.add currentState.actorOnLeft)) (when (> bottom 720)
(when currentState.actorOnRight (currentState.add currentState.actorOnRight)))) (-= character.actor.y (- bottom 720))))
(let [&mut reAddFront false]
(case character.stagePosition
((or LeftBehind RightBehind)
(set reAddFront true)
(+= character.actor.y STAGE_BEHIND_DY))
(otherwise))
(when reAddFront
(when currentState.actorOnLeft (currentState.remove currentState.actorOnLeft))
(when currentState.actorOnRight (currentState.remove currentState.actorOnRight)))
(currentState.add character.actor)
(when reAddFront
(when currentState.actorOnLeft (currentState.add currentState.actorOnLeft))
(when currentState.actorOnRight (currentState.add currentState.actorOnRight))))
})
(cc)) (cc))
(method :Void hideCharacter [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> character :Continuation cc] (method :Void hideCharacter [:Character<FlxStagePosition,FlxStageFacing,ActorFlxSprite> character :Continuation cc]
@@ -306,18 +320,23 @@
(currentState.add prop))) (currentState.add prop)))
(cc)) (cc))
(prop &mut :FlxSprite _canvas null)
(method :FlxSprite canvas []
(unless _canvas
(set _canvas (new FlxSprite 0 0))
(_canvas.makeGraphic FlxG.width FlxG.height FlxColor.BLACK))
_canvas)
(method :Void smartShowPropOnScreen [:FlxSprite prop :Int layer :RelativePosition rpos :Continuation cc] (method :Void smartShowPropOnScreen [:FlxSprite prop :Int layer :RelativePosition rpos :Continuation cc]
(assert (<= 0 layer SceneFlxState.LAYER_MAX) "Layer $layer is out of range 0-$SceneFlxState.LAYER_MAX") (assert (<= 0 layer SceneFlxState.LAYER_MAX) "Layer $layer is out of range 0-$SceneFlxState.LAYER_MAX")
(let [canvas (new FlxSprite 0 0)] (let [[x y] (SpriteTools.positionOn prop (canvas) rpos)]
(canvas.makeGraphic 1280 720 FlxColor.BLACK) (SpriteTools.scaleStampOn prop (canvas) rpos)
(let [[x y] (SpriteTools.positionOn prop canvas rpos)] (set prop.x x)
(SpriteTools.scaleStampOn prop canvas rpos) (set prop.y y)
(set prop.x x) (if (= layer SceneFlxState.LAYER_MAX)
(set prop.y y) // In front of everything:
(if (= layer SceneFlxState.LAYER_MAX) (currentState.add prop)
// In front of everything: (.add (nth currentState.spriteLayers layer) prop)))
~(currentState.add prop)
(.add (nth currentState.spriteLayers layer) prop))))
(cc)) (cc))
(method :Void showPropOnScreen [:FlxSprite prop :FlxScreenPosition position :Continuation cc] (method :Void showPropOnScreen [:FlxSprite prop :FlxScreenPosition position :Continuation cc]

View File

@@ -14,6 +14,10 @@ enum FlxStagePosition {
Right; Right;
LeftBehind; LeftBehind;
RightBehind; RightBehind;
// Specify the layer and position relative to screen size, or in absolute coordinates, etc.
// AND don't move the object automatically for any reason
FullControl(layer:Int, pos:RelativePosition);
} }
enum FlxStageFacing { enum FlxStageFacing {