Advertisement
EconomicSerg

AnimationDebug

Jul 29th, 2021
1,817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.97 KB | None | 0 0
  1. package;
  2.  
  3. import flixel.FlxG;
  4. import flixel.FlxObject;
  5. import flixel.FlxSprite;
  6. import flixel.FlxState;
  7. import flixel.addons.display.FlxGridOverlay;
  8. import flixel.group.FlxGroup.FlxTypedGroup;
  9. import flixel.text.FlxText;
  10. import flixel.util.FlxColor;
  11.  
  12. /**
  13.     *DEBUG MODE
  14.  */
  15. class AnimationDebug extends FlxState
  16. {
  17.     var bf:Boyfriend;
  18.     var dad:Character;
  19.     var char:Character;
  20.     var textAnim:FlxText;
  21.     var dumbTexts:FlxTypedGroup<FlxText>;
  22.     var animList:Array<String> = [];
  23.     var curAnim:Int = 0;
  24.     var isDad:Bool = true;
  25.     var daAnim:String = 'spooky';
  26.     var camFollow:FlxObject;
  27.  
  28.     public function new(daAnim:String = 'spooky')
  29.     {
  30.         super();
  31.         this.daAnim = daAnim;
  32.     }
  33.  
  34.     override function create()
  35.     {
  36.         FlxG.sound.music.stop();
  37.  
  38.         var gridBG:FlxSprite = FlxGridOverlay.create(10, 10);
  39.         gridBG.scrollFactor.set(0.5, 0.5);
  40.         add(gridBG);
  41.  
  42.         if (daAnim == 'bf')
  43.             isDad = false;
  44.  
  45.         if (isDad)
  46.         {
  47.             dad = new Character(0, 0, daAnim);
  48.             dad.screenCenter();
  49.             dad.debugMode = true;
  50.             add(dad);
  51.  
  52.             char = dad;
  53.             dad.flipX = false;
  54.         }
  55.         else
  56.         {
  57.             bf = new Boyfriend(0, 0);
  58.             bf.screenCenter();
  59.             bf.debugMode = true;
  60.             add(bf);
  61.  
  62.             char = bf;
  63.             bf.flipX = false;
  64.         }
  65.  
  66.         dumbTexts = new FlxTypedGroup<FlxText>();
  67.         add(dumbTexts);
  68.  
  69.         textAnim = new FlxText(300, 16);
  70.         textAnim.size = 26;
  71.         textAnim.scrollFactor.set();
  72.         add(textAnim);
  73.  
  74.         genBoyOffsets();
  75.  
  76.         camFollow = new FlxObject(0, 0, 2, 2);
  77.         camFollow.screenCenter();
  78.         add(camFollow);
  79.  
  80.         FlxG.camera.follow(camFollow);
  81.  
  82.         super.create();
  83.     }
  84.  
  85.     function genBoyOffsets(pushList:Bool = true):Void
  86.     {
  87.         var daLoop:Int = 0;
  88.  
  89.         for (anim => offsets in char.animOffsets)
  90.         {
  91.             var text:FlxText = new FlxText(10, 20 + (18 * daLoop), 0, anim + ": " + offsets, 15);
  92.             text.scrollFactor.set();
  93.             text.color = FlxColor.BLUE;
  94.             dumbTexts.add(text);
  95.  
  96.             if (pushList)
  97.                 animList.push(anim);
  98.  
  99.             daLoop++;
  100.         }
  101.     }
  102.  
  103.     function updateTexts():Void
  104.     {
  105.         dumbTexts.forEach(function(text:FlxText)
  106.         {
  107.             text.kill();
  108.             dumbTexts.remove(text, true);
  109.         });
  110.     }
  111.  
  112.     override function update(elapsed:Float)
  113.     {
  114.         textAnim.text = char.animation.curAnim.name;
  115.  
  116.         if (FlxG.keys.justPressed.E)
  117.             FlxG.camera.zoom += 0.25;
  118.         if (FlxG.keys.justPressed.Q)
  119.             FlxG.camera.zoom -= 0.25;
  120.  
  121.         if (FlxG.keys.pressed.I || FlxG.keys.pressed.J || FlxG.keys.pressed.K || FlxG.keys.pressed.L)
  122.         {
  123.             if (FlxG.keys.pressed.I)
  124.                 camFollow.velocity.y = -90;
  125.             else if (FlxG.keys.pressed.K)
  126.                 camFollow.velocity.y = 90;
  127.             else
  128.                 camFollow.velocity.y = 0;
  129.  
  130.             if (FlxG.keys.pressed.J)
  131.                 camFollow.velocity.x = -90;
  132.             else if (FlxG.keys.pressed.L)
  133.                 camFollow.velocity.x = 90;
  134.             else
  135.                 camFollow.velocity.x = 0;
  136.         }
  137.         else
  138.         {
  139.             camFollow.velocity.set();
  140.         }
  141.  
  142.         if (FlxG.keys.justPressed.W)
  143.         {
  144.             curAnim -= 1;
  145.         }
  146.  
  147.         if (FlxG.keys.justPressed.S)
  148.         {
  149.             curAnim += 1;
  150.         }
  151.  
  152.         if (curAnim < 0)
  153.             curAnim = animList.length - 1;
  154.  
  155.         if (curAnim >= animList.length)
  156.             curAnim = 0;
  157.  
  158.         if (FlxG.keys.justPressed.S || FlxG.keys.justPressed.W || FlxG.keys.justPressed.SPACE)
  159.         {
  160.             char.playAnim(animList[curAnim]);
  161.  
  162.             updateTexts();
  163.             genBoyOffsets(false);
  164.         }
  165.  
  166.         var upP = FlxG.keys.anyJustPressed([UP]);
  167.         var rightP = FlxG.keys.anyJustPressed([RIGHT]);
  168.         var downP = FlxG.keys.anyJustPressed([DOWN]);
  169.         var leftP = FlxG.keys.anyJustPressed([LEFT]);
  170.  
  171.         var holdShift = FlxG.keys.pressed.SHIFT;
  172.         var multiplier = 1;
  173.         if (holdShift)
  174.             multiplier = 10;
  175.  
  176.         if (upP || rightP || downP || leftP)
  177.         {
  178.             updateTexts();
  179.             if (upP)
  180.                 char.animOffsets.get(animList[curAnim])[1] += 1 * multiplier;
  181.             if (downP)
  182.                 char.animOffsets.get(animList[curAnim])[1] -= 1 * multiplier;
  183.             if (leftP)
  184.                 char.animOffsets.get(animList[curAnim])[0] += 1 * multiplier;
  185.             if (rightP)
  186.                 char.animOffsets.get(animList[curAnim])[0] -= 1 * multiplier;
  187.  
  188.             updateTexts();
  189.             genBoyOffsets(false);
  190.             char.playAnim(animList[curAnim]);
  191.         }
  192.  
  193.         super.update(elapsed);
  194.     }
  195. }
  196.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement