⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ball.java~1~

📁 j2me源代码
💻 JAVA~1~
字号:
package jbricks;import javax.microedition.lcdui.Graphics;/** * * <p>Title: 弹球</p> * * <p>Description: 该类实现了弹球的显示和属性的维护,包括弹球的半径,坐标。 *                 此外,该类还实现了弹球的自绘功能。</p> * */public class Ball extends Sprite {    private int dx;    private int dy;    private int xo;    private int yo;    public static final int RADIUS = Math.max(2, Screen.width / 55);    private ThreeDColor color;    private ThreeDColor brighter;    private ThreeDColor darker;    private int counter;    private int offset;    public Ball(int x, int y, int dx, int dy) {        moveTo(x, y);        setSteps(dx, dy);        offset = 0;        width = 2 * RADIUS;        height = 2 * RADIUS;        this.dx = dx;        this.dy = dy;        xo = yo = 0;        color = ThreeDColor.red;        brighter = color.brighter();        darker = color.darker();    }    public void setSteps(int dx, int dy) {        this.dx = dx;        this.dy = dy;    }    public int getXStep() {        return dx;    }    public int getYStep() {        return dy;    }    public void move() {        x = x + dx + xo;        y = y + dy + yo;        xo = yo = 0;    }    public void bounceHorizontal() {        dx = -dx;        if (Util.getRandomInt(0, 1000) < 70) {            xo = dx < 0 ? -1 : 1;        }    }    public void bounceVertical() {        dy = -dy;        if (Util.getRandomInt(0, 1000) < 70) {            yo = dy < 0 ? -1 : 1;        }    }    public void bounce(Sprite other) {        int cx, cy;        cx = getCenterX();        cy = getCenterY();        if (dx < 0) {            if (cy >= other.y && cy < other.y + other.height                && x < other.x + other.width) {                dx = Math.abs(dx);            }        } else {            if (cy >= other.y && cy < other.y + other.height                && x + width >= other.x) {                dx = -Math.abs(dx);            }        }        if (dy < 0) {            if (cx >= other.x && cx < other.x + other.width                && y < other.y + other.height) {                dy = Math.abs(dy);            }        } else {            if (cx >= other.x && cx < other.x + other.width                && y + height >= other.y) {                dy = -Math.abs(dy);            }        }        if (Util.getRandomInt(0, 1000) < 70) {            xo = dx < 0 ? -1 : 1;        }        if (Util.getRandomInt(0, 1000) < 70) {            yo = dy < 0 ? -1 : 1;        }    }    public void paintShadow(Graphics g) {        g.setColor(ThreeDColor.black.getRGB());        g.fillArc(x + shadow, y + shadow, width, height, 0, 360);    }    public void paint(Graphics g) {        if (++counter == 6) {            counter = 0;            offset = 1 - offset;        }        g.setColor(color.getRGB());        g.fillArc(x, y, width, height, 0, 360);        g.setColor(brighter.getRGB());        g.drawArc(x + 2, y + 2, width - 4, height - 4, 180 + offset, -90);        g.setColor(darker.getRGB());        g.drawArc(x, y, width, height, 0, -90);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -