1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-19 13:23:06 +00:00
Funkin/source/Character.hx
2021-01-14 23:33:12 -05:00

416 lines
13 KiB
Haxe

package;
import flixel.FlxSprite;
import flixel.animation.FlxBaseAnimation;
import flixel.graphics.frames.FlxAtlasFrames;
using StringTools;
class Character extends FlxSprite
{
public var animOffsets:Map<String, Array<Dynamic>>;
public var debugMode:Bool = false;
public var isPlayer:Bool = false;
public var curCharacter:String = 'bf';
public var holdTimer:Float = 0;
public function new(x:Float, y:Float, ?character:String = "bf", ?isPlayer:Bool = false)
{
animOffsets = new Map<String, Array<Dynamic>>();
super(x, y);
curCharacter = character;
this.isPlayer = isPlayer;
var tex:FlxAtlasFrames;
antialiasing = true;
switch (curCharacter)
{
case 'gf':
// GIRLFRIEND CODE
tex = FlxAtlasFrames.fromSparrow('assets/images/GF_assets.png', 'assets/images/GF_assets.xml');
frames = tex;
animation.addByPrefix('cheer', 'GF Cheer', 24, false);
animation.addByPrefix('singLEFT', 'GF left note', 24, false);
animation.addByPrefix('singRIGHT', 'GF Right Note', 24, false);
animation.addByPrefix('singUP', 'GF Up Note', 24, false);
animation.addByPrefix('singDOWN', 'GF Down Note', 24, false);
animation.addByIndices('sad', 'gf sad', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], "", 24, false);
animation.addByIndices('danceLeft', 'GF Dancing Beat', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], "", 24, false);
animation.addByIndices('danceRight', 'GF Dancing Beat', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24, false);
animation.addByIndices('hairBlow', "GF Dancing Beat Hair blowing", [0, 1, 2, 3], "", 24);
animation.addByIndices('hairFall', "GF Dancing Beat Hair Landing", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], "", 24, false);
animation.addByPrefix('scared', 'GF FEAR', 24);
addOffset('cheer');
addOffset('sad', -2, -2);
addOffset('danceLeft', 0, -9);
addOffset('danceRight', 0, -9);
addOffset("singUP", 0, 4);
addOffset("singRIGHT", 0, -20);
addOffset("singLEFT", 0, -19);
addOffset("singDOWN", 0, -20);
addOffset('hairBlow', 45, -8);
addOffset('hairFall', 0, -9);
addOffset('scared', -2, -17);
playAnim('danceRight');
case 'gf-car':
tex = FlxAtlasFrames.fromSparrow('assets/images/gfCar.png', 'assets/images/gfCar.xml');
frames = tex;
animation.addByIndices('singUP', 'GF Dancing Beat Hair blowing CAR', [0], "", 24, false);
animation.addByIndices('danceLeft', 'GF Dancing Beat Hair blowing CAR', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], "", 24, false);
animation.addByIndices('danceRight', 'GF Dancing Beat Hair blowing CAR', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24,
false);
addOffset('danceLeft', 0);
addOffset('danceRight', 0);
playAnim('danceRight');
case 'dad':
// DAD ANIMATION LOADING CODE
tex = FlxAtlasFrames.fromSparrow('assets/images/DADDY_DEAREST.png', 'assets/images/DADDY_DEAREST.xml');
frames = tex;
animation.addByPrefix('idle', 'Dad idle dance', 24);
animation.addByPrefix('singUP', 'Dad Sing Note UP', 24);
animation.addByPrefix('singRIGHT', 'Dad Sing Note RIGHT', 24);
animation.addByPrefix('singDOWN', 'Dad Sing Note DOWN', 24);
animation.addByPrefix('singLEFT', 'Dad Sing Note LEFT', 24);
addOffset('idle');
addOffset("singUP", -6, 50);
addOffset("singRIGHT", 0, 27);
addOffset("singLEFT", -10, 10);
addOffset("singDOWN", 0, -30);
playAnim('idle');
case 'spooky':
tex = FlxAtlasFrames.fromSparrow('assets/images/spooky_kids_assets.png', 'assets/images/spooky_kids_assets.xml');
frames = tex;
animation.addByPrefix('singUP', 'spooky UP NOTE', 24, false);
animation.addByPrefix('singDOWN', 'spooky DOWN note', 24, false);
animation.addByPrefix('singLEFT', 'note sing left', 24, false);
animation.addByPrefix('singRIGHT', 'spooky sing right', 24, false);
animation.addByIndices('danceLeft', 'spooky dance idle', [0, 2, 6], "", 12, false);
animation.addByIndices('danceRight', 'spooky dance idle', [8, 10, 12, 14], "", 12, false);
addOffset('danceLeft');
addOffset('danceRight');
addOffset("singUP", -20, 26);
addOffset("singRIGHT", -130, -14);
addOffset("singLEFT", 130, -10);
addOffset("singDOWN", -50, -130);
playAnim('danceRight');
case 'mom':
tex = FlxAtlasFrames.fromSparrow('assets/images/Mom_Assets.png', 'assets/images/Mom_Assets.xml');
frames = tex;
animation.addByPrefix('idle', "Mom Idle", 24, false);
animation.addByPrefix('singUP', "Mom Up Pose", 24, false);
animation.addByPrefix('singDOWN', "MOM DOWN POSE", 24, false);
animation.addByPrefix('singLEFT', 'Mom Left Pose', 24, false);
// ANIMATION IS CALLED MOM LEFT POSE BUT ITS FOR THE RIGHT
// CUZ DAVE IS DUMB!
animation.addByPrefix('singRIGHT', 'Mom Pose Left', 24, false);
addOffset('idle');
addOffset("singUP", 14, 71);
addOffset("singRIGHT", 10, -60);
addOffset("singLEFT", 250, -23);
addOffset("singDOWN", 20, -160);
playAnim('idle');
case 'mom-car':
tex = FlxAtlasFrames.fromSparrow('assets/images/momCar.png', 'assets/images/momCar.xml');
frames = tex;
animation.addByPrefix('idle', "Mom Idle", 24, false);
animation.addByPrefix('singUP', "Mom Up Pose", 24, false);
animation.addByPrefix('singDOWN', "MOM DOWN POSE", 24, false);
animation.addByPrefix('singLEFT', 'Mom Left Pose', 24, false);
// ANIMATION IS CALLED MOM LEFT POSE BUT ITS FOR THE RIGHT
// CUZ DAVE IS DUMB!
animation.addByPrefix('singRIGHT', 'Mom Pose Left', 24, false);
addOffset('idle');
addOffset("singUP", 14, 71);
addOffset("singRIGHT", 10, -60);
addOffset("singLEFT", 250, -23);
addOffset("singDOWN", 20, -160);
playAnim('idle');
case 'monster':
tex = FlxAtlasFrames.fromSparrow('assets/images/Monster_Assets.png', 'assets/images/Monster_Assets.xml');
frames = tex;
animation.addByPrefix('idle', 'monster idle', 24);
animation.addByPrefix('singUP', 'monster up note', 24, false);
animation.addByPrefix('singDOWN', 'monster down', 24, false);
animation.addByPrefix('singLEFT', 'Monster left note', 24, false);
animation.addByPrefix('singRIGHT', 'Monster Right note', 24, false);
addOffset('idle');
addOffset("singUP", -20, 50);
addOffset("singRIGHT", -51);
addOffset("singLEFT", -30);
addOffset("singDOWN", -30, -40);
playAnim('idle');
case 'pico':
tex = FlxAtlasFrames.fromSparrow('assets/images/Pico_FNF_assetss.png', 'assets/images/Pico_FNF_assetss.xml');
frames = tex;
animation.addByPrefix('idle', "Pico Idle Dance", 24);
animation.addByPrefix('singUP', 'pico Up note0', 24, false);
animation.addByPrefix('singDOWN', 'Pico Down Note0', 24, false);
if (isPlayer)
{
animation.addByPrefix('singLEFT', 'Pico NOTE LEFT0', 24, false);
animation.addByPrefix('singRIGHT', 'Pico Note Right0', 24, false);
animation.addByPrefix('singRIGHTmiss', 'Pico Note Right Miss', 24, false);
animation.addByPrefix('singLEFTmiss', 'Pico NOTE LEFT miss', 24, false);
}
else
{
// Need to be flipped! REDO THIS LATER!
animation.addByPrefix('singLEFT', 'Pico Note Right0', 24, false);
animation.addByPrefix('singRIGHT', 'Pico NOTE LEFT0', 24, false);
animation.addByPrefix('singRIGHTmiss', 'Pico NOTE LEFT miss', 24, false);
animation.addByPrefix('singLEFTmiss', 'Pico Note Right Miss', 24, false);
}
animation.addByPrefix('singUPmiss', 'pico Up note miss', 24);
animation.addByPrefix('singDOWNmiss', 'Pico Down Note MISS', 24);
playAnim('idle');
addOffset('idle');
addOffset("singUP", -29, 27);
addOffset("singRIGHT", -68, -7);
addOffset("singLEFT", 65, 9);
addOffset("singDOWN", 200, -70);
addOffset("singUPmiss", -19, 67);
addOffset("singRIGHTmiss", -60, 41);
addOffset("singLEFTmiss", 62, 64);
addOffset("singDOWNmiss", 210, -28);
playAnim('idle');
flipX = true;
case 'bf':
var tex = FlxAtlasFrames.fromSparrow('assets/images/BOYFRIEND.png', 'assets/images/BOYFRIEND.xml');
frames = tex;
animation.addByPrefix('idle', 'BF idle dance', 24, false);
animation.addByPrefix('singUP', 'BF NOTE UP0', 24, false);
animation.addByPrefix('singLEFT', 'BF NOTE LEFT0', 24, false);
animation.addByPrefix('singRIGHT', 'BF NOTE RIGHT0', 24, false);
animation.addByPrefix('singDOWN', 'BF NOTE DOWN0', 24, false);
animation.addByPrefix('singUPmiss', 'BF NOTE UP MISS', 24, false);
animation.addByPrefix('singLEFTmiss', 'BF NOTE LEFT MISS', 24, false);
animation.addByPrefix('singRIGHTmiss', 'BF NOTE RIGHT MISS', 24, false);
animation.addByPrefix('singDOWNmiss', 'BF NOTE DOWN MISS', 24, false);
animation.addByPrefix('hey', 'BF HEY', 24, false);
animation.addByPrefix('firstDeath', "BF dies", 24, false);
animation.addByPrefix('deathLoop', "BF Dead Loop", 24, true);
animation.addByPrefix('deathConfirm', "BF Dead confirm", 24, false);
animation.addByPrefix('scared', 'BF idle shaking', 24);
antialiasing = true;
addOffset('idle', -5);
addOffset("singUP", -29, 27);
addOffset("singRIGHT", -38, -7);
addOffset("singLEFT", 12, -6);
addOffset("singDOWN", -10, -50);
addOffset("singUPmiss", -29, 27);
addOffset("singRIGHTmiss", -30, 21);
addOffset("singLEFTmiss", 12, 24);
addOffset("singDOWNmiss", -11, -19);
addOffset("hey", 7, 4);
addOffset('firstDeath', 37, 11);
addOffset('deathLoop', 37, 5);
addOffset('deathConfirm', 37, 69);
addOffset('scared', -4);
flipX = true;
case 'bf-car':
var tex = FlxAtlasFrames.fromSparrow('assets/images/bfCar.png', 'assets/images/bfCar.xml');
frames = tex;
animation.addByPrefix('idle', 'BF idle dance', 24, false);
animation.addByPrefix('singUP', 'BF NOTE UP0', 24, false);
animation.addByPrefix('singLEFT', 'BF NOTE LEFT0', 24, false);
animation.addByPrefix('singRIGHT', 'BF NOTE RIGHT0', 24, false);
animation.addByPrefix('singDOWN', 'BF NOTE DOWN0', 24, false);
animation.addByPrefix('singUPmiss', 'BF NOTE UP MISS', 24, false);
animation.addByPrefix('singLEFTmiss', 'BF NOTE LEFT MISS', 24, false);
animation.addByPrefix('singRIGHTmiss', 'BF NOTE RIGHT MISS', 24, false);
animation.addByPrefix('singDOWNmiss', 'BF NOTE DOWN MISS', 24, false);
antialiasing = true;
addOffset('idle', -5);
addOffset("singUP", -29, 27);
addOffset("singRIGHT", -38, -7);
addOffset("singLEFT", 12, -6);
addOffset("singDOWN", -10, -50);
addOffset("singUPmiss", -29, 27);
addOffset("singRIGHTmiss", -30, 21);
addOffset("singLEFTmiss", 12, 24);
addOffset("singDOWNmiss", -11, -19);
flipX = true;
}
playAnim('singUP');
if (isPlayer)
{
flipX = !flipX;
// var animArray
var oldRight = animation.getByName('singRIGHT').frames;
animation.getByName('singRIGHT').frames = animation.getByName('singLEFT').frames;
animation.getByName('singLEFT').frames = oldRight;
// IF THEY HAVE MISS ANIMATIONS??
if (animation.getByName('singRIGHTmiss') != null)
{
var oldMiss = animation.getByName('singRIGHTmiss').frames;
animation.getByName('singRIGHTmiss').frames = animation.getByName('singLEFTmiss').frames;
animation.getByName('singLEFTmiss').frames = oldMiss;
}
}
}
override function update(elapsed:Float)
{
if (curCharacter != 'bf')
{
if (animation.curAnim.name.startsWith('sing'))
{
holdTimer += elapsed;
}
var dadVar:Float = 4;
if (curCharacter == 'dad')
dadVar = 6.1;
if (holdTimer >= Conductor.stepCrochet * dadVar * 0.001)
{
dance();
holdTimer = 0;
}
}
switch (curCharacter)
{
case 'gf':
if (animation.curAnim.name == 'hairFall' && animation.curAnim.finished)
playAnim('danceRight');
}
super.update(elapsed);
}
private var danced:Bool = false;
/**
* FOR GF DANCING SHIT
*/
public function dance()
{
switch (curCharacter)
{
case 'mom':
playAnim('idle');
case 'mom-car':
playAnim('idle');
case 'bf':
playAnim('idle');
case 'bf-car':
playAnim('idle');
case 'gf':
if (!animation.curAnim.name.startsWith('hair'))
{
danced = !danced;
if (danced)
playAnim('danceRight');
else
playAnim('danceLeft');
}
case 'gf-car':
if (!animation.curAnim.name.startsWith('hair'))
{
danced = !danced;
if (danced)
playAnim('danceRight');
else
playAnim('danceLeft');
}
case 'spooky':
danced = !danced;
if (danced)
playAnim('danceRight');
else
playAnim('danceLeft');
case 'dad':
playAnim('idle');
case 'monster':
playAnim('idle');
case 'pico':
playAnim('idle');
}
}
public function playAnim(AnimName:String, Force:Bool = false, Reversed:Bool = false, Frame:Int = 0):Void
{
animation.play(AnimName, Force, Reversed, Frame);
if (animation.curAnim != null)
{
var daOffset = animOffsets.get(animation.curAnim.name);
if (animOffsets.exists(animation.curAnim.name))
{
offset.set(daOffset[0], daOffset[1]);
}
}
if (curCharacter == 'gf')
{
if (AnimName == 'singLEFT')
{
danced = true;
}
else if (AnimName == 'singRIGHT')
{
danced = false;
}
if (AnimName == 'singUP' || AnimName == 'singDOWN')
{
danced = !danced;
}
}
}
public function addOffset(name:String, x:Float = 0, y:Float = 0)
{
animOffsets[name] = [x, y];
}
}