亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sprite.java

?? j2me 橫版過關游戲工程。(demo).可以參考下
?? JAVA
字號:

import javax.microedition.lcdui.*;

/**
 * 文件名: WestGameCanvas.java <br>
 * 作者: 汪霞 <br>
 * 創建日期: 2005-12-1 <br>
 * 文件功能: <br>
 * 版本:1.0 <br>
 * 編譯環境:CLDC1.0, MIDP1.0 <br>
 * 實現環境:NOKIA60 <br>
 * 注釋: <br>
 * 修改者姓名: <br>
 * 版權聲明:Copyright (c) 2000 GameFactory .All rights reserved. <br>
 */
public class Sprite
{

    protected int     x, y;                 //在屏幕上,需要繪制圖片的位置

    protected boolean visible;               //設置當前圖片的顯示與否

    int               id;

    // 動畫起始索引
    private int       sequenceIndex;

    // 自定義動畫順序
    private boolean   customSequenceDefined;

    // 動畫源圖像
    Image             sourceImage;

    // 動畫幀數
    int               numberFrames;

    // 幀的左上角相對于源圖像的x坐標數組
    int               frameCoordsX[];

    // 幀的左上角相對于源圖像的y坐標數組
    int               frameCoordsY[];

    // 幀的寬度
    int               srcFrameWidth;

    // 幀的高度
    int               srcFrameHeight;

    // 動畫幀的順序數組
    int               frameSequence[];

    // 碰撞檢測塊的左上角x坐標 (相對于一幀)
    int               collisionRectX;

    // 碰撞檢測塊的左上角y坐標 (相對于一幀)
    int               collisionRectY;

    // 碰撞檢測塊的寬度
    int               collisionRectWidth;

    // 碰撞檢測塊的高度
    int               collisionRectHeight;

    // 用 單幀圖像 生成sprite的constructor
    public Sprite(int id, Image image)
    {
        // 調用layer類構造函數,只有一幀的sprite,圖像的大小就是幀的大小
        visible = true;
        // 調用初始化幀相關事項的函數,對sequenceIndex不做更改(false)
        initializeFrames(image, image.getWidth(), image.getHeight(), false);
        // 調用初始化碰撞檢測塊的函數
        initCollisionRecBounds();
    }

    // 用 多幀圖像 生成sprite的constructor
    public Sprite(int id, Image image, int frameWidht, int frameHeight)
    {
        // 調用layer類構造函數,初始化幀的大小
        visible = true;
        // 參數合法化檢測
        if (frameWidht < 1 || frameHeight < 1
                || image.getWidth() % frameWidht != 0
                || image.getHeight() % frameHeight != 0)

        {
            System.out.println("imgWidth=" + image.getWidth() + ", imgHeight="
                    + image.getHeight());
            System.out.println("frameWidth=" + frameWidht + ", frameHeight="
                    + frameHeight);
            throw new IllegalArgumentException();
        }
        else
        {
            // 調用初始化幀相關事項的函數,對sequenceIndex不做更改(false)
            initializeFrames(image, frameWidht, frameHeight, false);
            // 調用初始化碰撞檢測塊的函數
            initCollisionRecBounds();
            this.id = id;
        }
    }

    // 設定動畫起始索引
    public void setFrame(int sequenceIndex)
    {
        // 動畫起始索引范圍限定
        if (sequenceIndex < 0 || sequenceIndex >= frameSequence.length)
            throw new IndexOutOfBoundsException();
        else
        {
            this.sequenceIndex = sequenceIndex;
        }
    }

    // 取得動畫起始索引
    public int getFrame()
    {
        return sequenceIndex;
    }

    // 取得動畫順序數組的長度
    public int getFrameSequenceLength()
    {
        return frameSequence.length;
    }

