Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infinite mode #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added android/assets/ui/x0.75/infinite_off.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 added android/assets/ui/x0.75/infinite_on.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 added android/assets/ui/x1.0/infinite_off.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 added android/assets/ui/x1.0/infinite_on.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 added android/assets/ui/x1.25/infinite_off.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 added android/assets/ui/x1.25/infinite_on.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 added android/assets/ui/x1.5/infinite_off.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 added android/assets/ui/x1.5/infinite_on.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 added android/assets/ui/x2.0/infinite_off.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 added android/assets/ui/x2.0/infinite_on.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 added android/assets/ui/x4.0/infinite_off.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 added android/assets/ui/x4.0/infinite_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0'
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/io/github/lonamiwebs/klooni/Klooni.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ public static boolean toggleSnapToGrid() {
return result;
}

public static boolean shouldInfiniteMode() {
return prefs.getBoolean("infiniteMode", false);
}

public static boolean toggleInfiniteMode() {
final boolean result = !shouldInfiniteMode();
prefs.putBoolean("infiniteMode", result).flush();
return result;
}

// Themes related
public static boolean isThemeBought(Theme theme) {
if (theme.getPrice() == 0)
Expand Down
3 changes: 2 additions & 1 deletion core/src/io/github/lonamiwebs/klooni/SkinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class SkinLoader {
private final static String[] ids = {
"play", "play_saved", "star", "stopwatch", "palette", "home", "replay",
"share", "sound_on", "sound_off", "snap_on", "snap_off", "issues", "credits",
"web", "back", "ok", "cancel", "power_off", "effects"
"web", "back", "ok", "cancel", "power_off", "effects", "infinite_on",
"infinite_off"
};

private final static float bestMultiplier;
Expand Down
5 changes: 5 additions & 0 deletions core/src/io/github/lonamiwebs/klooni/game/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public boolean putPiece(Piece piece, int x, int y) {

//region Public methods

// Return true if the cell in given coordinates is empty
public boolean isEmpty(int x, int y) {
return cells[x][y].isEmpty();
}

public void draw(final Batch batch) {
batch.setTransformMatrix(batch.getTransformMatrix().translate(pos.x, pos.y, 0));

Expand Down
26 changes: 16 additions & 10 deletions core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PieceHolder implements BinSerializable {
//region Members

final Rectangle area;
private final Piece[] pieces;
private Piece[] pieces;

private final Sound pieceDropSound;
private final Sound invalidPieceDropSound;
Expand Down Expand Up @@ -99,6 +99,15 @@ public PieceHolder(final GameLayout layout, final Board board,

//region Private methods

// If no piece is currently being held, the area will be 0
private int calculateHeldPieceArea() {
return heldPiece > -1 ? pieces[heldPiece].calculateArea() : 0;
}

private Vector2 calculateHeldPieceCenter() {
return heldPiece > -1 ? pieces[heldPiece].calculateGravityCenter() : null;
}

// Determines whether all the pieces have been put (and the "hand" is finished)
private boolean handFinished() {
for (int i = 0; i < count; ++i)
Expand All @@ -112,6 +121,11 @@ private boolean handFinished() {
private void takeMore() {
for (int i = 0; i < count; ++i)
pieces[i] = Piece.random();

// If infinite mode is turned on, make sure all pieces always fit
if (Klooni.shouldInfiniteMode())
pieces = State.validateBlock(pieces, board);

updatePiecesStartLocation();

if (Klooni.soundsEnabled()) {
Expand Down Expand Up @@ -187,15 +201,6 @@ public Array<Piece> getAvailablePieces() {
return result;
}

// If no piece is currently being held, the area will be 0
private int calculateHeldPieceArea() {
return heldPiece > -1 ? pieces[heldPiece].calculateArea() : 0;
}

private Vector2 calculateHeldPieceCenter() {
return heldPiece > -1 ? pieces[heldPiece].calculateGravityCenter() : null;
}

// Tries to drop the piece on the given board. As a result, it
// returns one of the following: NO_DROP, NORMAL_DROP, ON_BOARD_DROP
public DropResult dropPiece() {
Expand Down Expand Up @@ -224,6 +229,7 @@ public DropResult dropPiece() {
heldPiece = -1;
if (handFinished())
takeMore();

} else
result = new DropResult(false);

Expand Down
Loading