diff --git a/.gitignore b/.gitignore index 0354010..10feca0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -./bin +bin/* +.settings diff --git a/README.md b/README.md index e69de29..2450517 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,33 @@ +Kokgee -- A flexible Tetris clone +================================= + +Version 0.01 alpha +11 April 2012 + +(c) 2012 Nick Penaranda + +nick4p@gmail.com +bpenaran@gmu.edu + +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 diff --git a/src/com/nickpenaranda/kokgee/KokgeeGame.java b/src/com/nickpenaranda/kokgee/KokgeeGame.java index 7bb6aa8..a61a344 100644 --- a/src/com/nickpenaranda/kokgee/KokgeeGame.java +++ b/src/com/nickpenaranda/kokgee/KokgeeGame.java @@ -70,6 +70,7 @@ private enum Movement { private static ArrayList mShapes; private Piece mPiece; + private Shape mNextShape; private int mBoard[][]; private Stack mRowsToKill; @@ -167,7 +168,8 @@ public void init(GameContainer arg0) throws SlickException { // @TODO Do the right thing!!! } - spawnRandom(); + genRandom(); + spawnNext(); } @Override @@ -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 */ @@ -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 */ @@ -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; @@ -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); } /* @@ -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 @@ -502,9 +543,6 @@ 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(); } @@ -512,9 +550,6 @@ private void doRotateCW() { 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(); }