Greetings, I am making a Breakout/Arkanoid game. I made a method that makes a brick wall.
MyWorld:
...
I set color of a brick in its constructor, but the color doesn't change at all. Can someone please help me?
Brick:
private Color[] colors = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.PINK };
private void makeWall() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 5; j++) { int color = Greenfoot.getRandomNumber(colors.length); Brick brick = new Brick(colors[color]); int width = brick.getImage().getWidth(); int height = brick.getImage().getHeight(); addObject(brick, width * (i + 1) - width / 2, height * (j + 1) - height / 2); } } }
public Brick(Color color) { getImage().scale(100, 50); getImage().fillRect(0, 100, 0, 50); getImage().setColor(color); }