Skip to content

Commit

Permalink
Next piece preview, fast drop via space, updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpenaranda committed Apr 12, 2012
1 parent 1c98c9b commit f05985f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
./bin
bin/*
.settings
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Kokgee -- A flexible Tetris clone
=================================

Version 0.01 alpha
11 April 2012

(c) 2012 Nick Penaranda

[email protected]
[email protected]

See LICENSE.TXT for license information.

1. Description
--------------

Kokgee (Pronounced KOH-ghee) is a Tetris clone designed to be flexible and amenable to research. It is designed to be compliant with the original Tetris specifications, but adds some enhancements such as CW rotation, "speeded drop" and next piece preview. Scoring is simplified and only accounts for completed lines.

2. Features/Specs
-----------------

* Built with Java and uses LWJGL/Slick
* Complies with original Tetris specifications
* Sounds

3. Controls
-----------

* Left/Right Arrow Move left/right
* Down Arrow Speeded descent
* Spacebar Instant ("Hard") drop
* (DEV) F1/F2 Increase/decrease level
* Escape Exit game
59 changes: 47 additions & 12 deletions src/com/nickpenaranda/kokgee/KokgeeGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private enum Movement {
private static ArrayList<Shape> mShapes;

private Piece mPiece;
private Shape mNextShape;
private int mBoard[][];

private Stack<Integer> mRowsToKill;
Expand Down Expand Up @@ -167,7 +168,8 @@ public void init(GameContainer arg0) throws SlickException {
// @TODO Do the right thing!!!
}

spawnRandom();
genRandom();
spawnNext();
}

@Override
Expand All @@ -178,6 +180,8 @@ public void render(GameContainer c, Graphics g) throws SlickException {
int bx = (c.getWidth() / 2) - (PIECE_SIZE * BOARD_WIDTH / 2);
int by = (PIECE_SIZE * BOARD_HEIGHT) + BOARD_PADDING_V;

int prex = (c.getWidth() / 2) + (PIECE_SIZE * BOARD_WIDTH / 2) + PIECE_SIZE;
int prey = BOARD_PADDING_V + (PIECE_SIZE * 4) + PIECE_SIZE;
/*
* Render text information
*/
Expand Down Expand Up @@ -206,6 +210,20 @@ public void render(GameContainer c, Graphics g) throws SlickException {
g.drawRect(bx + (x * PIECE_SIZE), by - (y * PIECE_SIZE), PIECE_SIZE, PIECE_SIZE);
}

/*
* Render next piece
*/
g.drawString("Next piece", prex, prey - (PIECE_SIZE * 4));

for(int k : mNextShape.getParts(0)) {
int px = (k - 1) % 4;
int py = (k - 1) / 4;
g.setColor(mColors[mNextShape.getColor()]);
g.fillRect(prex + (px * PIECE_SIZE), prey - (py * PIECE_SIZE), PIECE_SIZE, PIECE_SIZE);
g.setColor(Color.white);
g.drawRect(prex + (px * PIECE_SIZE), prey - (py * PIECE_SIZE), PIECE_SIZE, PIECE_SIZE);
}

/*
* Render active piece
*/
Expand Down Expand Up @@ -301,6 +319,9 @@ public void keyPressed(int key, char c) {
bForcePhysics = true;
bBoost = true;
break;
case Input.KEY_SPACE:
doDrop();
break;
case Input.KEY_F:
doRotateCW();
break;
Expand Down Expand Up @@ -352,15 +373,24 @@ public static void main(String[] args) {
}
}


/*
* Creates a new piece at the prescribed position and orientation
*/
private void spawnRandom() {
int numShapes = mShapes.size();
int shapeIndex = R.nextInt(numShapes);
mPiece = new Piece(mShapes.get(shapeIndex),
private void spawnNext() {
mPiece = new Piece(mNextShape,
0,
3,BOARD_HEIGHT - 2); // places position 11 at (6,20)
genRandom();
}

/*
* Selects a next piece
*/
private void genRandom() {
int numShapes = mShapes.size();
int shapeIndex = R.nextInt(numShapes);
mNextShape = mShapes.get(shapeIndex);
}

/*
Expand Down Expand Up @@ -472,12 +502,23 @@ private boolean pieceCollides(int ox,int oy, int[] parts) {
*/
private void doPhysics() {
if(mPiece == null)
spawnRandom();
spawnNext();

if(pieceCollides(mPiece.getX(),mPiece.getY() - 1,mPiece.getParts())) haltPiece();
else mPiece.moveDown();
}

/*
* Drops the piece directly down and sets it
*/
private void doDrop() {
if(mPiece != null) {
while(!pieceCollides(mPiece.getX(),mPiece.getY() - 1,mPiece.getParts()))
mPiece.moveDown();
haltPiece();
}
}

/*
* doMoveLeft/doMoveRight are called when movement is LEFT or RIGHT, respectively.
* bound and piece collision checking are performed to deny movement
Expand All @@ -502,19 +543,13 @@ private void doMoveRight() {
*/
private void doRotateCW() {
if(mPiece != null) {
// int dLowestRow = mPiece.peekCWLR() - mPiece.getLowestRow();
// if(!pieceCollides(mPiece.getX(),mPiece.getY() - dLowestRow,mPiece.peekCW()))
// mPiece.rotateCW();
if(!pieceCollides(mPiece.getX(),mPiece.getY(),mPiece.peekCW()))
mPiece.rotateCW();
}
}

private void doRotateCCW() {
if(mPiece != null) {
// int dLowestRow = mPiece.peekCCWLR() - mPiece.getLowestRow();
// if(!pieceCollides(mPiece.getX(),mPiece.getY() - dLowestRow,mPiece.peekCCW()))
// mPiece.rotateCCW();
if(!pieceCollides(mPiece.getX(),mPiece.getY(),mPiece.peekCW()))
mPiece.rotateCCW();
}
Expand Down

0 comments on commit f05985f

Please sign in to comment.