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

📄 gameengine.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    case 5:
                        bytPathBits &= Erix.FIFTH_BIT_SET;
                        if(bytPathBits == Erix.FIFTH_BIT_SET){
                            nReturnValue = ENEMY_ERIX_COLLISION;
                        }
                        break;
                    case 6:
                        bytPathBits &= Erix.SIXTH_BIT_SET;
                        if(bytPathBits == Erix.SIXTH_BIT_SET){
                            nReturnValue = ENEMY_ERIX_COLLISION;
                        }
                        break;
                    case 7:
                        bytPathBits &= Erix.SEVENTH_BIT_SET;
                        if(bytPathBits == Erix.SEVENTH_BIT_SET){
                            nReturnValue = ENEMY_ERIX_COLLISION;
                        }
                        break;
                    default:
                        break;
                }

            } catch (Exception e) {
                System.out.println(
                    "Exception in checking if PathBeingCrossed by Enemy - "
                    + nRowNum + " " + nColNum);
            }

            if (nReturnValue != 0) {
                m_bIsPathCrossed = true;
                return nReturnValue;
            }


        // Checking whether the enemy has collided with the boundary of the
        // unsecured region:
        try {
            int nRow = -1;
            int nXPos = -1;
            int nCol = -1;
            int nBit = -1;

            //Check if any one of the enemy has reached the boundary.
            nRow = m_objEnemy[nEnemyIndex].m_nEnemyYPos;
            nXPos = m_objEnemy[nEnemyIndex].m_nEnemyXPos;
            nCol = nXPos >> 3;
            nBit = nXPos % 8;

            if(GameEngine.inSecuredRegion(m_arrSecuredRegionBmp, nRow, nCol, nBit)) {
                nReturnValue = ENEMY_BOUNDARY_COLLISION;
            }

        } catch(Exception e) {
            System.out.println("Exception in checkEnemyCollision with boundary - " +e);
        }

        return nReturnValue;
    } // end of code block that checks for
      // the enemy's collision with Erix or Erix's path.


    /**
     * Checks for the collision of Erix with the enemies.
     * If the return value indicates that the Erix collided with an Enemy, the
     * GameEngine requests the 'Lose Life' sound to be played, and uses the
     * processLoseLife() method to do the required processing for the player
     * losing a life.
     * @return Indicates whether Erix collided with an enemy or not.
     */
    private boolean checkErixCollision() {

        boolean bReturnValue = false;
        for(int i = 0; i < m_nNumberOfEnemies; i++){
            if(m_objEnemy[i].m_nEnemyXPos == m_objErix.m_nErixXPos
                    && m_objEnemy[i].m_nEnemyYPos == m_objErix.m_nErixYPos){
                bReturnValue = true;
                break;
            }
        }
        return bReturnValue;
    } // end of method checkErixCollision


    /**
     * Decrements the life count of Erix.
     * Sets the mode to LIFE_LOSE so the appropriate msg is shown on the screen.
     * Also it deletes the saved game, if any from the rms.
     */
    private void processLoseLife() {
        --m_bytLifeCount;
        m_nEngineMode = LIFE_LOSE_MODE;

        // Set this flag to get the appropriate msg painted.
        m_objCanvas.m_bMessagePaintedOnce = false;
    }

    /**
     * During the game loop, the queueSound method is used to request a certain
     * sound effect to be played.
     * There are certain occurrences in the game at which certain sounds are
     * played. However, in case two or more such event occur in the same
     * iteration of the game loop, only the most important of these sounds must
     * be played. The queusSound method checks to see whether another sound has
     * been requested in the same iteration. If so, the earlier request is
     * overwritten with the newer request if the newer request is of a higher
     * priority; otherwise the newer request is discarded. This makes sure that
     * at the end of an iteration, only the most important sound requested
     * during that iteration is played.
     * @param nSoundType The type of sound to be queued by the Engine for
     * playing.
     */
    private void queueSound(int nSoundType) {
        // If the new sound request is for a sound
        // that is of a higher priority (lower priority number)
        // than other requests received in this iteration,
        // choose this as the current candidate
        // for the sound to be played at the end of the iteration.
        if (nSoundType < m_nHighestPrioritySoundRequested) {
            m_nHighestPrioritySoundRequested = nSoundType;
        }
    }


    /**
     * Checks whether Erix has reached the boundary of the unsecured area.
     * During a move, if Erix reaches the boundary of the unsecured area, it
     * indicates the completion of Erix's move. In this case, the GameEngine
     * requests the playing of the 'Region secured' sound, and proceeds with
     * the processing required for the completed move.
     * @return Returns if Erix has reached the boundary of the unsecured area
     * or not.
     */
    private boolean hasReachedBoundary() {
        //boolean bReturnValue = false;
        //try{
            //int nRow = m_objErix.m_nErixYPos;
            //int nXPos = m_objErix.m_nErixXPos;
            //int nCol = nXPos >> 3;
            //int nBit = nXPos % 8;

            //bReturnValue = GameEngine.inSecuredRegion(m_arrSecuredRegionBmp, nRow, nCol, nBit);
            return (GameEngine.inSecuredRegion(m_arrSecuredRegionBmp,
            	m_objErix.m_nErixYPos, m_objErix.m_nErixXPos >> 3, m_objErix.m_nErixXPos % 8));

        //}catch(Exception e){
            //System.out.println("Exception in hasReachedBoundary() - "+e);
        //}
        //return bReturnValue;
    }



    /**
     * This method is used check if the given row, column & bit position is set
     * in the bitmap.
     * @param arrBitmap The bitmap in which the bit has to be checked is its
     * set or not.
     * @param nRow The row position of the bit to be checked.
     * @param nCol The column position of the bit to be checked.
     * @param nBit The bit position in a byte that has to be checked.
     * @return Indicates if the particluar bit was set or not.
     */
    public static boolean inSecuredRegion(byte[][] arrBitmap, int nRow, int nCol, int nBit) {
        boolean bReturnValue = false;
        try {
            byte bytSecured = arrBitmap[nRow][nCol];

            switch(nBit) {
                case 0:
                    bytSecured &= Erix.ZERO_BIT_SET;
                    if(bytSecured == Erix.ZERO_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 1:
                    bytSecured &= Erix.FIRST_BIT_SET;
                    if(bytSecured == Erix.FIRST_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 2:
                    bytSecured &= Erix.SECOND_BIT_SET;
                    if(bytSecured == Erix.SECOND_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 3:
                    bytSecured &= Erix.THIRD_BIT_SET;
                    if(bytSecured == Erix.THIRD_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 4:
                    bytSecured &= Erix.FOURTH_BIT_SET;
                    if(bytSecured == Erix.FOURTH_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 5:
                    bytSecured &= Erix.FIFTH_BIT_SET;
                    if(bytSecured == Erix.FIFTH_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 6:
                    bytSecured &= Erix.SIXTH_BIT_SET;
                    if(bytSecured == Erix.SIXTH_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                case 7:
                    bytSecured &= Erix.SEVENTH_BIT_SET;
                    if(bytSecured == Erix.SEVENTH_BIT_SET){
                        bReturnValue = true;
                    }
                    break;
                default:
                    break;
            }
        } catch(Exception e) {
            System.out.println("Exception in inSecuredRegion() - ");
            e.printStackTrace();
        }
        return bReturnValue;
    } // end of method inSecuredRegion


    /**
     * Identifies the two regions in which the unsecured area is divided after
     * the successful completion of a move by Erix.
     * The logic used is to go round all the vertices of unselected region in a
     * sequential order.
     * If either the start or the end vertex of Erix lies between 2 boundary
     * points of the unselected region, then note down the previous & the next
     * points corresponding to that vertex.
     * For example if the unselected region was U0, U1, .... Un, U0 and the
     * Erix's path was P0, P1, P2 ... Pn. The last point int he unselected
     * region array would be the first point again in order to complete the
     * cycle.
     * Now if the start point P0 lies between U1 & U2 and the end point lies
     * between U5 & U6.
     * Therefore Region 1 would be U0, U1, P0, P1, P2, .... Pn, U6, U7, ... Un,
     * U0 and Region 2 would be P0, P1, .... Pn, U5, U4, U3, U2, P0.
     * Also care has to be taken to check if Erix's path has to be considered
     * in a reverse order.
     * Another case to take care is if either the start or end point are exactly
     * a vertex in the unselected region.
     */
    private void identifyRegions() {

        //Starting X coordinate of Erix's path.
        int nErixStartX = m_objErix.m_arrErixPath[0][0];

        //Starting Y coordinate of Erix's path.
        int nErixStartY = m_objErix.m_arrErixPath[0][1];

        //Ending X coordinate of Erix's path.
        int nErixEndX = m_objErix.m_arrErixPath[m_objErix.m_nNumberOfVertices-1][0];

        //Ending Y coordinate of Erix's path.
        int nErixEndY = m_objErix.m_arrErixPath[m_objErix.m_nNumberOfVertices-1][1];

        // The serial number of the point on the unselected region boundary,
        // that occurs previous to Erix's starting point.
        int nStartPrevPoint = -1;

        // The serial number of the point on the unselected region boundary,
        // that occurs next to Erix's starting point.
        int nStartNextPoint = -1;

        // The serial number of the point on the unselected region boundary,
        // that occurs previous to Erix's ending point.
        int nEndPrevPoint = -1;

        // The serial number of the point on the unselected region boundary,
        // that occurs next to Erix's ending point.
        int nEndNextPoint = -1;

        // Flag to indicate whether Erix's path has to be considered
        // in reversed order of its vertices' serial numbers, or not.
        boolean bReverseErixPath = false;

        // Flag to indicate whether the unselected path has
        // 3 consecutive points in a straight line.
        // If true then the point in-between has to be eliminated
        // from the Unselected path.
        boolean bCheckUnselectedPath = false;

        int nCount = 0;
        int nLargerVal;
        int nSmallerVal;

        for(int i = 0; i < m_nUnSelectedRegionPoints-1; i++){

            //Checking if the start point coincides with the current vertex.
            if(nErixStartX == m_arrUnSelectedRegion[i][0]
               && nErixStartY == m_arrUnSelectedRegion[i][1]){
                nStartPrevPoint = i-1;
                nStartNextPoint = i+1;
                nCount++;
                bCheckUnselectedPath = true;
            }

            //Checking if the end point coincides with the current vertex.
            if(nErixEndX == m_arrUnSelectedRegion[i][0]
               && nErixEndY == m_arrUnSelectedRegion[i][1]){
                nEndPrevPoint = i-1;
                nEndNextPoint = i+1;
                if(nCount == 0){
                    bReverseErixPath = true;
                }
                nCount++;
                bCheckUnselectedPath = true;
            }

            //If both start & end points have been processed then exit loop.
            if(nCount == 2){
                break;
            }

            //Processing for Vertical edges.
            if(m_arrUnSelectedRegion[i][0] == m_arrUnSelectedRegion[i+1][0]){

                if(nEri

⌨️ 快捷键说明

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