Brick.java

/**
* Copyright (c) 2012-2013 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners. 
* See LICENSE.TXT for license information.
*/

package com.nokia.example.explonoid.game;

import javax.microedition.lcdui.game.Sprite;

/**
 * Represents a brick element that is supposed to be hit with the ball.
 */
public class Brick
        extends Sprite {

    public static final int ROWS = 5;
    public static final int COLS = 2;
    public static final int PADDING_V = 6;
    public static final int PADDING_H = 5;

    public Brick(int brick, Resources r) {
        super(r.bricks, r.bricks.getWidth() / COLS, r.bricks.getHeight() / ROWS);
        defineCollisionRectangle(r.scale(PADDING_H), r.scale(PADDING_V),
                                 (int) (r.bricks.getWidth() / COLS - r.scale(PADDING_H)),
                                 (int) (r.bricks.getHeight() / ROWS - r.scale(PADDING_V)));
        defineReferencePixel((int) (getWidth() * 0.5 + 0.5), (int) (getHeight() * 0.5 + 0.5));
        setFrame(brick);
    }
}