    // 設定動畫順序數組
    public void setFrameSequence(int[] sequence)
    {
        // 動畫順序數組如果為空
        if (null == sequence)
        {
            // 設定動畫起始索引為0
            sequenceIndex = 0;
            // 設定自定義動畫順序為fasle
            customSequenceDefined = false;
            // 按幀的自然順序,設定動畫順序數組
            frameSequence = new int[numberFrames];
            for (int i = numberFrames - 1; i >= 0; i--)
                frameSequence[i] = i;
            return;
        }
        // 出錯處理
        if (sequence.length < 1)
            throw new IllegalArgumentException();
        // 出錯處理:動畫索引范圍檢測
        for (int i = sequence.length - 1; i >= 0; i--)
            if (sequence[i] < 0 || sequence[i] >= numberFrames)
                throw new ArrayIndexOutOfBoundsException();
        // 設定自定義動畫順序為true
        customSequenceDefined = true;
        // 拷貝形參數組 到 動畫順序數組
        frameSequence = new int[sequence.length];
        System.arraycopy(sequence, 0, frameSequence, 0, sequence.length);
        // 設定動畫起始索引為0
        sequenceIndex = 0;
    }

    // 設定碰撞檢測塊范圍 (相對于一幀)
    public void defineCollisionRectangle(int x, int y, int w, int h)
    {
        // 設定碰撞檢測塊各值(左上角是相對于幀的)
        collisionRectX = x;
        collisionRectY = y;
        collisionRectWidth = w;
        collisionRectHeight = h;
    }

    // 與sprite的碰撞檢測
    public final boolean collidesWith(Sprite s)
    {
        // 如果有一方不可見,忽略檢測,返回false
        if (!this.visible || !s.visible)
            return false;
        // 由形參sprite的位置和碰撞檢測塊計算四邊范圍
        int thatLeft = s.x + s.collisionRectX;
        int thatTop = s.y + s.collisionRectY;
        int thatRight = thatLeft + s.collisionRectWidth;
        int thatBottom = thatTop + s.collisionRectHeight;
        // 由本sprite的位置和碰撞檢測塊計算四邊范圍
        int thisLeft = x + collisionRectX;
        int thisTop = y + collisionRectY;
        int thisRight = thisLeft + collisionRectWidth;
        int thisBottom = thisTop + collisionRectHeight;
        // 返回碰撞檢測函數的值,true為碰,false為沒碰
        return intersectRect(thatLeft, thatTop, thatRight, thatBottom,
                thisLeft, thisTop, thisRight, thisBottom);
    }

    // 與圖片的碰撞檢測
    public final boolean collidesWith(Image image, int imgX, int imgY)
    {
        if (!visible)
            return false;
        // 由image的位置和寬高計算四邊范圍
        int thatLeft = imgX;
        int thatTop = imgY;
        int thatRight = thatLeft + image.getWidth();
        int thatBottom = thatTop + image.getHeight();
        // 由本sprite的位置和碰撞檢測塊計算四邊范圍
        int thisLeft = x + collisionRectX;
        int thisTop = y + collisionRectY;
        int thisRight = thisLeft + collisionRectWidth;
        int thisBottom = thisTop + collisionRectHeight;
        // 返回碰撞檢測函數的值,true為碰,false為沒碰
        return intersectRect(thatLeft, thatTop, thatRight, thatBottom,
                thisLeft, thisTop, thisRight, thisBottom);
    }

    // 碰撞檢測處理(針對 矩形范圍)
    private boolean intersectRect(int r1Left, int r1Top, int r1Right,
            int r1Bottom, int r2Left, int r2Top, int r2Right, int r2Bottom)
    {
        // 碰撞檢測原理:碰撞的充分必要條件(一下所做的比較是是坐標x,y值的比較)
        // rec2的左邊必然小于rec1的右邊
        // rec2的右邊必然大于rec1的左邊
        // rec2的上邊必然小于rec1的下邊
        // rec2的下邊必然大于rec1的上邊
        return r2Left < r1Right && r2Right > r1Left && r2Top < r1Bottom
                && r2Bottom > r1Top;
    }

