2020-12-24 18:24:11 -05:00
|
|
|
package;
|
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2021-09-02 17:07:32 -04:00
|
|
|
import openfl.utils.Assets;
|
2020-12-24 18:24:11 -05:00
|
|
|
|
2021-03-18 21:08:44 -04:00
|
|
|
using StringTools;
|
|
|
|
|
2020-12-24 18:24:11 -05:00
|
|
|
class HealthIcon extends FlxSprite
|
|
|
|
{
|
2021-03-01 18:59:51 -05:00
|
|
|
/**
|
|
|
|
* Used for FreeplayState! If you use it elsewhere, prob gonna annoying
|
|
|
|
*/
|
|
|
|
public var sprTracker:FlxSprite;
|
|
|
|
|
2021-03-20 12:33:29 -04:00
|
|
|
var char:String = '';
|
2021-03-18 21:08:44 -04:00
|
|
|
var isPlayer:Bool = false;
|
|
|
|
|
2020-12-24 18:24:11 -05:00
|
|
|
public function new(char:String = 'bf', isPlayer:Bool = false)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2021-03-18 21:08:44 -04:00
|
|
|
this.isPlayer = isPlayer;
|
|
|
|
|
2020-12-24 18:24:11 -05:00
|
|
|
antialiasing = true;
|
2021-06-22 20:32:37 -04:00
|
|
|
changeIcon(char);
|
2020-12-24 18:24:11 -05:00
|
|
|
scrollFactor.set();
|
|
|
|
}
|
2021-03-01 18:59:51 -05:00
|
|
|
|
2021-03-18 21:08:44 -04:00
|
|
|
public var isOldIcon:Bool = false;
|
|
|
|
|
|
|
|
public function swapOldIcon():Void
|
|
|
|
{
|
|
|
|
isOldIcon = !isOldIcon;
|
|
|
|
|
|
|
|
if (isOldIcon)
|
2021-03-20 12:33:29 -04:00
|
|
|
changeIcon('bf-old');
|
2021-03-18 21:08:44 -04:00
|
|
|
else
|
2021-04-19 12:19:40 -04:00
|
|
|
changeIcon(PlayState.SONG.player1);
|
2021-03-18 21:08:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-22 21:11:06 -04:00
|
|
|
var pixelArrayFunny:Array<String> = CoolUtil.coolTextFile(Paths.file('images/icons/pixelIcons.txt'));
|
|
|
|
|
2021-03-20 12:33:29 -04:00
|
|
|
public function changeIcon(newChar:String):Void
|
2021-03-18 21:08:44 -04:00
|
|
|
{
|
2021-03-20 12:33:29 -04:00
|
|
|
if (newChar != 'bf-pixel' && newChar != 'bf-old')
|
|
|
|
newChar = newChar.split('-')[0].trim();
|
|
|
|
|
2021-09-02 17:07:32 -04:00
|
|
|
if (!Assets.exists(Paths.image('icons/icon-' + newChar)))
|
|
|
|
{
|
|
|
|
FlxG.log.warn('No icon with data: $newChar : using default placeholder face instead!');
|
|
|
|
newChar = "face";
|
|
|
|
}
|
|
|
|
|
2021-03-20 12:33:29 -04:00
|
|
|
if (newChar != char)
|
2021-03-19 00:03:29 -04:00
|
|
|
{
|
2021-03-20 12:33:29 -04:00
|
|
|
if (animation.getByName(newChar) == null)
|
|
|
|
{
|
2021-06-22 20:18:22 -04:00
|
|
|
var imgSize:Int = 150;
|
|
|
|
|
2021-06-22 21:11:06 -04:00
|
|
|
if (newChar.endsWith('pixel') || pixelArrayFunny.contains(newChar))
|
2021-06-22 20:18:22 -04:00
|
|
|
imgSize = 32;
|
|
|
|
|
|
|
|
loadGraphic(Paths.image('icons/icon-' + newChar), true, imgSize, imgSize);
|
|
|
|
|
2021-03-20 12:33:29 -04:00
|
|
|
animation.add(newChar, [0, 1], 0, false, isPlayer);
|
|
|
|
}
|
|
|
|
animation.play(newChar);
|
|
|
|
char = newChar;
|
2021-06-22 20:18:22 -04:00
|
|
|
|
2021-06-22 21:11:06 -04:00
|
|
|
if (newChar.endsWith('pixel') || pixelArrayFunny.contains(newChar))
|
2021-06-22 20:21:54 -04:00
|
|
|
antialiasing = false;
|
2021-07-15 22:30:19 -04:00
|
|
|
else
|
|
|
|
antialiasing = true;
|
|
|
|
setGraphicSize(150);
|
|
|
|
updateHitbox();
|
2021-03-19 00:03:29 -04:00
|
|
|
}
|
2021-03-18 21:08:44 -04:00
|
|
|
}
|
|
|
|
|
2021-03-01 18:59:51 -05:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
|
|
|
if (sprTracker != null)
|
|
|
|
setPosition(sprTracker.x + sprTracker.width + 10, sprTracker.y - 30);
|
|
|
|
}
|
2020-12-24 18:24:11 -05:00
|
|
|
}
|