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

📄 sprite.java

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

import javax.microedition.lcdui.*;

class Sprite {
    static final int BG_COLOR = 0x000000;
    static Image IMG_ALL;
    static Image IMG_SPLASH;
    static Image IMG_RESUME;

	/* Start	Commented	18-03-2003		for transparency	*/
    //static Image[] wrongWay = new Image[4];
    //static Image[] coily = new Image[10];
    //static Image[] qBert = new Image[8];
    //static Image selector;
	/* End		Commented	18-03-2003	*/


	//VALLI MR2
	static Image IMG_SELECT;



    static Image imgOffscreen;
    static Graphics gOffscreen;

    static void initImages() {
        IMG_ALL = loadImage("/qbertassetsbig.png");
        IMG_SPLASH = loadImage("/splash.png");
        IMG_RESUME = loadImage("/resume.png");

	//VALLI MR2
        IMG_SELECT = loadImage("/selector.png");

	/* Start	Commented	18-03-2003		for transparency	*/
        //selector = loadImage("/selector.png");
        //String ext = ".png";
        //String ww = "/ww";
        //String cO = "/cy";
        //String qB = "/qb";

        //for (int i = 0; i < coily.length; i++) {
        //    coily[i] = loadImage(cO + i + ext);
        //}
        //wrongWay[1] = loadImage(ww + "1" + ext);
        //wrongWay[3] = loadImage(ww + "3" + ext);

        //for (int i = 0; i < qBert.length; i++){
        //    qBert[i] = loadImage(qB + i + ext);
        //}

	/* End		Commented	18-03-2003	*/

        imgOffscreen = Image.createImage(Globals.SCREEN_W, Globals.SCREEN_H);
        gOffscreen = imgOffscreen.getGraphics();
    }

    static private Image loadImage(String filename) {
        try {
            return Image.createImage(filename);
        } catch (Exception e) {
            return null;
        }
    }


    static void drawSavingWindow(Graphics g, String word) {
        g.setColor(0x0000ff); // blue
        g.drawRect(Globals.GAMEMENU_BOX_X - 2, Globals.GAMEMENU_BOX_Y - 2, Globals.GAMEMENU_BOX_WIDTH + 3, Globals.GAMEMENU_BOX_HEIGHT + 3);

        g.setColor(0xff0000); // red
        g.drawRect(Globals.GAMEMENU_BOX_X - 1, Globals.GAMEMENU_BOX_Y - 1, Globals.GAMEMENU_BOX_WIDTH + 1, Globals.GAMEMENU_BOX_HEIGHT + 1);
        g.setColor(BG_COLOR);

        g.fillRect(Globals.GAMEMENU_BOX_X, Globals.GAMEMENU_BOX_Y, Globals.GAMEMENU_BOX_WIDTH, Globals.GAMEMENU_BOX_HEIGHT);

		/* Start	Modified		25-04-2003	for chinese support	*/
		g.setColor(255,255,4);
		g.setFont(Globals.font);
		g.drawString(word,Globals.GAMEMENU_PAUSE_X,Globals.GAMEMENU_PAUSE_Y,g.TOP | g.LEFT);
        //drawWord(g, Globals.GAMEMENU_PAUSE_X, Globals.GAMEMENU_PAUSE_Y, word);
        /* End		Modified		25-04-2003	*/
    }


    static void renderScore(Graphics g, int score, int x, int y) {
        do {
            int rem = score % 10;
            /* Start	Modified	18-03-2003	transparency	*/
            x -= (m_gArr2ClipInfo_Numbers[rem][2] + 1);
            /* End		Modified	18-03-2003	*/
            drawClipped(g, IMG_ALL, x, y, m_gArr2ClipInfo_Numbers, rem, 1);
            score /= 10;
        }
        while (score > 0);
    }

    /* Start	Modified	15-05-2003		for chinese support	*/
    static void renderHighScore(Graphics g, String score, int x, int y) {
		/* Start	Modified		25-04-2003	for chinese support	*/
		g.setColor(255,117,0);
		g.setFont(Globals.font);
		g.drawString(score,x,y,g.TOP | g.RIGHT);
    }
    /* End		Modified	15-05-2003	*/



