Skip to content

Commit

Permalink
Support showing optimal number of steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteHamster committed Jul 21, 2024
1 parent 17eb25f commit fcb8e9b
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ public class Level {
private int number;
private int indexInPack;
private LevelPack pack;
private int optimalSteps;

public Level(int indexInPack, int number, LevelPack pack, String color, String modifier) {
public Level(int indexInPack, int number, LevelPack pack, String color, String modifier, int optimalSteps) {
this.number = number;
this.indexInPack = indexInPack;
this.pack = pack;
this.optimalSteps = optimalSteps;

color = color.replaceAll("\\s", "");
modifier = modifier.replaceAll("\\s", "");
Expand Down Expand Up @@ -74,4 +76,8 @@ public int getIndexInPack() {
public LevelPack getPack() {
return pack;
}

public int getOptimalSteps() {
return optimalSteps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ private LevelPack(int id, String fileName, Context context) {
int number = Integer.parseInt(levelEl.getAttribute("number"));
String colors = levelEl.getAttribute("color");
String modifiers = levelEl.getAttribute("modifier");
int optimalSteps = 0;
if (levelEl.hasAttribute("solution")) {
String solution = levelEl.getAttribute("solution");
optimalSteps = solution.split(",").length;
}

levels.add(new Level(indexInPack, number, this, colors, modifiers));
levels.add(new Level(indexInPack, number, this, colors, modifiers, optimalSteps));
indexInPack++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class LevelList extends Drawable {
private final Plane planeLevel;
private final Plane planeLevelDone;
private final Plane planeLevelPerfect;
private final Plane planeLevelLocked;
private final Number number;
private final float boxHeight;
Expand All @@ -25,9 +26,11 @@ public LevelList(float boxSize, State context) {

TextureCoordinates coordinatesLevel = TextureCoordinates.getFromBlocks(6, 0, 7, 1);
TextureCoordinates coordinatesLevelDone = TextureCoordinates.getFromBlocks(7, 0, 8, 1);
TextureCoordinates coordinatesLevelLocked = TextureCoordinates.getFromBlocks(6, 3, 7, 4);
TextureCoordinates coordinatesLevelPerfect = TextureCoordinates.getFromBlocks(6, 1, 7, 2);
TextureCoordinates coordinatesLevelLocked = TextureCoordinates.getFromBlocks(7, 1, 8, 2);
planeLevel = new Plane(0, 0, boxSize, boxSize, coordinatesLevel);
planeLevelDone = new Plane(0, 0, boxSize, boxSize, coordinatesLevelDone);
planeLevelPerfect = new Plane(0, 0, boxSize, boxSize, coordinatesLevelPerfect);
planeLevelLocked = new Plane(0, 0, boxSize, boxSize, coordinatesLevelLocked);
number = new Number();
number.setFontSize(boxSize / 3);
Expand Down Expand Up @@ -55,7 +58,11 @@ private float getYFor(int num) {
private void drawButton(int indexInPack, Level level, GL10 gl) {
Plane draw;
if (context.isSolved(level.getNumber())) {
draw = planeLevelDone;
if (level.getOptimalSteps() != 0 && context.loadSteps(level.getNumber()) <= level.getOptimalSteps()) {
draw = planeLevelPerfect;
} else {
draw = planeLevelDone;
}
} else if (!context.isPlayable(level)) {
draw = planeLevelLocked;
} else {
Expand Down
42 changes: 30 additions & 12 deletions app/src/main/java/com/bytehamster/flowitgame/state/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.bytehamster.flowitgame.R;
import com.bytehamster.flowitgame.animation.Animation;
import com.bytehamster.flowitgame.animation.AnimationFactory;
import com.bytehamster.flowitgame.animation.AnimationRepeated;
import com.bytehamster.flowitgame.animation.ScaleAnimation;
import com.bytehamster.flowitgame.animation.TranslateAnimation;
import com.bytehamster.flowitgame.filler.Filler;
Expand Down Expand Up @@ -41,6 +40,7 @@ public class GameState extends State {
private Plane headerBackground;
private Number stepsUsed;
private Number stepsBest;
private Number stepsOptimal;
private boolean isFilling = false;
private boolean won = false;
private float topBarHeight;
Expand All @@ -49,6 +49,7 @@ public class GameState extends State {
private float topBarPadding;
private float stepsUsedCurrentYDelta;
private float stepsUsedBestYDelta;
private float stepsOptimalYDelta;
private LastLevelState lastLevelState = LastLevelState.NO_LEVEL;
private Filler filler;

Expand All @@ -75,6 +76,7 @@ protected void initialize(GLRenderer glRenderer) {
topButtonY = glRenderer.getHeight() - topButtonSize - topBarPadding;
stepsUsedCurrentYDelta = topButtonSize * 0.6f;
stepsUsedBestYDelta = topButtonSize * 0.1f;
stepsOptimalYDelta = topButtonSize * -0.4f;

TextureCoordinates coordinatesHeader = TextureCoordinates.getFromBlocks(14, 12, 15, 13);
headerBackground = new Plane(0, glRenderer.getHeight(), glRenderer.getWidth(), topBarHeight, coordinatesHeader);
Expand Down Expand Up @@ -109,19 +111,25 @@ protected void initialize(GLRenderer glRenderer) {
stepsUsed = new Number();
stepsUsed.setFontSize(topButtonSize * 0.35f);
stepsUsed.setX(5 * topButtonSize + 3 * topBarPadding);
stepsUsed.setY(glRenderer.getHeight() + topBarPadding + stepsUsedCurrentYDelta);
stepsUsed.setY(glRenderer.getHeight() + topBarPadding + stepsUsedCurrentYDelta + 0.25f * topButtonSize);
glRenderer.addDrawable(stepsUsed);

stepsBest = new Number();
stepsBest.setFontSize(topButtonSize * 0.35f);
stepsBest.setX(5 * topButtonSize + 3 * topBarPadding);
stepsBest.setY(glRenderer.getHeight() + topBarPadding + stepsUsedBestYDelta);
stepsBest.setY(glRenderer.getHeight() + topBarPadding + stepsUsedBestYDelta + 0.25f * topButtonSize);
glRenderer.addDrawable(stepsBest);

TextureCoordinates coordinateSteps = TextureCoordinates.getFromBlocks(12, 10, 15, 11);
stepsLabel = new Plane(0, 0, 3 * topButtonSize, topButtonSize, coordinateSteps);
stepsOptimal = new Number();
stepsOptimal.setFontSize(topButtonSize * 0.35f);
stepsOptimal.setX(5 * topButtonSize + 3 * topBarPadding);
stepsOptimal.setY(glRenderer.getHeight() + topBarPadding + stepsOptimalYDelta + 0.25f * topButtonSize);
glRenderer.addDrawable(stepsOptimal);

TextureCoordinates coordinateSteps = TextureCoordinates.getFromBlocks(12, 10, 15, 12);
stepsLabel = new Plane(0, 0, 3 * topButtonSize, 2 * topButtonSize, coordinateSteps);
stepsLabel.setX(2 * topButtonSize + 3 * topBarPadding);
stepsLabel.setY(glRenderer.getHeight() + topBarPadding);
stepsLabel.setY(glRenderer.getHeight() + topBarPadding - 0.75f * topButtonSize);
stepsLabel.setVisible(false);
glRenderer.addDrawable(stepsLabel);

Expand Down Expand Up @@ -160,9 +168,10 @@ public void entry() {
AnimationFactory.startMoveYTo(left, topButtonY);
AnimationFactory.startMoveYTo(right, topButtonY);
AnimationFactory.startMoveYTo(restart, topButtonY);
AnimationFactory.startMoveYTo(stepsLabel, topButtonY);
AnimationFactory.startMoveYTo(stepsBest, topButtonY + stepsUsedBestYDelta);
AnimationFactory.startMoveYTo(stepsUsed, topButtonY + stepsUsedCurrentYDelta);
AnimationFactory.startMoveYTo(stepsLabel, topButtonY - 0.75f * topButtonSize);
AnimationFactory.startMoveYTo(stepsBest, topButtonY + stepsUsedBestYDelta + 0.25f * topButtonSize);
AnimationFactory.startMoveYTo(stepsUsed, topButtonY + stepsUsedCurrentYDelta + 0.25f * topButtonSize);
AnimationFactory.startMoveYTo(stepsOptimal, topButtonY + stepsOptimalYDelta + 0.25f * topButtonSize);
AnimationFactory.startMoveYTo(headerBackground, getScreenHeight() - topBarHeight);
}

Expand All @@ -174,6 +183,11 @@ private void reloadLevel() {
} else {
stepsBest.setValue(loadSteps(level.getNumber()));
}
if (level.getOptimalSteps() <= 0) {
stepsOptimal.setValue(Number.VALUE_NAN);
} else {
stepsOptimal.setValue(level.getOptimalSteps());
}
AnimationFactory.startScaleHide(stepsImproved, 0);
isFilling = false;
level.reset();
Expand Down Expand Up @@ -261,9 +275,13 @@ public void exit() {
AnimationFactory.startMoveYTo(right, getScreenHeight() + topBarPadding);
AnimationFactory.startMoveYTo(restart, getScreenHeight() + topBarPadding);
AnimationFactory.startMoveYTo(solved, getScreenHeight() + topBarPadding);
AnimationFactory.startMoveYTo(stepsLabel, getScreenHeight() + topBarPadding);
AnimationFactory.startMoveYTo(stepsBest, getScreenHeight() + topBarPadding + stepsUsedBestYDelta);
AnimationFactory.startMoveYTo(stepsUsed, getScreenHeight() + topBarPadding + stepsUsedCurrentYDelta);
AnimationFactory.startMoveYTo(stepsLabel, getScreenHeight() + topBarPadding - 0.75f * topButtonSize);
AnimationFactory.startMoveYTo(stepsBest, getScreenHeight() + topBarPadding
+ stepsUsedBestYDelta + 0.25f * topButtonSize);
AnimationFactory.startMoveYTo(stepsUsed, getScreenHeight() + topBarPadding
+ stepsUsedCurrentYDelta + 0.25f * topButtonSize);
AnimationFactory.startMoveYTo(stepsOptimal, getScreenHeight() + topBarPadding
+ stepsOptimalYDelta + 0.25f * topButtonSize);
AnimationFactory.startMoveYTo(headerBackground, getScreenHeight());
AnimationFactory.startMoveYTo(winMessage, -getScreenWidth() * 0.5f);
AnimationFactory.startScaleHide(stepsImproved, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void saveSteps(int level, int steps) {
}
}

int loadSteps(int level) {
public int loadSteps(int level) {
return playedPrefs.getInt("s"+level, STEPS_NOT_SOLVED);
}

Expand Down
Binary file modified app/src/main/res/drawable-de-nodpi/texture_colorscheme_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-de-nodpi/texture_colorscheme_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-fr-nodpi/texture_colorscheme_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-fr-nodpi/texture_colorscheme_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-it-nodpi/texture_colorscheme_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-it-nodpi/texture_colorscheme_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-nodpi/texture_colorscheme_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-nodpi/texture_colorscheme_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/texture.xcf
Binary file not shown.

0 comments on commit fcb8e9b

Please sign in to comment.