Shrink picked pieces

This commit is contained in:
Lonami Exo 2017-01-25 19:45:19 +01:00
parent 5fd653feb2
commit c0fdc5ece8
4 changed files with 10 additions and 8 deletions

View file

@ -9,13 +9,13 @@ public class Board {
Cell[][] cells;
private final int count; // Cell count
private final int size; // Size per cell
public final int cellSize; // Size per cell
public NinePatch cellPatch;
public Board(int boardSize, int cellSize) {
count = boardSize;
size = cellSize;
this.cellSize = cellSize;
cells = new Cell[count][count];
for (int i = 0; i < count; i++) {
@ -29,7 +29,7 @@ public class Board {
}
public int getPxSize() {
return count * size;
return count * cellSize;
}
private boolean inBounds(int x, int y) {
@ -66,6 +66,6 @@ public class Board {
public void draw(SpriteBatch batch, int x, int y) {
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++)
cells[i][j].draw(batch, cellPatch, x + j * size, y + i * size, size);
cells[i][j].draw(batch, cellPatch, x + j * cellSize, y + i * cellSize, cellSize);
}
}

View file

@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
// Pieces can be L shaped and be rotated 0 to 3 times to make it random
// Maximum size = 4
// Maximum cellSize = 4
public class Piece {
private final static int[] colors = {

View file

@ -3,6 +3,7 @@ package io.github.lonamiwebs.klooni.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
public class PieceHolder {
@ -32,7 +33,7 @@ public class PieceHolder {
for (int i = 0; i < count; i++) {
pieces[i] = Piece.random();
// Set the local position and the cell size
// Set the local position and the cell cellSize
pieces[i].pos.set(pos.x + i * perPieceSize, pos.y);
pieces[i].cellSize = Math.min(
perPieceSize / pieces[i].cellCols,
@ -65,7 +66,7 @@ public class PieceHolder {
return false;
}
public void update() {
public void update(float cellSizeOnBoard) {
if (heldPiece > -1) {
Piece piece = pieces[heldPiece];
@ -77,6 +78,7 @@ public class PieceHolder {
mouse.sub(piece.getRectangle().width / 2, piece.getRectangle().height / 2);
piece.pos.lerp(mouse, 0.4f);
piece.cellSize = Interpolation.linear.apply(piece.cellSize, cellSizeOnBoard, 0.4f);
}
}

View file

@ -55,7 +55,7 @@ public class GameScreen implements Screen, InputProcessor {
Gdx.graphics.getWidth() / 2 - board.getPxSize() / 2,
Gdx.graphics.getHeight() * 3 / 4 - board.getPxSize() / 2);
holder.update();
holder.update(board.cellSize);
holder.draw(batch, board.cellPatch);
batch.end();