    static final void drawIntroBackground(Graphics g,
                                                 int[][] arr2Board,
                                                 int round,
                                                 int lvl) {

        g.setColor(BG_COLOR);
        g.fillRect(0, 0, Globals.SCREEN_W, Globals.SCREEN_H);

        int introIndex = Math.min(5, lvl);

        // read in values
        int[] arrLevelData = Globals.LEVEL_DATA[introIndex][round];

        int leftColor = arrLevelData[Globals.LVL_INDEX_LEFT_CLR];
        int rightColor = arrLevelData[Globals.LVL_INDEX_RIGHT_CLR];

        int cube_width_offset = Globals.CUBE_WIDTH/2;
        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 num = 0;

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                // diamond

                int x = (Globals.GAME_WIDTH / 2 - width_inc) + (cube_width_offset * ( i - j)) - 3;
                int y = 25 + (cube_height_offset * (i+j));

                renderFullCube(g, x, y, leftColor, rightColor, arr2Board[i][j]);
            }
        }

        // draw level
        drawClipped(g, IMG_ALL, Globals.INTRO_LEVEL_X, Globals.INTRO_LEVEL_Y, g_arr2ClipInfoStuff, 2, 1);

        // draw circle thing
        drawClipped( g, IMG_ALL, Globals.INTRO_CIRCLE_X, Globals.INTRO_CIRCLE_Y, g_arr2ClipInfoStuff, 1, 1);

        int val = 11;

        if (lvl == 0)
            val = 10;

        renderScore(g, lvl + 1, Globals.INTRO_CIRCLE_X + val, Globals.INTRO_CIRCLE_Y + 5);
    }


    static void renderBabyCube(Graphics g, int x, int y, int leftColor, int rightColor, int topColor) {
        drawBabyTop(g, x, y, topColor);
        drawBabyLeft(g, x, y, leftColor);
        drawBabyRight(g, x, y, rightColor);
    }


    private static void drawBabyTop(Graphics g, int x, int y, int color) {
        // 4 draws total for top
        g.setColor(color);
        g.fillRect(x, y + 1, 10, 1);
        g.fillRect(x + 2, y, 6, 1);
        g.fillRect(x + 2, y + 2, 6, 1);
    }


    private static void drawBabyLeft(Graphics g, int x, int y, int color) {
        g.setColor(color);

        g.fillRect(x, y + 2, 2, 3);
        g.fillRect(x + 2, y + 3, 2, 3);
        g.fillRect(x + 4, y + 3, 1, 4);
    }


    private static void drawBabyRight(Graphics g, int x, int y, int color) {
        g.setColor(color);

        g.fillRect(x + 5, y + 3, 1, 4);
        g.fillRect(x + 6, y + 3, 2, 3);
        g.fillRect(x + 7, y + 2, 2, 3);
    }


    static void renderFullCube(Graphics g, int x, int y, int leftColor, int rightColor, int topColor) {
        drawTop(g, x, y, topColor);
        drawLeft(g, x, y, leftColor);
        drawRight(g, x, y, rightColor);
    }


    static void drawTop(Graphics g, int x, int y, int color) {
        g.setColor(color);
        g.fillRect(x, y + 3, 16, 2);
        g.fillRect(x + 2, y + 2, 12, 4);
        g.fillRect(x + 4, y + 1, 8, 6);
        g.fillRect(x + 6, y, 4, 8);
    }


    private static void drawLeft(Graphics g, int x, int y, int color) {
        g.setColor(color);
        g.fillRect(x, y + 5, 2, 8);
        g.fillRect(x + 2, y + 6, 2, 8);
        g.fillRect(x + 4, y + 7, 2, 8);
        g.fillRect(x + 6, y + 8, 2, 8);
    }


    private static void drawRight(Graphics g, int x, int y, int color) {
        g.setColor(color);
        g.fillRect(x + 8, y + 8, 2, 8);
        g.fillRect(x + 10, y + 7, 2, 8);
        g.fillRect(x + 12, y + 6, 2, 8);
        g.fillRect(x + 14, y + 5, 2, 8);
    }


    static void drawQbert(Graphics g, CharacterSprite ch) {

        if (ch.charShowChar()) {
            int dir = ch.charDir();
            int pos = ch.charPosition();
            int cycle_num = ch.charImgCycle();

            int moves[] = ch.charFutureMoves();

            int x = ch.charX()+1;
            int y = ch.charY()+1;

            int img_num = dir * 2 + 1;

            if (moves[0] == 0) {
                // Not moving
                if (pos == 0) {
                    //pos = 2;
                    ch.charPosition(2);
                } else if (pos == 1) {
                    //pos = 0;
                    img_num--;
                    ch.charPosition(0);
                }
            } else {
                img_num--;
                ch.charPosition(1);
            }
			/* Start	Modified	18-03-2003		transparency	*/
        	drawClipped(g, IMG_ALL, x, y, gArr3ClipInfo_Qbert, img_num,1);
            //g.drawImage(qBert[img_num], x, y, Globals.GFX_TOPLEFT);
        	/* End		Modified	18-03-2003	*/
        }
    }


    static void drawCharacter(Graphics g, int animationCycle, CharacterSprite ch) {

        if (ch.charShowChar()) {
            int type = ch.charType();

            switch (type) {
                case Globals.COILY :
                    renderCoily(g, animationCycle, ch, true);
                    break;
                case Globals.RED :
                    renderRedBall(g, animationCycle, ch);
                    break;
                case Globals.GREEN :
                    renderGreenBall(g, animationCycle, ch);
                    break;
                case Globals.PURPLE :
                    renderCoily(g, animationCycle, ch, false);
                    break;
                case Globals.SLICK :
                    renderSlick(g, animationCycle, ch);
                    break;
                case Globals.SAM :
                    renderSam(g, animationCycle, ch);
                    break;
                case Globals.UGG :
                    renderUgg(g, animationCycle, ch);
                    break;
                case Globals.WRONGWAY :
                    renderWrongWay(g, animationCycle, ch);
                    break;
            }
        }
    }


    static void renderDisc(Graphics g, int animationCycle, CharacterSprite ch) {
        int x = ch.charX();
        int y = ch.charY();
        int img_num = ch.charPosition() + 1;
        int num_imgs = ch.charImgCycle();
        if (animationCycle != -1) {
            if (img_num < num_imgs) {
                ch.charPosition(ch.charPosition() + 1);
            } else {
                ch.charPosition(0);
                img_num = 0;
            }
        } else {
            img_num--;
        }
		/* Start	Modified		18-03-2003		transparency	*/
        drawClipped(g, IMG_ALL, x, y, g_arr3ClipInfo_Disc, img_num);
        /* End	Modified		18-03-2003	*/
    }


    static private void renderRedBall(Graphics g, int animationCycle, CharacterSprite ch) {
        int x = ch.charX();
        int y = ch.charY();

        int img_num = 0;
        int moves[] = ch.charFutureMoves();
        if (moves[0] != 0) {
            img_num = 1;
        }
		/* Start	Modified		18-03-2003		transparency	*/
        drawClipped(g, IMG_ALL, x + 2, y + 8, g_arr3ClipInfo_RedBall, img_num,1);
        /* End		Modified	18-03-2003	*/
    }


    static private void renderGreenBall(Graphics g, int animationCycle, CharacterSprite ch) {
        int x = ch.charX();
        int y = ch.charY();
        int img_num = 0;
        int moves[] = ch.charFutureMoves();
        if (moves[0] != 0) {
            img_num = 1;
        }
		/* Start	Modified		18-03-2003	transparency	*/
        drawClipped(g, IMG_ALL, x + 2, y + 8, g_arr3ClipInfo_GreenBall, img_num,1);
        /* End	Modified		18-03-2003	*/
    }


    static private void renderCoily(Graphics g, int animationCycle, CharacterSprite ch, boolean snake) {
        int x = ch.charX();
        int y = ch.charY();
        int img_num = ch.charDir();
        int moves[] = ch.charFutureMoves();
        if (!snake) {
            img_num = 0;
            y += 6;

            if (moves[0] != 0)
                img_num = 1;
        } else {
            img_num = 2 + ch.charDir()*2;
            if (moves[0] != 0) {
                 img_num++;
                 y -= 6;
            }
        }
		/* Start	Modified		18-03-2003		transparency	*/
        drawClipped(g, IMG_ALL, x, y, g_arr3ClipInfo_Coily, img_num,1);
        //g.drawImage(coily[img_num], x, y, Globals.GFX_TOPLEFT);
        /* End		Modified	18-03-2003	*/
    }


    static private void renderUgg(Graphics g, int animationCycle, CharacterSprite ch) {
        int x = ch.charX();
        int y = ch.charY();
        int img_num = ch.charDir();
		/* Start	Modified	18-03-2003		transparency	*/
        drawClipped(g, IMG_ALL, x, y - 1, g_arr3ClipInfo_Ugg, img_num,1);
        /* End		Modified	18-03-2003	*/
    }


    static private void renderWrongWay(Graphics g, int animationCycle, CharacterSprite ch) {
        int x = ch.charX();
        int y = ch.charY();
        int img_num = ch.charDir();
		/* Start	Modified	18-03-2003		transparency	*/
        drawClipped(g, IMG_ALL, x, y - 1, g_arr3ClipInfo_WrongWay, img_num,1);
        //g.drawImage(wrongWay[img_num], x, y - 1, Globals.GFX_TOPLEFT);
        /* End		Modified	18-03-2003	*/

    }


    static private void renderSlick(Graphics g, int animationCycle, CharacterSprite ch) {
        int x = ch.charX();
        int y = ch.charY();
        int img_num = 0;
        if (ch.charDir() == Globals.DOWNRIGHT) {
            img_num = 1;
        }
        /* Start	Modified		18-03-2003	transparency	*/
        drawClipped(g, IMG_ALL, x+1, y+1, g_arr3ClipInfo_Slick, img_num,1);

⌨️ 快捷键说明

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