    // 初始化幀相關事項
    private void initializeFrames(Image image, int frameWidth, int frameHeight,
            boolean maintainCurFrame)
    {
        // 計算源圖像大小
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();
        // 計算源圖像行和列的幀數
        int numHorizontalFrames = imageWidth / frameWidth;
        int numVerticalFrames = imageHeight / frameHeight;
        // 更新舊的源圖像
        sourceImage = image;
        // 更新幀的高寬值
        srcFrameWidth = frameWidth;
        srcFrameHeight = frameHeight;
        // 計算源圖像中幀的總數
        numberFrames = numHorizontalFrames * numVerticalFrames;
        // 如果maintainCurFrame為false就不改變sequenceIndex
        if (maintainCurFrame)
            sequenceIndex = 0;
        // 更新幀相對于源圖像的x,y坐標數組
        frameCoordsX = new int[numberFrames];
        frameCoordsY = new int[numberFrames];
        // 如果不是自定義順序,更新動畫幀的順序數組
        if (!customSequenceDefined)
            frameSequence = new int[numberFrames];
        // 數組索引值
        short currentFrame = 0;
        // 這里還可以用單層for循環來完成,不過會用到乘法,而下面的算法只有加法
        for (short yy = 0; yy < imageHeight; yy += frameHeight)
        {
            for (short xx = 0; xx < imageWidth; xx += frameWidth)
            {
                //************************************************************
                //                System.out.println("xx=" + xx + ", yy+" + yy);
                // 紀錄幀相對于源圖像的x坐標
                frameCoordsX[currentFrame] = xx;
                // 紀錄幀相對于源圖像的y坐標
                frameCoordsY[currentFrame] = yy;
                // 如果不是自定義順序,那就按自然順序更新動畫幀的順序數組
                if (!customSequenceDefined)
                    frameSequence[currentFrame] = currentFrame;
                // 數組索引值自加一
                currentFrame++;
            }
        }
    }

    // 初始化碰撞檢測塊
    private void initCollisionRecBounds()
    {
        // 檢測塊的邊界是相對于幀的左上角
        collisionRectX = 0;
        collisionRectY = 0;
        collisionRectWidth = srcFrameWidth;
        collisionRectHeight = srcFrameHeight;
    }

    // 取得源圖像包含幀的總和
    public int getRawFrameCount()
    {
        return numberFrames;
    }

    // 計算下一幀的索引值
    public void nextFrame()
    {
        sequenceIndex = (sequenceIndex + 1) % frameSequence.length;
    }

    // 計算上一幀的索引值
    public void prevFrame()
    {
        if (0 == sequenceIndex)
            sequenceIndex = frameSequence.length - 1;
        else
            sequenceIndex--;
    }

    // 畫出動畫
    public final void paint(Graphics g)
    {
        // 出錯檢測
        if (null == g)
            throw new NullPointerException();
        // 如果本sprite可見,就可以畫
        if (visible)
        {
            //************************************************************
            //            System.out.println("x=" + x + ", y=" + y + ", srcFrameWidth="
            //                    + srcFrameWidth + ", srcFrameHeight=" + srcFrameHeight);
            // 設定畫筆區域
            g.setClip(x, y, srcFrameWidth, srcFrameHeight);
            //************************************************************
            //            System.out.println("frameCoordsX="
            //                    + frameCoordsX[frameSequence[sequenceIndex]]
            //                    + ", frameCoordxY="
            //                    + frameCoordsY[frameSequence[sequenceIndex]]);
            // 用動畫索引(sequenceIndex),從動畫幀的順序數組(frameSequence),取得幀號
            // 用幀號取得該幀相對于源圖像的位置(frameCoordsX,frameCoordsY)
            // 向畫筆的x,y位置,在平移(frameCoordsX,frameCoordsY),畫源圖像
            g.drawImage(sourceImage, x
                    - frameCoordsX[frameSequence[sequenceIndex]], y
                    - frameCoordsY[frameSequence[sequenceIndex]], Graphics.TOP
                    | Graphics.LEFT);

        }
    }

