Funkin/source/AnimationDebug.hx

194 lines
3.7 KiB
Haxe
Raw Normal View History

2020-10-04 02:42:58 -04:00
package;
import flixel.FlxG;
2020-10-04 18:27:49 -04:00
import flixel.FlxObject;
2020-10-04 17:44:52 -04:00
import flixel.FlxSprite;
2020-10-04 02:42:58 -04:00
import flixel.FlxState;
2020-10-04 17:44:52 -04:00
import flixel.addons.display.FlxGridOverlay;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText;
2020-10-04 20:53:49 -04:00
import flixel.util.FlxColor;
2020-10-04 02:42:58 -04:00
2020-10-04 17:44:52 -04:00
/**
*DEBUG MODE
*/
2020-10-18 20:59:53 -04:00
class AnimationDebug extends FlxState
2020-10-04 02:42:58 -04:00
{
2020-10-04 17:44:52 -04:00
var bf:Boyfriend;
2020-10-18 20:59:53 -04:00
var dad:Character;
2020-10-04 18:27:49 -04:00
var char:Character;
2020-10-04 17:44:52 -04:00
var textAnim:FlxText;
var dumbTexts:FlxTypedGroup<FlxText>;
var animList:Array<String> = [];
var curAnim:Int = 0;
2020-10-29 23:06:52 -04:00
var isDad:Bool = true;
2020-10-23 19:12:38 -04:00
var daAnim:String = 'spooky';
2020-10-04 18:27:49 -04:00
var camFollow:FlxObject;
2020-10-23 19:12:38 -04:00
public function new(daAnim:String = 'spooky')
2020-10-04 18:27:49 -04:00
{
super();
2020-10-23 19:12:38 -04:00
this.daAnim = daAnim;
2020-10-04 18:27:49 -04:00
}
2020-10-04 17:44:52 -04:00
2020-10-04 02:42:58 -04:00
override function create()
{
FlxG.sound.music.stop();
2020-10-04 18:27:49 -04:00
var gridBG:FlxSprite = FlxGridOverlay.create(10, 10);
gridBG.scrollFactor.set(0.5, 0.5);
2020-10-04 17:44:52 -04:00
add(gridBG);
2020-10-29 23:06:52 -04:00
if (daAnim == 'bf')
isDad = false;
2020-10-04 18:27:49 -04:00
if (isDad)
{
2020-10-23 19:12:38 -04:00
dad = new Character(0, 0, daAnim);
2020-10-04 18:27:49 -04:00
dad.screenCenter();
dad.debugMode = true;
add(dad);
char = dad;
}
else
{
bf = new Boyfriend(0, 0);
bf.screenCenter();
bf.debugMode = true;
add(bf);
char = bf;
}
2020-10-04 17:44:52 -04:00
dumbTexts = new FlxTypedGroup<FlxText>();
add(dumbTexts);
2020-10-04 18:27:49 -04:00
textAnim = new FlxText(300, 16);
2020-10-04 17:44:52 -04:00
textAnim.size = 26;
2020-10-04 18:27:49 -04:00
textAnim.scrollFactor.set();
2020-10-04 17:44:52 -04:00
add(textAnim);
genBoyOffsets();
2020-10-04 18:27:49 -04:00
camFollow = new FlxObject(0, 0, 2, 2);
camFollow.screenCenter();
add(camFollow);
FlxG.camera.follow(camFollow);
2020-10-04 02:42:58 -04:00
super.create();
}
2020-10-04 17:44:52 -04:00
function genBoyOffsets(pushList:Bool = true):Void
{
var daLoop:Int = 0;
2020-10-04 18:27:49 -04:00
for (anim => offsets in char.animOffsets)
2020-10-04 17:44:52 -04:00
{
var text:FlxText = new FlxText(10, 20 + (18 * daLoop), 0, anim + ": " + offsets, 15);
2020-10-04 18:27:49 -04:00
text.scrollFactor.set();
2020-10-04 20:53:49 -04:00
text.color = FlxColor.BLUE;
2020-10-04 17:44:52 -04:00
dumbTexts.add(text);
if (pushList)
animList.push(anim);
daLoop++;
}
}
function updateTexts():Void
{
dumbTexts.forEach(function(text:FlxText)
{
text.kill();
dumbTexts.remove(text, true);
});
}
override function update(elapsed:Float)
{
2020-10-04 18:27:49 -04:00
textAnim.text = char.animation.curAnim.name;
if (FlxG.keys.justPressed.E)
FlxG.camera.zoom += 0.25;
if (FlxG.keys.justPressed.Q)
FlxG.camera.zoom -= 0.25;
if (FlxG.keys.pressed.I || FlxG.keys.pressed.J || FlxG.keys.pressed.K || FlxG.keys.pressed.L)
{
if (FlxG.keys.pressed.I)
camFollow.velocity.y = -90;
else if (FlxG.keys.pressed.K)
camFollow.velocity.y = 90;
else
camFollow.velocity.y = 0;
if (FlxG.keys.pressed.J)
camFollow.velocity.x = -90;
else if (FlxG.keys.pressed.L)
camFollow.velocity.x = 90;
else
camFollow.velocity.x = 0;
}
else
{
camFollow.velocity.set();
}
2020-10-04 17:44:52 -04:00
if (FlxG.keys.justPressed.W)
{
curAnim -= 1;
}
if (FlxG.keys.justPressed.S)
{
curAnim += 1;
}
if (curAnim < 0)
curAnim = animList.length - 1;
if (curAnim >= animList.length)
curAnim = 0;
if (FlxG.keys.justPressed.S || FlxG.keys.justPressed.W || FlxG.keys.justPressed.SPACE)
{
2020-10-04 18:27:49 -04:00
char.playAnim(animList[curAnim]);
updateTexts();
genBoyOffsets(false);
2020-10-04 17:44:52 -04:00
}
var upP = FlxG.keys.anyJustPressed([UP]);
var rightP = FlxG.keys.anyJustPressed([RIGHT]);
var downP = FlxG.keys.anyJustPressed([DOWN]);
var leftP = FlxG.keys.anyJustPressed([LEFT]);
2020-10-04 18:27:49 -04:00
var holdShift = FlxG.keys.pressed.SHIFT;
var multiplier = 1;
if (holdShift)
multiplier = 10;
2020-10-04 17:44:52 -04:00
if (upP || rightP || downP || leftP)
{
updateTexts();
if (upP)
2020-10-04 18:27:49 -04:00
char.animOffsets.get(animList[curAnim])[1] += 1 * multiplier;
2020-10-04 17:44:52 -04:00
if (downP)
2020-10-04 18:27:49 -04:00
char.animOffsets.get(animList[curAnim])[1] -= 1 * multiplier;
2020-10-04 17:44:52 -04:00
if (leftP)
2020-10-04 18:27:49 -04:00
char.animOffsets.get(animList[curAnim])[0] += 1 * multiplier;
2020-10-04 17:44:52 -04:00
if (rightP)
2020-10-04 18:27:49 -04:00
char.animOffsets.get(animList[curAnim])[0] -= 1 * multiplier;
2020-10-04 17:44:52 -04:00
updateTexts();
genBoyOffsets(false);
2020-10-04 18:27:49 -04:00
char.playAnim(animList[curAnim]);
2020-10-04 17:44:52 -04:00
}
super.update(elapsed);
}
2020-10-04 02:42:58 -04:00
}