// from wackadot // from handleCollisions if (dot.intersects(blueDot)) { repositionRandomly(blueDot); if (dot.getColor().equals(Color.BLUE)) { dot.setColor(Color.RED); score++; } else { score--; } updateString(scoreSprite, "Score: ", score); } if (dot.intersects(redDot)) { repositionRandomly(redDot); if (dot.getColor().equals(Color.RED)) { dot.setColor(Color.BLUE); score++; } else { score--; } updateString(scoreSprite, "Score: ", score); } => private void checkCollision (Sprite badDot, Color old, Color new) { if (dot.intersects(badDot)) { repositionRandomly(badDot); if (dot.getColor().equals(old)) { dot.setColor(new); score++; } else { score--; } updateString(scoreSprite, "Score: ", score); } } checkCollision(blueDot, Color.BLUE, Color.RED); checkCollision(redDot, Color.RED, Color.BLUE); ==================================================================== // from breakout // from handleCollisions if (ball.intersects(walls[2])) { if (lives == 0) { endMessage.setText("You Lose!"); canvas.addSprite(endMessage); gameOver = true; } else { lives --; // rest not shown ... } } else if (score == 40) { endMessage.setText("You Win"); canvas.addSprite(endMessage); gameOver = true; } => private void endGame (String message) { endMessage.setText(message); canvas.addSprite(endMessage); gameOver = true; } if (ball.intersects(walls[2])) { if (lives == 0) { endGame("You Lose!"); } else { lives --; // rest not shown ... } } else if (score == 40) { endGame("You Win"); } ==================================================================== // from breakout // from handleCollisions if (blocks[k].getColor().equals(Color.LIGHT_GRAY)) { score = score + 5; } else if (blocks[k].getColor().equals(Color.GRAY)) { score = score + 10; } else if (blocks[k].getColor().equals(Color.DARK_GRAY)) { score = score + 15; } if (blocks[k].getColor().equals(Color.BLACK)) { score = score + 20; } ==================================================================== // from breakout // from handleCollisions for (int k = 0; k < 9; k++) { for (int j = 0; j < 3; j++) { if (blocks[k][j].isVisible() && blocks[k][j].intersects(ball1)) { ballTracker1.bounce(ball1, blocks[k][j]); if (blocks[k][j].getColor() == Color.WHITE) blocks[k][j].setVisible(false); else blocks[k][j].setColor(Color.WHITE); score++; blocksleft--; } if (blocks[k][j].isVisible() && blocks[k][j].intersects(ball2)) { ballTracker2.bounce(ball2, blocks[k][j]); if (blocks[k][j].getColor() == Color.WHITE) blocks[k][j].setVisible(false); else blocks[k][j].setColor(Color.WHITE); score++; blocksleft--; } } } ==================================================================== // from breakout // from initSprites for (int i = 0; i < NUM_BLOCKS; i++) { blocks1[i].setColor(new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)); blocks1[i].setScale(canvas.getWidth() * 0.1); blocks1[i].setLocation(canvas.getWidth() * 0.1 + 44 * i, canvas.getHeight() * 0.25); blocks2[i].setColor(new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)); blocks2[i].setScale(canvas.getWidth() * 0.1); blocks2[i].setLocation(canvas.getWidth() * 0.1 + 44 * i, canvas.getHeight() * 0.3); blocks3[i].setColor(new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)); blocks3[i].setScale(canvas.getWidth() * 0.1); blocks3[i].setLocation(canvas.getWidth() * 0.1 + 44 * i, canvas.getHeight() * 0.35); } ==================================================================== // from breakout public void advanceFrame () { handleInput(); if (level == 1) handleCollisions1(); else if (level == 2) handleCollisions2(); else if (level == 3) handleCollisions3(); updateStatus(); } // awesome, but can we make it better? // - level data class // - okay, but no methods // - level class // - okay, but no access to canvas, random, etc.