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

📄 backgroundsprite.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
字号:
package com.centerscore.game;

import javax.microedition.lcdui.*;

class BackGroundSprite {
    static final byte LIVES_X = 0;
	/* Start	Modified		07-05-2003		for chinese support	*/
    static final byte LIVES_Y = 38;
    //static final byte LIVES_Y = 30;
    /* End		Modified		07-05-2003	*/
    static final byte LIVES_WIDTH = 7;
    static final byte LIVES_HEIGHT = 8;

    static final byte FINAL_CUBE_X = 15;
	/* Start	Modified		07-05-2003		for chinese support	*/
    static final byte FINAL_CUBE_Y = 28;
    //static final byte FINAL_CUBE_Y = 20;
    /* End		Modified		07-05-2003	*/

    private int m_LivesLeft;
    private int m_Score;
    private int m_Lvl;
    private int m_Round;
    private int m_final_color;
    private int[][] m_arr2_boardLayout;
    private Image m_backGroundImage;
    private Graphics m_bgGraphics;
    private int m_flip_color, m_startColor;
    private int m_leftColor, m_rightColor;

    BackGroundSprite(int arr2BoardLayout[][]) {
        m_arr2_boardLayout = arr2BoardLayout;

        m_backGroundImage = Sprite.imgOffscreen;
        m_bgGraphics = Sprite.gOffscreen;
    }


    int getFlippedColor() {
        return m_flip_color;
    }


    /**
    * Assembles background image onto offscreen buffer
    */
    void forceRedraw() {
        m_bgGraphics.setColor(Sprite.BG_COLOR);
        m_bgGraphics.fillRect(0, 0, Globals.SCREEN_W, Globals.SCREEN_H);

        int cube_width_offset = Globals.CUBE_WIDTH;
        int cube_height_offset = (int) Globals.CUBE_WIDTH / 4 * 3;
        int width_inc = cube_width_offset / 2;

        int x = Globals.GAME_WIDTH / 2 - width_inc - cube_width_offset;
        int y = 25; // start from here and go down
        int i = 1, j = 1;
        while (i <= Globals.QBERT_DIMENSIONS) {
            // Check to see what m_bgColor the block is
            while (j <= i) {
                x += cube_width_offset;
                int topColor = m_arr2_boardLayout[i - 1][j - 1];
                Sprite.renderFullCube(m_bgGraphics, x, y,
                                      m_leftColor,
                                      m_rightColor,
                                      topColor
                                      );
                j++;
            }
            x -= width_inc += cube_width_offset;
            y += cube_height_offset;
            j = 1;
            i++;
        }

        Sprite.drawClipped(m_bgGraphics, Sprite.IMG_ALL, Globals.CHANGE_TO_X, Globals.CHANGE_TO_Y, Sprite.g_arr2ClipInfoStuff, 6, 1); // changeTo
        Sprite.renderBabyCube(m_bgGraphics, FINAL_CUBE_X, FINAL_CUBE_Y, m_leftColor, m_rightColor, m_final_color);
		/* Start	Modified		07-05-2003		for chinese support	*/
		updateRound(m_Round);
		updateLvl(m_Lvl);
        //Sprite.renderScore(m_bgGraphics, m_Round + 1, Globals.ROUND_X, Globals.ROUND_Y);
        //Sprite.renderScore(m_bgGraphics, m_Lvl + 1, Globals.ROUND_X, Globals.LEVEL_Y);
        /* End		Modified		07-05-2003	*/
        Sprite.renderScore(m_bgGraphics, m_Score, Globals.SCORE_X, Globals.SCORE_Y);
        Sprite.drawClipped(m_bgGraphics, Sprite.IMG_ALL, Globals.ROUND_X - 32, Globals.LEVEL_Y, Sprite.g_arr2ClipInfoStuff, 7, 1); // level, round
        Sprite.renderLives(m_bgGraphics, m_LivesLeft);
        Sprite.drawClipped(m_bgGraphics, Sprite.IMG_ALL, 0, 0, Sprite.g_arr2ClipInfoStuff, 3, 1); // header
    }


