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

📄 gameplay.java~10~

📁 J2ME游戏引擎,直接在JBUILDER2006下运行,不包含需要的SDK和虚拟机
💻 JAVA~10~
📖 第 1 页 / 共 2 页
字号:
import java.util.Vector;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0.0 */public class GamePlay extends GameFrameBase{    //Game State Defining    final static byte PLAYS_NEXT_LEVEL = 20;    final static byte PLAYS_COUNT_DOWN = 21;    final static byte PLAYS_PLAYING = 22;    final static byte PLAYS_STAGE_CLEARED = 23;    final static byte PLAYS_BOOM = 24;    final static byte PLAYS_GAME_OVER = 25;    //Game map Defining    final static byte STAGE_DATA[][][] =        {            {            {2, 0, 0, 4, 0},            {0, 0, 3, 0, 4},            {1, 0, 2, 0, 0},            {0, 0, 0, 0, 0}        }    };    //Gaming Consts    final static byte STAGE_COUNT = 1;    final static byte BLOCK_SIZE = 24;    final static byte SMALL_BLOCK_SIZE = 16;    final static byte MAP_X_LENGTH = 5;    final static byte MAP_Y_LENGTH = 4;    final static byte START_POS_X = 4;    final static byte START_POS_Y = 1;    //=变量定义=================    private byte m_i_CarSpeed;    byte m_Curr_StageData[][];    int m_i_CurrStage;    int m_i_CarPosX, m_i_CarPosY, m_i_CarRaw, m_i_CarCol, m_i_CarDirect,        m_i_StartCountLeft, iTemp;    //==================================END=    //=图片资源=================    private Surface m_Surface_BigRoad = null;    private Surface m_Surface_BigCar = null;    private Surface m_Surface_SmallRoad = null;    private Surface m_Surface_SmallCar = null;    private Surface m_Surface_Icons = null;    private Surface m_Surface_Digits = null;    private Surface m_Surface_Boom = null;    private Surface m_Surface_TitleNext = null;    private Surface m_Surface_TitleGameOver = null;    //==================================END=    public GamePlay()    {        m_vect_SurfacePath = new Vector();        m_vect_SurfacePath.addElement("/bigroad.png");        m_vect_SurfacePath.addElement("/bigcar.png");        m_vect_SurfacePath.addElement("/smallroad.png");        m_vect_SurfacePath.addElement("/smallcar.png");        m_vect_SurfacePath.addElement("/icons.png");        m_vect_SurfacePath.addElement("/digits.png");        m_vect_SurfacePath.addElement("/boom.png");        m_vect_SurfacePath.addElement("/title_next.png");        m_vect_SurfacePath.addElement("/title_gameover.png");        m_Curr_StageData = new byte[MAP_Y_LENGTH][MAP_X_LENGTH];    }    public void Create(GameViewBase view)    {        m_View = view;        m_BackGraphy = m_View.m_g_BackGraphy;        m_Surface_BigRoad = m_View.nextSurface();        m_Surface_BigCar = m_View.nextSurface();        m_Surface_SmallRoad = m_View.nextSurface();        m_Surface_SmallCar = m_View.nextSurface();        m_Surface_Icons = m_View.nextSurface();        m_Surface_Digits = m_View.nextSurface();        m_Surface_Boom = m_View.nextSurface();        m_Surface_TitleNext = m_View.nextSurface();        m_Surface_TitleGameOver = m_View.nextSurface();    }    public void Release()    {        if(m_View != null)            m_View.ReleaseAllSurfaces();    }    public void NewGame(int iStage)    {        m_i_CurrStage = iStage;        for (int i = 0; i < MAP_Y_LENGTH; i++)        {            for (int j = 0; j < MAP_X_LENGTH; j++)                m_Curr_StageData[i][j] = STAGE_DATA[iStage % STAGE_COUNT][i][j];        }        m_i_CarSpeed = (byte) (2 + (iStage / STAGE_COUNT));        if (m_i_CarSpeed == 5)            m_i_CarSpeed = 6;        if (m_i_CarSpeed > 6)            m_i_CarSpeed = 8;        m_i_CarPosX = 0;        m_i_CarPosY = (MAP_Y_LENGTH + 1) * BLOCK_SIZE;        m_i_CarDirect = 0;        m_i_StartCountLeft = 5;        iTemp = 0;        m_i_FrameState = PLAYS_NEXT_LEVEL;    }    public void OnKeyDown(int iScanCode)    {        switch (m_i_FrameState)        {            case PLAYS_COUNT_DOWN:            case PLAYS_PLAYING:                switch (iScanCode)                {                    case GameViewBase.KEY_SOFTKEY1:                    case GameViewBase.KEY_FIRE:                        for (int i = 0; i < MAP_Y_LENGTH; i++)                        {                            for (int j = 0; j < MAP_X_LENGTH; j++)                            {                                if (m_Curr_StageData[i][j] > 0)                                {                                    m_Curr_StageData[i][j]++;                                    if (m_Curr_StageData[i][j] > 4)                                        m_Curr_StageData[i][j] = 1;                                }                            }                        }                        break;                }                break;        }    }    public void OnKeyUp(int iScanCode)    {    }    public void Show()    {        switch (m_i_FrameState)        {            case PLAYS_NEXT_LEVEL:                DrawGameBackGround();                DrawNextScreen();                m_i_CarPosX += m_i_CarSpeed;                if (m_i_CarPosX > 4 * BLOCK_SIZE)                {                    m_i_FrameState = PLAYS_COUNT_DOWN;                    m_i_CarPosX = 0;                }                break;            case PLAYS_COUNT_DOWN:                DrawGameBackGround();                DrawRoad();                DrawCar();                DrawCountDown();                iTemp++;                if (iTemp > 15)                {                    iTemp = 0;                    m_i_StartCountLeft--;                }                if (m_i_StartCountLeft == 0)                {                    iTemp = 0;                    m_i_FrameState = PLAYS_PLAYING;                }                break;            case PLAYS_PLAYING:                DrawGameBackGround();                DrawRoad();                DrawCar();                DrawIcons();                MoveCar();                break;            case PLAYS_STAGE_CLEARED:                DrawGameBackGround();                DrawRoad();                DrawIcons();                iTemp += m_i_CarSpeed;                m_View.Blt(m_i_CarPosX + START_POS_X,                           m_i_CarPosY + START_POS_Y - iTemp, BLOCK_SIZE,                           BLOCK_SIZE, m_i_CarDirect * BLOCK_SIZE, 0,                           m_Surface_BigCar);                if (iTemp == BLOCK_SIZE)                {                    NewGame(m_i_CurrStage + 1);                }                break;            case PLAYS_BOOM:                DrawGameBackGround();                DrawRoad();                DrawCar();                DrawIcons();                m_View.Blt(m_i_CarPosX + START_POS_X - 10,                           m_i_CarPosY + START_POS_Y - 9, 45, 42, 0, 0,                           m_Surface_Boom);                iTemp++;                if (iTemp > 20)                {                    iTemp = 0;                    m_i_FrameState = PLAYS_GAME_OVER;                }                break;            case PLAYS_GAME_OVER:                DrawGameBackGround();                DrawGameOver();                iTemp++;                if (iTemp > 20)                {                    iTemp = 0;                    //Release();

⌨️ 快捷键说明

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