    //  設定動畫順序數組
    public void setFrameSequenceWX(int[] sequence)
    {
        // 動畫順序數組如果為空
        if (null == sequence)
        {
            // 設定動畫起始索引為0
            setFrame(0);
            // 按幀的自然順序,設定動畫順序數組
            frameSequence = new int[numberFrames];
            for (int i = numberFrames - 1; i >= 0; i--)
                frameSequence[i] = i;
            return;
        }
        // 出錯處理
        if (sequence.length < 1)
            throw new IllegalArgumentException();
        // 出錯處理:動畫索引范圍檢測
        for (int i = sequence.length - 1; i >= 0; i--)
            if (sequence[i] >= numberFrames)
                throw new ArrayIndexOutOfBoundsException();
        // 拷貝形參數組 到 動畫順序數組
        frameSequence = new int[sequence.length];
        System.arraycopy(sequence, 0, frameSequence, 0, sequence.length);
        // 設定動畫起始索引為0
        setFrame(0);
    }

    /**
     * 需要繪制圖片的位置
     */
    public void setPosition(int x, int y)
    {
        this.x = x;
        this.y = y;
    }

    public void move(int dx, int dy)
    {
        x += dx;
        y += dy;
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区四区国产精品| 看电视剧不卡顿的网站| 在线不卡免费欧美| 成人99免费视频| 另类欧美日韩国产在线| 91亚洲精华国产精华精华液| 97久久超碰国产精品| 91麻豆国产在线观看| 亚洲精品一线二线三线无人区| 日韩欧美亚洲国产另类| 91精品国产美女浴室洗澡无遮挡| 欧美日本精品一区二区三区| 欧美日韩国产天堂| 亚洲黄网站在线观看| 亚洲国产一区二区视频| 亚洲va天堂va国产va久| 奇米影视在线99精品| 美女视频网站久久| 成人性生交大片| 91久久人澡人人添人人爽欧美| 91免费国产视频网站| 国产亚洲综合性久久久影院| 日本一区二区动态图| 亚洲欧美视频在线观看视频| 亚洲午夜电影在线观看| 99riav一区二区三区| 国产三级精品三级在线专区| 亚洲精品大片www| www.欧美日韩国产在线| 91麻豆精品国产91久久久更新时间 | 欧日韩精品视频| 欧美二区乱c少妇| 亚洲va天堂va国产va久| 91精品国产综合久久香蕉的特点| 亚洲成年人影院| 91精品免费在线| 极品尤物av久久免费看| 91色婷婷久久久久合中文| 亚洲人xxxx| 欧美这里有精品| 午夜欧美视频在线观看| 成人动漫一区二区在线| 中文字幕综合网| 美女脱光内衣内裤视频久久网站 | 老司机一区二区| 精品福利一区二区三区免费视频| 国产在线不卡一区| 欧美日韩精品欧美日韩精品一综合| 一级精品视频在线观看宜春院| 欧美日韩一区二区欧美激情| 国产欧美精品一区| 99re热这里只有精品视频| 一区二区久久久| 欧美一区二区免费视频| 国产在线精品视频| 亚洲色图在线播放| 69堂精品视频| 成人妖精视频yjsp地址| 亚洲线精品一区二区三区| 日韩久久久久久| 99久久精品一区| 另类小说一区二区三区| 国产精品久久久久影视| 久久99精品久久久| 中文字幕成人av| 欧美日韩一区二区三区在线看| 国产综合色在线| 久久一区二区三区四区| 久久精品国产99国产| 中文字幕日韩欧美一区二区三区| 国产99久久久久久免费看农村| 久久综合九色综合97婷婷女人| 99精品欧美一区二区蜜桃免费| 奇米精品一区二区三区四区| 国产精品久久影院| 在线不卡a资源高清| 国产suv精品一区二区三区| 石原莉奈一区二区三区在线观看| 欧美人伦禁忌dvd放荡欲情| 国产91色综合久久免费分享| 热久久久久久久| 亚洲视频小说图片| 日本一区二区三区视频视频| 在线播放日韩导航| 一本高清dvd不卡在线观看| 亚洲一区二区三区四区中文字幕| 欧美色老头old∨ideo| 成人午夜av在线| 国产一区免费电影| 日本免费新一区视频| 久久午夜国产精品| 日韩一级黄色片| 国产在线一区观看| 天涯成人国产亚洲精品一区av| 亚洲欧洲av色图| 欧美激情一区二区三区四区| 精品久久久久久久久久久久包黑料| 国内精品视频一区二区三区八戒 | 8v天堂国产在线一区二区| 97se亚洲国产综合自在线| 国产宾馆实践打屁股91| 国产一区二区调教| 国产一区二区三区在线观看免费| 男女视频一区二区| 蜜桃久久久久久久| 蜜臀av一区二区三区| 美日韩一区二区| 另类小说综合欧美亚洲| 另类综合日韩欧美亚洲| 久久不见久久见中文字幕免费| 日韩中文字幕不卡| 日本三级韩国三级欧美三级| 青青草精品视频| 免费成人av在线| 九一九一国产精品| 国产在线精品国自产拍免费| 国产精品亚洲人在线观看| 亚洲伊人伊色伊影伊综合网| 麻豆一区二区三区| 久久精品噜噜噜成人88aⅴ| 久久er99热精品一区二区| 狠狠色狠狠色综合日日91app| 毛片av一区二区| 国产精品2024| 成人av电影观看| 在线观看成人小视频| 欧美日韩久久不卡| 欧美tickle裸体挠脚心vk| 国产午夜亚洲精品午夜鲁丝片| 国产精品三级久久久久三级| 欧美日本在线观看| 日韩女优av电影在线观看| 久久综合九色综合欧美98 | 偷拍自拍另类欧美| 久久www免费人成看片高清| 国产成人一区二区精品非洲| 亚洲成人一区二区| 久久国产精品99久久久久久老狼| 国产91色综合久久免费分享| 91麻豆国产在线观看| 欧美一区二区三区在线视频| 欧美电影免费观看高清完整版在| 国产日产欧美一区二区三区| 亚洲黄色av一区| 免费高清成人在线| av电影在线不卡| 91精品国产综合久久婷婷香蕉 | 欧美成人一区二区三区片免费 | 免费观看日韩av| 不卡电影免费在线播放一区| 欧美午夜寂寞影院| 一本到不卡免费一区二区| 欧美日韩亚洲不卡| 久久九九全国免费| 五月综合激情网| 国产1区2区3区精品美女| 欧美性xxxxxxxx| 国产精品久久综合| 老色鬼精品视频在线观看播放| 成人小视频在线观看| 日韩精品一区国产麻豆| 亚洲柠檬福利资源导航| 国模冰冰炮一区二区| 欧美日韩国产中文| 亚洲免费在线播放| 国产精品乡下勾搭老头1| 8x福利精品第一导航| 亚洲免费视频成人| 国产成人精品免费网站| 日韩女优毛片在线| 午夜精品久久久久久久99水蜜桃| 99热精品一区二区| 26uuu久久综合| 日韩av不卡在线观看| 欧美专区在线观看一区| 中文字幕亚洲精品在线观看| 国产传媒久久文化传媒| 91精品国产乱码久久蜜臀| 亚洲国产日韩一区二区| 色综合色狠狠综合色| 中文字幕色av一区二区三区| 国产成+人+日韩+欧美+亚洲| 欧美精品一区二区三区久久久| 日本最新不卡在线| 欧美日韩一区 二区 三区 久久精品| 亚洲丝袜美腿综合| 成人动漫av在线| 中文字幕免费在线观看视频一区| 91精品国产色综合久久ai换脸 | 韩国三级电影一区二区| 欧美日韩日本视频| 亚洲国产综合色| 欧美日韩亚洲高清一区二区| 夜夜嗨av一区二区三区四季av| 91久久精品一区二区| 一区二区三区av电影| 欧美视频在线一区| 天天做天天摸天天爽国产一区| 欧美日韩国产精选| 蜜桃视频在线观看一区二区|