diff --git a/src/ru/nsu/ccfit/zuev/osu/game/ScoreBar.java b/src/ru/nsu/ccfit/zuev/osu/game/ScoreBar.java index 3c50dabb0..130870f81 100644 --- a/src/ru/nsu/ccfit/zuev/osu/game/ScoreBar.java +++ b/src/ru/nsu/ccfit/zuev/osu/game/ScoreBar.java @@ -19,6 +19,7 @@ public class ScoreBar extends GameObject { private final AnimSprite ki; private final float width; private float lasthp = 0; + private final float mColourX = Utils.toRes(5); public ScoreBar(final GameObjectListener listener, final Scene scene, final StatisticV2 stat) { @@ -26,25 +27,21 @@ public ScoreBar(final GameObjectListener listener, final Scene scene, bg = new Sprite(0, 0, ResourceManager.getInstance().getTexture( "scorebar-bg")); bg.setScaleCenter(0, 0); - /*final int colourFrames = SkinManager.getFrames("scorebar-colour"); - colour = new AnimSprite(Utils.toRes(5), Utils.toRes(16), - "scorebar-colour-", colourFrames, colourFrames);*/ + if (ResourceManager.getInstance().isTextureLoaded("scorebar-colour-0")) { List loadedScoreBarTextures = new ArrayList<>(); for (int i = 0; i < 60; i++) { if (ResourceManager.getInstance().isTextureLoaded("scorebar-colour-" + i)) loadedScoreBarTextures.add("scorebar-colour-" + i); } - colour = new AnimSprite(Utils.toRes(5), Utils.toRes(16), loadedScoreBarTextures.size(), + + colour = new AnimSprite(mColourX, Utils.toRes(16), loadedScoreBarTextures.size(), loadedScoreBarTextures.toArray(new String[loadedScoreBarTextures.size()])); } else { - colour = new Sprite(Utils.toRes(5), Utils.toRes(16), + colour = new Sprite(mColourX, Utils.toRes(16), ResourceManager.getInstance().getTexture("scorebar-colour")); } width = colour.getWidth(); - /*for (int i = 0; i < colour.getTextureRegionCount(); i++) { - colour.setTextureRegion(i, colour.getTextureRegionAt(i).deepCopy()); - }*/ ki = ResourceManager.getInstance().isTextureLoaded("scorebar-kidanger") ? new AnimSprite(0, 0, 0, "scorebar-ki", "scorebar-kidanger", "scorebar-kidanger2") : new AnimSprite(0, 0, 0, "scorebar-ki"); @@ -70,27 +67,32 @@ public void update(final float dt) { hp = speed * dt * Math.signum(hp - lasthp) + lasthp; } - /*for (int i = 0; i < colour.getTextureRegionCount(); i++) { - colour.getTextureRegionAt(i).setWidth((int) (width * hp)); - }*/ - colour.setWidth(width * hp); + float translationX = width * (1 - Math.abs(hp)); - ki.setPosition(Utils.toRes(5) + colour.getWidth() - ki.getWidth() / 2, + colour.setPosition(mColourX - translationX, colour.getY()); + + if (colour.getClass() == Sprite.class) + { + colour.getTextureRegion().setTexturePosition((int) -translationX, 0); + } + else if (colour.getClass() == AnimSprite.class) + { + AnimSprite sprite = (AnimSprite) colour; + + int i = sprite.getTextureRegionCount() - 1; + while (i >= 0) + { + sprite.getTextureRegionAt(i).setTexturePosition((int) -translationX, 0); + --i; + } + } + + ki.setPosition(Utils.toRes(5) + colour.getX() + width - ki.getWidth() / 2, Utils.toRes(16) + colour.getHeight() / 2 - ki.getHeight() / 2); - //ki.setScale(hp>lasthp?1.2f:1); ki.setFrame(hp > 0.49 ? 0 : hp > 0.24 ? 1 : 2); lasthp = hp; - /*if (hp < 0.5f) { - if (hp < 0.25f) { - ki.setFrame(2); - } else { - ki.setFrame(1); - } - } else { - ki.setFrame(0); - }*/ } public void flush() {