# HG changeset patch # User Matti Hamalainen # Date 1296258868 -7200 # Node ID 4bacc98973f568562e2972f9280a09947eaaefd9 # Parent a7751971c2a3612fce8afea6faa8edcb015f7b68 More work. diff -r a7751971c2a3 -r 4bacc98973f5 game/Engine.java --- a/game/Engine.java Sat Jan 29 00:30:00 2011 +0200 +++ b/game/Engine.java Sat Jan 29 01:54:28 2011 +0200 @@ -80,6 +80,8 @@ Piece current; public boolean flagGameOver; + + int moveX, moveY, movePoint; public GameBoard() @@ -122,6 +124,7 @@ { board[x][y].animate(time); } + } private boolean isEmpty(int x, int y) @@ -227,6 +230,7 @@ lauta = new GameBoard(); addKeyListener(this); + } public void startThreads() @@ -254,10 +258,12 @@ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; - + + // Use antialiasing when rendering the game elements g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + // Rescale background if component size has changed Dimension dim = getSize(); if (oldDim == null || !dim.equals(oldDim)) { @@ -265,17 +271,24 @@ Graphics2D gimg = lautaBGScaled.createGraphics(); gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - AffineTransform xform = AffineTransform.getScaleInstance(0.5f, 0.5f); - gimg.drawImage(lautaBG, xform, null); + + gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null); oldDim = dim; System.out.print("scale changed\n"); } + // Background, pieces g2.drawImage(lautaBGScaled, 0, 0, null); lauta.paint(g2, 100, 150, 60); + // Other elements + + // Request focus to keep keyboard input coming if (!hasFocus()) + { + System.out.print(".\n"); requestFocus(); + } } public void keyTyped(KeyEvent e) @@ -317,7 +330,8 @@ lauta.animate(clock); - repaint(); + if (clock % 2 == 1) + repaint(); try { Thread.sleep(10); diff -r a7751971c2a3 -r 4bacc98973f5 game/Piece.java --- a/game/Piece.java Sat Jan 29 00:30:00 2011 +0200 +++ b/game/Piece.java Sat Jan 29 01:54:28 2011 +0200 @@ -92,8 +92,8 @@ currRotation = currRotation + (dir ? -1 : 1); newAngle = (float) (currRotation * Math.PI) / 2.0f; + lerpRotation = new Interpolate(currAngle, newAngle, maxTime); rotationChanged = true; - lerpRotation = new Interpolate(currAngle, newAngle, maxTime); } public Point2D getPointCoords(float x, float y, float dim, int index) @@ -158,7 +158,6 @@ if (activeChanged) { - } throb = (time % 100) / 100.0f; @@ -170,9 +169,6 @@ tf.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); g.transform(tf); - if (type == PieceType.ACTIVE) - System.out.print("angle = " + currAngle + "\n"); - switch (type) { case LOCKED: g.setPaint(Color.green); break; case ACTIVE: g.setPaint(Color.red); break;