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

📄 prince.java

📁 一个j2me游戏代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	{
        //clear flags in last frame
        blocked = false;
		if (m_flag[3] == false)
			return false;
		if (m_frameIndex == -1)
			return false;
		super.updateAI(camX, camY);
		// energy
		if (m_energy < m_maxEnergy)
			m_energy ++;
		// invincible
		if (m_counter > 0)
		    m_counter--;
		// reborn
		if (m_showDirection > 0)
		    m_showDirection--;
		/*debug
		if(GE.Lyman == 5)
		{
			for (int i = 1; i < ABILITY_NUMBER; i++)
			{
				if (ability[i] == 0)
		            enableAbility(i);
			}
			enableAbility(0);
		}//*/
		curState = nextState = m_actionIDNow;

		switch(curState)
		{
			//case Def.PRINCE_HIDE:
			//	stopAction(false);
			//	break;
			case Def.PRINCE_FLASH:
				if (m_actionOver)
					nextState = Def.PRINCE_NORMAL;//fall in case no road behind prince
			case Def.PRINCE_NORMAL:
                //definitely don't jump some tutorials
                if (noJump) break;
				if (m_phbBottom < Def.PHB_BOX)
				{
					nextState = Def.PRINCE_FALL;
				}
				else if (GE.m_input[Def.KEY_D] == Def.Dn_Instant && m_phbBottom == Def.PHB_SOLID)
				{
					if(checkGround(false) == 2)
					{
						setFlipX(true);
					}
					else if(checkGround(true) == 2)
					{
						setFlipX(false);
					}
					else break;
					m_posX = m_grabPosX;
					m_posY = m_grabPosY;
					nextState = Def.PRINCE_CLIMBDOWN;
				}
				else if(GE.m_input[Def.KEY_L] >= Def.Dn_Instant || GE.m_input[Def.KEY_R] >= Def.Dn_Instant)
				{
                    setFlipX(GE.m_input[Def.KEY_L] >= Def.Dn_Instant);
                    checkRoll();
				}
				else if(GE.m_input[Def.KEY_U] == Def.Dn_Instant)
				{
					if (checkClimbUp())
					{
						m_posX = m_grabPosX;
						m_posY = m_grabPosY;
						curState = nextState = Def.PRINCE_CLIMBUP;
                        setAction(Def.PRINCE_CLIMBUP, 1);
						nextFrame(true);
						nextFrame(true);
					}
					else if (scanPhb4Grab())
						nextState = Def.PRINCE_JUMP_UP;
					else
					    nextState = Def.PRINCE_JUMP_AHEAD;
				}
                else if (ability[CAN_SWORD] > 0 && GE.m_input[Def.KEY_ATTACK] == Def.Dn_Instant)
                    nextState = Def.PRINCE_STRIKE;
				break;

			case Def.PRINCE_RUN:
				if (m_phbBottom < Def.PHB_BOX)
				{
					nextState = Def.PRINCE_FALL;
				}
				else if (checkRoll())
				{
				}
				else if (GE.m_input[Def.KEY_U] == Def.Dn_Instant)
				{
					nextState = Def.PRINCE_JUMP_AHEAD;
				}
				else if(GE.m_input[Def.KEY_L] < Def.Dn_Instant && GE.m_input[Def.KEY_R] < Def.Dn_Instant ||
						m_flag[0] != (GE.m_input[Def.KEY_L] >= Def.Dn_Instant))
				{
					nextState = Def.PRINCE_NORMAL;
				}
				break;

            case Def.PRINCE_ROLL_READY:
                if (m_actionOver)
                    nextState = Def.PRINCE_ROLL;
                break;

            case Def.PRINCE_ROLL:
                if (m_phbBottom < Def.PHB_BOX)
                {
                    nextState = Def.PRINCE_FALL;
					byte[] box = getColBox();
					m_posY += ((box[3] - box[1])/2) << 8;
                    break;
                }
                if (comsumeEnergy(ENERGY_ROLL) > 0 && (GE.m_input[Def.KEY_L] == Def.Dn_Continuous2 || GE.m_input[Def.KEY_R] == Def.Dn_Continuous2))
                {
                    //setFlipX(GE.m_input[Def.KEY_L] == Def.Dn_Continuous2);
                    //setAction(Def.PRINCE_ROLL, true);
                }
                else if(GE.m_input[Def.KEY_L] >= Def.Dn_Instant || GE.m_input[Def.KEY_R] >= Def.Dn_Instant)
                {
                    setFlipX(GE.m_input[Def.KEY_L] >= Def.Dn_Instant);
                    nextState = Def.PRINCE_NORMAL;
                }
                else
                    nextState = Def.PRINCE_NORMAL;
				break;

			case Def.PRINCE_JUMP_UP:
				m_vX = (m_grabPosX - m_posX) / 16;
				if (checkHang() || m_phbTop >= Def.PHB_BOX || m_vY >= 0)
				{
					if (!tryHang())
					    nextState = Def.PRINCE_FALL;
				}
				break;

			case Def.PRINCE_JUMP_AHEAD:
		        /*if (GE.m_input[Def.KEY_U] >= Def.Dn_Instant && m_phbBottom == Def.PHB_WALLING && ability[CAN_WALLING] > 0)
		        {
					if (ability[MORE_ENERGY] > 0)
					    nextState = Def.PRINCE_WALLING_MORE;
					else
		                nextState = Def.PRINCE_WALLING;
					break;
				}*/
			case Def.PRINCE_WALLFLY:
			    if (m_vY > 0x1200)
				{
					setAction(Def.PRINCE_FALL, 1);
					curState = nextState = Def.PRINCE_FALL;
					stopAction(false);
				}
			case Def.PRINCE_FALL:
				if(checkHang())
				{
					if (!noGrab && tryHang()) break;
				}
                if(GE.m_input[Def.KEY_U] == Def.Dn_Instant)
                {
                    if (checkWallJump())
                    {
                        noGrab = false;
                        break;
                    }
                    else if (checkClimbUp())
                    {
                        m_posX = m_grabPosX;
                        m_posY = m_grabPosY;
                        curState = nextState = Def.PRINCE_CLIMBUP;
                        setAction(Def.PRINCE_CLIMBUP, 1);
                        nextFrame(true);
                        nextFrame(true);
                        nextFrame(true);
                        break;
					}
					//***** no walling more **********
                    if (m_actionIDNow != Def.PRINCE_WALLFLY && m_phbBottom == Def.PHB_WALLING && ability[CAN_WALLING] > 0)
                    {
                        noGrab = false;
                        nextState = Def.PRINCE_WALLING;
                        break;
                    }
					//*******************************/
                }
				if (m_vY >= 0 && m_phbBottom >= Def.PHB_BOX)
                {
                    noGrab = false;
					nextState = Def.PRINCE_LAND;
                }
				break;

			case Def.PRINCE_WALLING:
			//case Def.PRINCE_WALLING_MORE:
				if (comsumeEnergy(ENERGY_WALLING) == 0 || GE.m_input[Def.KEY_U] < Def.Dn_Continuous ||
                    m_phbBottom != Def.PHB_WALLING || m_phbLeft >= Def.PHB_BOX ||
                    m_phbRight >= Def.PHB_BOX || blocked)
				{
					nextState = Def.PRINCE_FALL;
				}
				break;

			case Def.PRINCE_WALLJUMP:
				if (m_actionOver)
				{
					nextState = (m_energy == 0 ? Def.PRINCE_FALL: Def.PRINCE_WALLFLY);
				}
				break;

			case Def.PRINCE_HANG:
				if (GE.m_input[Def.KEY_U] == Def.Dn_Instant)
				{
					nextState = Def.PRINCE_CLIMBUP;
				}
				else if (GE.m_input[Def.KEY_D] == Def.Dn_Instant)
				{
                    noGrab = true;
                    //hard coded for face right hang
                    if (!m_flag[0]) m_posX -= (2<<8);
                    toFall();
				}
				else if (GE.m_input[Def.KEY_ATTACK] == Def.Dn_Instant)
				{
					m_camOffsetY = -m_camOffsetY;
				}
				break;

			case Def.PRINCE_LAND:
				if(m_actionOver)
				{
					nextState = Def.PRINCE_NORMAL;
				}
				break;

			case Def.PRINCE_CLIMBDOWN:
				//if(m_actionOver)
                if( m_frameIDNow == m_anim.nFrame[m_actionIDNow] -1 )
                {
					if (!tryHang())
                    {
                        toFall();
                    }
                }
                break;

			case Def.PRINCE_CLIMBUP:
				//if(m_actionOver)
                if( m_frameIDNow == m_anim.nFrame[m_actionIDNow] -1 )
				{
					m_posX += (m_flag[0]?-2:2) << 8;
					nextState = Def.PRINCE_NORMAL;
				}
                break;

			case Def.PRINCE_STRIKE:
				if (m_actionOver)
                {
                    //if (GE.m_input[Def.KEY_ATTACK] == Def.Dn_Instant)
					//	curState = Def.PRINCE_NORMAL;
                    //else
                        nextState = Def.PRINCE_NORMAL;
                }
				break;

            case Def.PRINCE_LASTSTRIKE:
                if (m_actionOver)
                {
                    m_vX = 0;
                    nextState = Def.PRINCE_LASTSTRIKE2;
                }
                break;

			case Def.PRINCE_LASTSTRIKE2:
                if (m_actionOver)
                {
                    //m_vX = 0; // stop moving for dagger
                    //if (GE.m_input[Def.KEY_ATTACK] <= Def.Dn_Instant)
					//    nextState = Def.PRINCE_NORMAL;
                }
				break;

			case Def.PRINCE_PULL:
			case Def.PRINCE_PUSH:
				followBox();
				if (m_relativeMisc != null)
				{
					if (m_vX == 0 ||
					   (m_actionIDNow == Def.PRINCE_PUSH &&
						   (m_flag[0] && GE.m_input[Def.KEY_L] <= Def.Up_Continuous ||
						   !m_flag[0] && GE.m_input[Def.KEY_R] <= Def.Up_Continuous)) ||
					   (m_actionIDNow == Def.PRINCE_PULL &&
						   (!m_flag[0] && GE.m_input[Def.KEY_L] <= Def.Up_Continuous ||
							 m_flag[0] && GE.m_input[Def.KEY_R] <= Def.Up_Continuous || !checkDragMove())))
					{
						nextState = Def.PRINCE_READY_PULL_PUSH;
						m_relativeMisc.m_vX = 0;
					}
				}
				break;

			case Def.PRINCE_READY_PULL_PUSH:
				if (GE.m_input[Def.KEY_L] >= Def.Dn_Instant || GE.m_input[Def.KEY_R] >= Def.Dn_Instant)
				{
                    boolean left = GE.m_input[Def.KEY_L] >= Def.Dn_Instant;
                    if (left && m_posX > m_relativeMisc.m_posX ||
                       !left && m_posX < m_relativeMisc.m_posX)//prince on right
                    {
                        nextState = Def.PRINCE_PUSH;
                    }
                    else
                    {
                        if (checkDragMove())
                            nextState = Def.PRINCE_PULL;
                        else
                            break;
                    }
                    setAction(nextState, 1);
					curState = nextState;
                    followBox();
				}
				else if(GE.m_input[Def.KEY_ATTACK] >= Def.Dn_Instant || GE.m_input[Def.KEY_D] >= Def.Dn_Instant)
				{
					nextState = Def.PRINCE_NORMAL;
					m_relativeMisc.m_vX = 0;
					m_posX += m_flag[0]?-(GE.m_tileWidth>>2)<<8:(GE.m_tileWidth>>2)<<8;//make prince close to box
				}
				else if (GE.m_input[Def.KEY_U] >= Def.Dn_Instant && checkClimbUp())
				{
					m_posX = m_grabPosX;
					m_posY = m_grabPosY;
					curState = nextState = Def.PRINCE_CLIMBUP;
                    setAction(Def.PRINCE_CLIMBUP, 1);
                    nextFrame(true);
                    nextFrame(true);
					//nextState = Def.PRINCE_CLIMBUP;
				}
				break;

			case Def.PRINCE_HURT:
			case Def.PRINCE_FLASH2:
				if(m_actionOver)
				{
					//if (m_phbBottom < Def.PHB_SOLID)
					//    nextState = Def.PRINCE_FALL;//fall in case no road behind prince
					//else
					nextState = Def.PRINCE_NORMAL;//fall in case no road behind prince
				}
				break;

			case Def.PRINCE_DIE:
				if(m_actionOver && m_vY == 0)
				{
					if (m_bornTimes > BORN_LIMIT)
					{
                        Pop2MIDlet.m_ge.levelFinished(false);
					}
					else
					{
						Player.updateCheckPoint(false);
						m_posX = m_start1;
						m_posY = m_start2;
						setFlipX(bornFlipX);
						initAI();
						m_showDirection = SHOWDIRECTION_FRAMES * 2;
                        checkTopBottom(CHECK_BOTTOM, true);
						Player.updateCamera(true);
						setAction(Def.PRINCE_FLASH, 1);
					}
				}
				break;
		}
		if (curState != nextState)
		{
			setAction(nextState, 1);
			if (nextState == Def.PRINCE_STRIKE)
            {
			    //GE.playSound(Def.SOUND_STRIKE_MID, 1);
            }
			else if (nextState == Def.PRINCE_FALL)
            {
				m_posY += 0x100;
				m_vX /= 2;
				stopAction(false);
            }
			else if (nextState == Def.PRINCE_NORMAL)
  				checkEnvironment(true);
			else if (nextState == Def.PRINCE_HANG || nextState == Def.PRINCE_JUMP_UP
			    || nextState == Def.PRINCE_JUMP_AHEAD)
			    stopAction(false);
		}
		// change the cam position
		if (nextState == Def.PRINCE_CLIMBDOWN || nextState == Def.PRINCE_FALL)
			m_camOffsetY = -CAM_OFFSETY;
		else if (nextState == Def.PRINCE_HANG && curState == Def.PRINCE_FALL)
		{
			m_camOffsetY = CAM_OFFSETY;
		}
		else if (nextState != Def.PRINCE_HANG)
		{
			if (m_flag[0])
	            m_camOffsetX = -CAM_OFFSETX;
			else
	            m_camOffsetX = CAM_OFFSETX;
			m_camOffsetY = CAM_OFFSETY;
		}
		if (GE.m_input[Def.KEY_D] >= Def.Dn_Instant)
            m_camOffsetY = -CAM_OFFSETY;
        else if (GE.m_input[Def.KEY_L] >= Def.Dn_Instant)
			m_camOffsetX = -CAM_OFFSETX;
		else if (GE.m_input[Def.KEY_R] >= Def.Dn_Instant)
			m_camOffsetX = CAM_OFFSETX;
		return true;
	}
	public void draw(int camX, int camY)
	{
		if (m_counter % 2 == 1 && GE.m_msgIndex < 0)
	        nextFrame(false);
		else
 	        super.draw(camX, camY);
	}
}

⌨️ 快捷键说明

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