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

📄 bullet.java

📁 J2ME 上的坦克大战的demo,欢迎大家用来学习使用
💻 JAVA
字号:
/**
 * Copyright_2006, Liao Xuefeng
 * Created on 2006-2-6
 */
package com.javaeedev.j2megame.tank;

import javax.microedition.lcdui.Canvas;

public class Bullet {

    public static final int STEP_FRAME = 4;

    public final int direction; // original direction
    private int x; // absolute pixel
    private int y;

    public Bullet(int direction, int x, int y) {
        this.direction = direction;
        this.x = x;
        this.y = y;
    }

    /**
     * Move bullet. If return true, it is out of visible window.
     * @return True if bullet is out of window.
     */
    public boolean move() {
        switch(direction) {
        case Canvas.UP:
            y -= STEP_FRAME;
            break;
        case Canvas.DOWN:
            y += STEP_FRAME;
            break;
        case Canvas.LEFT:
            x -= STEP_FRAME;
            break;
        case Canvas.RIGHT:
            x += STEP_FRAME;
            break;
        }
        return (x<0 || y<0 || x>=GameMainCanvas.ACTIVE_WIDTH || y>=GameMainCanvas.ACTIVE_HEIGHT);
    }

    public int getX() { return x; }

    public int getY() { return y; }

}

⌨️ 快捷键说明

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