    void updateBoard(int row, int cube, int color) {
        //int[] arr_colors = Globals.CUBE_COLORS[color];

        m_arr2_boardLayout[row][cube] = color;

        int cube_width_offset = Globals.CUBE_WIDTH;
        int cube_height_offset = (int) Globals.CUBE_WIDTH / 4 * 3;
        int width_inc = cube_width_offset / 2;

        int x = Globals.GAME_WIDTH / 2 - width_inc - cube_width_offset;
        int y = 25;
        int i = 1, j = 1;
        while (i <= Globals.QBERT_DIMENSIONS) {
            while (j <= i) {
                x += cube_width_offset;
                if (row == i - 1 && cube == j - 1) {
                    Sprite.drawTop(m_bgGraphics, x, y, color);//Globals.CUBE_COLORS[color][0]);
                    return;
                }
                j++;
            }
            x -= width_inc += cube_width_offset;
            y += cube_height_offset;
            j = 1;
            i++;
        }
    }

    /**
    * Updates the number of lives lefts. Triggers a rebuild of the background.
    * @param nLivesLeft The new number of lives left
    */
    void updateLivesLeft(int nLivesLeft) {
        m_LivesLeft = nLivesLeft;

        m_bgGraphics.setColor(256);
        m_bgGraphics.fillRect(LIVES_X, LIVES_Y + (nLivesLeft * LIVES_HEIGHT), LIVES_WIDTH, LIVES_HEIGHT);

        Sprite.renderLives(m_bgGraphics, m_LivesLeft);
    }

    /**
    * Updates the score. Triggers a rebuild of the background
    * @param nScore The new score
    */
    void updateScore(int nScore) {
        m_Score = nScore;

        m_bgGraphics.setColor(256);
        m_bgGraphics.fillRect(Globals.SCORE_X - Globals.SCORE_WIDTH,
                                Globals.SCORE_Y,
                                Globals.SCORE_WIDTH,
                                Globals.SCORE_HEIGHT);

        Sprite.renderScore(m_bgGraphics, nScore, Globals.SCORE_X, Globals.SCORE_Y);
    }
    /**
    * Updates the Level. Triggers a rebuild of the background.
    * @param nLvl The new Level
    */
    void updateLvl(int lvl) {
        m_Lvl = lvl;

        m_bgGraphics.setColor(256);
        m_bgGraphics.fillRect(Globals.LEVEL_X,
                                Globals.LEVEL_Y,
                                Globals.LEVEL_WIDTH,
                                Globals.LEVEL_HEIGHT);

		/* Start	Modified		07-05-2003		for chinese support	*/
        Sprite.renderScore(m_bgGraphics, lvl + 1, Globals.ROUND_X, Globals.LEVEL_Y+3);
        //Sprite.renderScore(m_bgGraphics, lvl + 1, Globals.LEVEL_X, Globals.LEVEL_Y);
        /* End		Modified		07-05-2003	*/
    }


    /**
    * Updates the round. Triggers a rebuild of the background
    * @param round The new round
    */
    void updateRound(int round) {
        m_Round = round;

        m_bgGraphics.setColor(256);
        m_bgGraphics.fillRect(Globals.ROUND_X,
                                Globals.ROUND_Y,
                                Globals.ROUND_WIDTH,
                                Globals.ROUND_HEIGHT);

        Sprite.renderScore(m_bgGraphics, round + 1, Globals.ROUND_X, Globals.ROUND_Y);
    }


    void toggleBoardColor() {
        if (m_flip_color == m_startColor) {
            m_flip_color = m_final_color;
        } else {
            m_flip_color = m_startColor;
        }

        int i = 0, j = 0;
        while (i < Globals.QBERT_DIMENSIONS) {
            while (j <= i) {
                updateBoard(i, j, m_flip_color);
                j++;
            }
            j = 0;
            i++;
        }
    }


    void setColors(int startColor, int finalColor, int leftColor, int rightColor) {

        m_final_color = finalColor;
        m_startColor = startColor;

        m_leftColor = leftColor;
        m_rightColor = rightColor;
    }


    void paint(Graphics g) {
        // draw composed background
        g.drawImage(m_backGroundImage, 0, 0, Globals.GFX_TOPLEFT);
    }
}

⌨️ 快捷键说明

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