2023-11-07 04:04:22 -05:00
|
|
|
package funkin.ui.freeplay;
|
2021-10-21 15:05:32 -04:00
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2021-10-21 23:08:48 -04:00
|
|
|
import flixel.util.FlxSignal;
|
2022-11-15 02:23:44 -05:00
|
|
|
import funkin.util.assets.FlxAnimationUtil;
|
2023-08-28 22:01:25 -04:00
|
|
|
import funkin.graphics.adobeanimate.FlxAtlasSprite;
|
2024-03-24 04:53:05 -04:00
|
|
|
import funkin.audio.FunkinSound;
|
2023-08-31 01:56:35 -04:00
|
|
|
import flixel.util.FlxTimer;
|
2024-03-23 17:50:48 -04:00
|
|
|
import funkin.audio.FunkinSound;
|
2023-08-31 01:56:35 -04:00
|
|
|
import funkin.audio.FlxStreamSound;
|
2021-10-21 15:05:32 -04:00
|
|
|
|
2023-08-28 22:01:25 -04:00
|
|
|
class DJBoyfriend extends FlxAtlasSprite
|
2021-10-21 15:05:32 -04:00
|
|
|
{
|
2023-01-22 19:55:30 -05:00
|
|
|
// Represents the sprite's current status.
|
|
|
|
// Without state machines I would have driven myself crazy years ago.
|
|
|
|
public var currentState:DJBoyfriendState = Intro;
|
|
|
|
|
|
|
|
// A callback activated when the intro animation finishes.
|
|
|
|
public var onIntroDone:FlxSignal = new FlxSignal();
|
|
|
|
|
|
|
|
// A callback activated when Boyfriend gets spooked.
|
|
|
|
public var onSpook:FlxSignal = new FlxSignal();
|
|
|
|
|
|
|
|
// playAnim stolen from Character.hx, cuz im lazy lol!
|
|
|
|
// TODO: Switch this class to use SwagSprite instead.
|
|
|
|
public var animOffsets:Map<String, Array<Dynamic>>;
|
|
|
|
|
2023-08-29 00:09:48 -04:00
|
|
|
var gotSpooked:Bool = false;
|
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
static final SPOOK_PERIOD:Float = 10.0;
|
|
|
|
static final TV_PERIOD:Float = 10.0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
// Time since dad last SPOOKED you.
|
|
|
|
var timeSinceSpook:Float = 0;
|
|
|
|
|
|
|
|
public function new(x:Float, y:Float)
|
|
|
|
{
|
2023-08-28 22:01:25 -04:00
|
|
|
super(x, y, Paths.animateAtlas("freeplay/freeplay-boyfriend", "preload"));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
animOffsets = new Map<String, Array<Dynamic>>();
|
|
|
|
|
2023-08-29 03:11:40 -04:00
|
|
|
anim.callback = function(name, number) {
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "Boyfriend DJ watchin tv OG":
|
|
|
|
if (number == 85) runTvLogic();
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
setupAnimations();
|
2023-08-28 22:01:25 -04:00
|
|
|
trace(listAnimations());
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-08-28 22:01:25 -04:00
|
|
|
FlxG.debugger.track(this);
|
2023-08-29 00:09:48 -04:00
|
|
|
FlxG.console.registerObject("dj", this);
|
2023-08-28 22:01:25 -04:00
|
|
|
|
|
|
|
anim.onComplete = onFinishAnim;
|
2023-08-29 00:09:48 -04:00
|
|
|
|
|
|
|
FlxG.console.registerFunction("tv", function() {
|
|
|
|
currentState = TV;
|
|
|
|
});
|
2023-08-28 22:01:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
[remote hand under,boyfriend top head,brim piece,arm cringe l,red lazer,dj arm in,bf fist pump arm,hand raised right,forearm left,fist shaking,bf smile eyes closed face,arm cringe r,bf clenched face,face shrug,boyfriend falling,blue tint 1,shirt sleeve,bf clenched fist,head BF relaxed,blue tint 2,hand down left,blue tint 3,blue tint 4,head less smooshed,blue tint 5,boyfriend freeplay,BF head slight turn,blue tint 6,arm shrug l,blue tint 7,shoulder raised w sleeve,blue tint 8,fist pump face,blue tint 9,foot rested light,hand turnaround,arm chill right,Boyfriend DJ,arm shrug r,head back bf,hat top piece,dad bod,face surprise snap,Boyfriend DJ fist pump,office chair,foot rested right,chest down,office chair upright,body chill,bf dj afk,head mouth open dad,BF Head defalt HAIR BLOWING,hand shrug l,face piece,foot wag,turn table,shoulder up left,turntable lights,boyfriend dj body shirt blowing,body chunk turned,hand down right,dj arm out,hand shrug r,body chest out,rave hand,palm,chill face default,head back semi bf,boyfriend bottom head,DJ arm,shoulder right dad,bf surprise,boyfriend dj body,hs1,Boyfriend DJ watchin tv OG,spinning disk,hs2,arm chill left,boyfriend dj intro,hs3,hs4,chill face extra,hs5,remote hand upright,hs6,pant over table,face surprise,bf arm peace,arm turnaround,bf eyes 1,arm slammed table,eye squit,leg BF,head mid piece,arm backing,arm swoopin in,shoe right lowering,forearm right,hand out,blue tint 10,body falling back,remote thumb press,shoulder,hair spike single,bf bent
|
|
|
|
arm,crt,foot raised right,dad hand,chill face 1,chill face 2,clenched fist,head SMOOSHED,shoulder left dad,df1,body chunk upright,df2,df3,df4,hat front piece,df5,foot rested right 2,hand in,arm spun,shoe raised left,bf 1 finger hand,bf mouth 1,Boyfriend DJ confirm,forearm down ,hand raised left,remote thumb up]
|
|
|
|
*/
|
|
|
|
override public function listAnimations():Array<String>
|
|
|
|
{
|
|
|
|
var anims:Array<String> = [];
|
|
|
|
@:privateAccess
|
|
|
|
for (animKey in anim.symbolDictionary)
|
|
|
|
{
|
|
|
|
anims.push(animKey.name);
|
|
|
|
}
|
|
|
|
return anims;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public override function update(elapsed:Float):Void
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
|
|
|
switch (currentState)
|
|
|
|
{
|
|
|
|
case Intro:
|
|
|
|
// Play the intro animation then leave this state immediately.
|
2023-08-28 22:01:25 -04:00
|
|
|
if (getCurrentAnimation() != 'boyfriend dj intro') playFlashAnimation('boyfriend dj intro', true);
|
2023-01-22 19:55:30 -05:00
|
|
|
timeSinceSpook = 0;
|
|
|
|
case Idle:
|
|
|
|
// We are in this state the majority of the time.
|
2024-03-24 04:53:05 -04:00
|
|
|
if (getCurrentAnimation() != 'Boyfriend DJ')
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2024-03-24 04:53:05 -04:00
|
|
|
playFlashAnimation('Boyfriend DJ', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getCurrentAnimation() == 'Boyfriend DJ' && this.isLoopFinished())
|
|
|
|
{
|
|
|
|
if (timeSinceSpook >= SPOOK_PERIOD && !gotSpooked)
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
|
|
|
currentState = Spook;
|
|
|
|
}
|
2024-03-24 04:53:05 -04:00
|
|
|
else if (timeSinceSpook >= TV_PERIOD)
|
2023-08-29 00:09:48 -04:00
|
|
|
{
|
|
|
|
currentState = TV;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
timeSinceSpook += elapsed;
|
|
|
|
case Confirm:
|
2023-08-28 22:01:25 -04:00
|
|
|
if (getCurrentAnimation() != 'Boyfriend DJ confirm') playFlashAnimation('Boyfriend DJ confirm', false);
|
2023-01-22 19:55:30 -05:00
|
|
|
timeSinceSpook = 0;
|
|
|
|
case Spook:
|
2023-08-28 22:01:25 -04:00
|
|
|
if (getCurrentAnimation() != 'bf dj afk')
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
|
|
|
onSpook.dispatch();
|
2023-08-28 22:01:25 -04:00
|
|
|
playFlashAnimation('bf dj afk', false);
|
2024-03-24 04:53:05 -04:00
|
|
|
gotSpooked = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
timeSinceSpook = 0;
|
2023-08-28 22:47:18 -04:00
|
|
|
case TV:
|
|
|
|
if (getCurrentAnimation() != 'Boyfriend DJ watchin tv OG') playFlashAnimation('Boyfriend DJ watchin tv OG', true);
|
2023-08-29 00:09:48 -04:00
|
|
|
timeSinceSpook = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
default:
|
|
|
|
// I shit myself.
|
|
|
|
}
|
2024-03-24 04:53:05 -04:00
|
|
|
|
|
|
|
if (FlxG.keys.pressed.CONTROL)
|
|
|
|
{
|
|
|
|
if (FlxG.keys.justPressed.LEFT)
|
|
|
|
{
|
|
|
|
this.offsetX -= FlxG.keys.pressed.ALT ? 0.1 : (FlxG.keys.pressed.SHIFT ? 10.0 : 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.RIGHT)
|
|
|
|
{
|
|
|
|
this.offsetX += FlxG.keys.pressed.ALT ? 0.1 : (FlxG.keys.pressed.SHIFT ? 10.0 : 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.UP)
|
|
|
|
{
|
|
|
|
this.offsetY -= FlxG.keys.pressed.ALT ? 0.1 : (FlxG.keys.pressed.SHIFT ? 10.0 : 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.DOWN)
|
|
|
|
{
|
|
|
|
this.offsetY += FlxG.keys.pressed.ALT ? 0.1 : (FlxG.keys.pressed.SHIFT ? 10.0 : 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.SPACE)
|
|
|
|
{
|
|
|
|
currentState = (currentState == Idle ? TV : Idle);
|
|
|
|
}
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-08-28 22:01:25 -04:00
|
|
|
function onFinishAnim():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-08-28 22:01:25 -04:00
|
|
|
var name = anim.curSymbol.name;
|
2023-01-22 19:55:30 -05:00
|
|
|
switch (name)
|
|
|
|
{
|
2023-08-28 22:01:25 -04:00
|
|
|
case "boyfriend dj intro":
|
2023-01-22 19:55:30 -05:00
|
|
|
// trace('Finished intro');
|
|
|
|
currentState = Idle;
|
|
|
|
onIntroDone.dispatch();
|
2023-08-28 22:01:25 -04:00
|
|
|
case "Boyfriend DJ":
|
2023-01-22 19:55:30 -05:00
|
|
|
// trace('Finished idle');
|
2023-08-28 22:01:25 -04:00
|
|
|
case "bf dj afk":
|
2023-01-22 19:55:30 -05:00
|
|
|
// trace('Finished spook');
|
|
|
|
currentState = Idle;
|
2023-08-28 22:01:25 -04:00
|
|
|
case "Boyfriend DJ confirm":
|
2023-08-28 22:47:18 -04:00
|
|
|
|
|
|
|
case "Boyfriend DJ watchin tv OG":
|
2023-08-29 00:09:48 -04:00
|
|
|
var frame:Int = FlxG.random.bool(33) ? 112 : 166;
|
2024-03-24 04:53:05 -04:00
|
|
|
|
|
|
|
// BF switches channels when the video ends, or at a 10% chance each time his idle loops.
|
|
|
|
if (FlxG.random.bool(5))
|
2023-08-29 03:11:40 -04:00
|
|
|
{
|
|
|
|
frame = 60;
|
|
|
|
// boyfriend switches channel code?
|
2024-03-24 04:53:05 -04:00
|
|
|
// runTvLogic();
|
2023-08-29 03:11:40 -04:00
|
|
|
}
|
2024-03-24 04:53:05 -04:00
|
|
|
trace('Replay idle: ${frame}');
|
2023-08-29 00:09:48 -04:00
|
|
|
anim.play("Boyfriend DJ watchin tv OG", true, false, frame);
|
2023-01-22 19:55:30 -05:00
|
|
|
// trace('Finished confirm');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function resetAFKTimer():Void
|
|
|
|
{
|
|
|
|
timeSinceSpook = 0;
|
2024-03-24 04:53:05 -04:00
|
|
|
gotSpooked = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
var offsetX:Float = 0.0;
|
|
|
|
var offsetY:Float = 0.0;
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
function setupAnimations():Void
|
|
|
|
{
|
2024-03-24 04:53:05 -04:00
|
|
|
// Intro
|
|
|
|
addOffset('boyfriend dj intro', 8.0 - 1.3, 3.0 - 0.4);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
// Idle
|
2023-08-28 22:01:25 -04:00
|
|
|
addOffset('Boyfriend DJ', 0, 0);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
// Confirm
|
2023-08-28 22:01:25 -04:00
|
|
|
addOffset('Boyfriend DJ confirm', 0, 0);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
// AFK: Spook
|
|
|
|
addOffset('bf dj afk', 649.5, 58.5);
|
|
|
|
|
|
|
|
// AFK: TV
|
|
|
|
addOffset('Boyfriend DJ watchin tv OG', 0, 0);
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
var cartoonSnd:Null<FunkinSound> = null;
|
2023-08-29 03:11:40 -04:00
|
|
|
|
2023-08-30 20:50:07 -04:00
|
|
|
public var playingCartoon:Bool = false;
|
2023-08-30 20:46:30 -04:00
|
|
|
|
2023-08-29 03:11:40 -04:00
|
|
|
public function runTvLogic()
|
|
|
|
{
|
|
|
|
if (cartoonSnd == null)
|
|
|
|
{
|
2023-08-30 20:50:07 -04:00
|
|
|
// tv is OFF, but getting turned on
|
2024-03-24 04:53:05 -04:00
|
|
|
// Eric got FUCKING TROLLED there is no `tv_on` or `channel_switch` sound!
|
|
|
|
// FunkinSound.playOnce(Paths.sound('tv_on'), 1.0, function() {
|
|
|
|
// });
|
|
|
|
loadCartoon();
|
2023-08-30 20:50:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// plays it smidge after the click
|
2024-03-24 04:53:05 -04:00
|
|
|
// new FlxTimer().start(0.1, function(_) {
|
|
|
|
// // FunkinSound.playOnce(Paths.sound('channel_switch'));
|
|
|
|
// });
|
|
|
|
cartoonSnd.destroy();
|
|
|
|
loadCartoon();
|
2023-08-29 03:11:40 -04:00
|
|
|
}
|
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
// loadCartoon();
|
2023-08-31 01:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadCartoon()
|
|
|
|
{
|
2024-03-24 04:53:05 -04:00
|
|
|
cartoonSnd = FunkinSound.load(Paths.sound(getRandomFlashToon()), 1.0, false, true, true, function() {
|
2023-08-31 01:56:35 -04:00
|
|
|
anim.play("Boyfriend DJ watchin tv OG", true, false, 60);
|
|
|
|
});
|
2024-03-24 04:53:05 -04:00
|
|
|
|
|
|
|
// Fade out music to 40% volume over 1 second.
|
|
|
|
// This helps make the TV a bit more audible.
|
|
|
|
FlxG.sound.music.fadeOut(1.0, 0.4);
|
|
|
|
|
|
|
|
// Play the cartoon at a random time between the start and 5 seconds from the end.
|
|
|
|
cartoonSnd.time = FlxG.random.float(0, Math.max(cartoonSnd.length - (5 * Constants.MS_PER_SEC), 0.0));
|
2023-08-31 01:56:35 -04:00
|
|
|
}
|
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
final cartoonList:Array<String> = openfl.utils.Assets.list().filter(function(path) return path.startsWith("assets/sounds/cartoons/"));
|
2023-08-31 01:56:35 -04:00
|
|
|
|
|
|
|
function getRandomFlashToon():String
|
|
|
|
{
|
|
|
|
var randomFile = FlxG.random.getObject(cartoonList);
|
|
|
|
|
2024-03-24 04:53:05 -04:00
|
|
|
// Strip folder prefix
|
2023-08-31 01:56:35 -04:00
|
|
|
randomFile = randomFile.replace("assets/sounds/", "");
|
2024-03-24 04:53:05 -04:00
|
|
|
// Strip file extension
|
2023-08-31 01:56:35 -04:00
|
|
|
randomFile = randomFile.substring(0, randomFile.length - 4);
|
|
|
|
|
|
|
|
return randomFile;
|
2023-08-29 03:11:40 -04:00
|
|
|
}
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
public function confirm():Void
|
|
|
|
{
|
|
|
|
currentState = Confirm;
|
|
|
|
}
|
|
|
|
|
|
|
|
public inline function addOffset(name:String, x:Float = 0, y:Float = 0)
|
|
|
|
{
|
|
|
|
animOffsets[name] = [x, y];
|
|
|
|
}
|
|
|
|
|
2023-08-28 22:01:25 -04:00
|
|
|
override public function getCurrentAnimation():String
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-08-28 22:01:25 -04:00
|
|
|
if (this.anim == null || this.anim.curSymbol == null) return "";
|
|
|
|
return this.anim.curSymbol.name;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-08-28 22:01:25 -04:00
|
|
|
public function playFlashAnimation(id:String, ?Force:Bool = false, ?Reverse:Bool = false, ?Frame:Int = 0):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-08-28 22:01:25 -04:00
|
|
|
anim.play(id, Force, Reverse, Frame);
|
2023-01-22 19:55:30 -05:00
|
|
|
applyAnimOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
function applyAnimOffset()
|
|
|
|
{
|
|
|
|
var AnimName = getCurrentAnimation();
|
|
|
|
var daOffset = animOffsets.get(AnimName);
|
|
|
|
if (animOffsets.exists(AnimName))
|
|
|
|
{
|
2024-03-24 04:53:05 -04:00
|
|
|
var xValue = daOffset[0];
|
|
|
|
var yValue = daOffset[1];
|
|
|
|
if (AnimName == "Boyfriend DJ watchin tv OG")
|
|
|
|
{
|
|
|
|
xValue += offsetX;
|
|
|
|
yValue += offsetY;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset.set(xValue, yValue);
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
else
|
2024-03-24 04:53:05 -04:00
|
|
|
{
|
2023-01-22 19:55:30 -05:00
|
|
|
offset.set(0, 0);
|
2024-03-24 04:53:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function destroy():Void
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
|
|
|
|
if (cartoonSnd != null)
|
|
|
|
{
|
|
|
|
cartoonSnd.destroy();
|
|
|
|
cartoonSnd = null;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
2022-11-15 02:23:44 -05:00
|
|
|
}
|
2021-10-21 15:05:32 -04:00
|
|
|
|
2022-11-15 02:23:44 -05:00
|
|
|
enum DJBoyfriendState
|
|
|
|
{
|
2023-01-22 19:55:30 -05:00
|
|
|
Intro;
|
|
|
|
Idle;
|
|
|
|
Confirm;
|
|
|
|
Spook;
|
2023-08-28 22:47:18 -04:00
|
|
|
TV;
|
2021-10-21 15:05:32 -04:00
|
|
|
}
|