From fdd8e0445e5c6ac836a67b224c47a89b88ef0959 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Thu, 18 Mar 2021 21:08:44 -0400 Subject: [PATCH] icon code redo for more modularity --- source/HealthIcon.hx | 56 ++++++++++++++++++++++++++------------------ source/PlayState.hx | 7 +----- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/source/HealthIcon.hx b/source/HealthIcon.hx index 9224904f1..53f404f98 100644 --- a/source/HealthIcon.hx +++ b/source/HealthIcon.hx @@ -2,6 +2,8 @@ package; import flixel.FlxSprite; +using StringTools; + class HealthIcon extends FlxSprite { /** @@ -9,37 +11,45 @@ class HealthIcon extends FlxSprite */ public var sprTracker:FlxSprite; + var char:String = 'bf'; + var isPlayer:Bool = false; + public function new(char:String = 'bf', isPlayer:Bool = false) { super(); - loadGraphic(Paths.image('iconGrid'), true, 150, 150); + this.isPlayer = isPlayer; + this.char = char; + + loadIcon(char); antialiasing = true; - animation.add('bf', [0, 1], 0, false, isPlayer); - animation.add('bf-holding-gf', [0, 1], 0, false, isPlayer); - animation.add('bf-car', [0, 1], 0, false, isPlayer); - animation.add('bf-christmas', [0, 1], 0, false, isPlayer); - animation.add('bf-pixel', [21, 21], 0, false, isPlayer); - animation.add('spooky', [2, 3], 0, false, isPlayer); - animation.add('pico', [4, 5], 0, false, isPlayer); - animation.add('pico-speaker', [4, 5], 0, false, isPlayer); - animation.add('mom', [6, 7], 0, false, isPlayer); - animation.add('mom-car', [6, 7], 0, false, isPlayer); - animation.add('tankman', [8, 9], 0, false, isPlayer); - animation.add('face', [10, 11], 0, false, isPlayer); - animation.add('dad', [12, 13], 0, false, isPlayer); - animation.add('senpai', [22, 22], 0, false, isPlayer); - animation.add('senpai-angry', [22, 22], 0, false, isPlayer); - animation.add('spirit', [23, 23], 0, false, isPlayer); - animation.add('bf-old', [14, 15], 0, false, isPlayer); - animation.add('gf', [16], 0, false, isPlayer); - animation.add('parents-christmas', [17], 0, false, isPlayer); - animation.add('monster', [19, 20], 0, false, isPlayer); - animation.add('monster-christmas', [19, 20], 0, false, isPlayer); - animation.play(char); scrollFactor.set(); } + public var isOldIcon:Bool = false; + + public function swapOldIcon():Void + { + isOldIcon = !isOldIcon; + + if (isOldIcon) + { + loadGraphic(Paths.image('icons/icon-bf-old'), true, 150, 150); + animation.add('bf-old', [0, 1], 0, false, isPlayer); + animation.play('bf-old'); + } + else + loadIcon(char); + } + + function loadIcon(char:String):Void + { + var realChar:String = char.split('-')[0].trim(); + loadGraphic(Paths.image('icons/icon-' + realChar), true, 150, 150); + animation.add(realChar, [0, 1], 0, false, isPlayer); + animation.play(realChar); + } + override function update(elapsed:Float) { super.update(elapsed); diff --git a/source/PlayState.hx b/source/PlayState.hx index fa7a6244e..971b1f651 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1389,12 +1389,7 @@ class PlayState extends MusicBeatState #end if (FlxG.keys.justPressed.NINE) - { - if (iconP1.animation.curAnim.name == 'bf-old') - iconP1.animation.play(SONG.player1); - else - iconP1.animation.play('bf-old'); - } + iconP1.swapOldIcon(); // do this BEFORE super.update() so songPosition is accurate if (startingSong)