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

📄 animation.java~87~

📁 手机上一个坦克游戏
💻 JAVA~87~
字号:
package demo;

import java.io.*;
import javax.microedition.lcdui.*;

public class Animation
    extends Thread {
    private Animation instance;
    private BattleField battleCanvas;
    private Image pic;
    //private int picIndex = 0;
    //private int times = 0;
    public boolean isStop = false;

    //public boolean run = true;
    public int x;
    public int y;
    //private int timesLength;
    public String who_get;
    public String prop;
    //private boolean isMain = true;

    //控制發射導彈個數
    //public static int missileIndex = 0;

    //private boolean isMe = true;

    public Animation(BattleField battleCan,String name) {
        instance = this;
        //picIndex = 0;
        battleCanvas = battleCan;
        //this.timesLength = timesLength;
        try {
            byte abyte[] = Main.b("");
            pic = Image.createImage(abyte, 0, abyte.length);
            abyte = null;
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        (new Thread(this)).start();
    }

    /*public Animation(BattleField battleCan, int frames, String name,
                     int timesLength, Missile missile) {
        this(battleCan, frames, name, timesLength);
        x = missile.m_x - 10;
        y = missile.m_y - 7;
        isMain = missile.isMain;
        //Animation.missileIndex = 0;
    }*/

    public void setPro(String item) {
        //this.mode = mode;
        //         this.id = id;
        prop = item;
    }

    public void move(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /*private void loadFrames(int frames, String name) throws Exception {
        pics = new Image[frames];
        byte abyte[];
        for (int i = 0; i < frames; ++i) {
            abyte = Main.b(name + Integer.toString(i) +
                           ".png");
            pics[i] = Image.createImage(abyte, 0, abyte.length);
        }
        abyte = null;
    };*/

    public void stopAnimation() {
        this.isStop = true;
        instance = null;
    }

    public void run() {
        while (true) {

            try {
                move(x, y + 5);
                //如果物品超出边界
                if (y > battleCanvas.MAP_HEIGHT - battleCanvas.BOX_SIZE) {
                    //销毁自己
                    stopAnimation();
                    break;
                }
                if (y + battleCanvas.BOX_SIZE > battleCanvas.map.topLine[x]) {
                    y = battleCanvas.map.topLine[x] - battleCanvas.BOX_SIZE;
                }
                else {
                    battleCanvas.repaint(0, 0, battleCanvas.screen_w,
                                         battleCanvas.screen_h);
                    //battleCanvas.repaint(x - 15 - battleCanvas.SCREEN_X, y - 15 - battleCanvas.SCREEN_Y, pics[picIndex].getWidth() + 30, battleCanvas.screen_h);
                }
                Thread.sleep(100L);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public void paint(Graphics g1) {
        if (!isStop) {
            if (this != null)
                g1.drawImage(pic, x,
                             y, g1.LEFT | g1.TOP);
        }
    }
}

⌨️ 快捷键说明

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