?? myplayer.java
字號:
if((st&GameCanvas.DOWN_PRESSED)!=0){
if(player_y+1<=maph-imgh) { sy=speed;}
this.setFrame(3+xn*(step++%4)); }//下
if(st== 6){ this.setFrame(6+xn*(step++%4)); }//左上
if(st==68){ this.setFrame(7+xn*(step++%4)); }//左下
if(st==34){ this.setFrame(5+xn*(step++%4)); }//右上
if(st==96){ this.setFrame(4+xn*(step++%4)); }//右下
if((st&GameCanvas.DOWN_PRESSED)!=0||(st&GameCanvas.UP_PRESSED)!=0||(st&GameCanvas.RIGHT_PRESSED)!=0||(st&GameCanvas.LEFT_PRESSED)!=0)
{}
else{step=0;this.setFrame(2*xn+3);
switch (action){
case 2: this.setFrame(2*xn+1);break;
case 64:this.setFrame(2*xn+3);break;
case 4: this.setFrame(2*xn+2);break;
case 32:this.setFrame(2*xn+0);break;
case 6: this.setFrame(2*xn+6);break;
case 68:this.setFrame(2*xn+7);break;
case 34:this.setFrame(2*xn+5);break;
case 96:this.setFrame(2*xn+4);break;
}
}//什么都沒按圖片的步長記錄設為0
}
//////////////////
private void goHome(){//回城
MyControl.load.backMapId=0;
MyControl.gameBoard.boardInit();
}
/////////
private void playerAddHp(int addhp){//加紅
playerHp+=addhp;
playerHp=playerHp<this.playerMaxHp?playerHp:this.playerMaxHp;
}
///////
private void playerAddMp(int addmp){//加藍
playerMp+=addmp;
playerMp=playerMp<this.playerMaxMp?playerMp:this.playerMaxMp;
}
/////////
/////////////////////
public int getPlayer_x() {
return player_x;
}
public int getplayer_y() {
return player_y;
}
////////////////
public void showPlayerHpMp(Graphics g){//顯示玩家的生命和體力.
int d=16;
g.setColor(0xffff00);
g.drawRect(10,h-d-1,50,5);
g.drawRect(10,h-d/2-1,50,5);
g.drawRect(w>>1,h-d/2-1,50,5);
g.setColor(0xff0000);
g.fillRect(11,h-d,this.playerHp*50/this.playerMaxHp,4);//生命
g.setColor(0x0000ff);
g.fillRect(11,h-d/2,this.playerMp*50/this.playerMaxMp,4);//Mp
g.drawString("L-"+playerLevel,w-30,h-d,0);
g.setColor(0x00ffff);
g.fillRect(w>>1,h-d/2,this.playerEx*50/playerNextEx,4);//經驗
cur.findGoodShow(g);//發現物品。
if(playerHp>0){
if(playerBooty){//獲得戰利品????//一次打一個怪時可得好幾個。以后要修正。
cur.findGoods();
cur.findGood = true;
cur.findGoodShow(g);
playerBooty = false;
if(playerEx>playerNextEx){playerNewMen();}//長級
}
}else{
this.goHome();//玩家死后回村
playerHp=1;
// isWarfare=false;
}
}
//////////////////
private void pressA_NpcSpeak(int st){//按1和npc說話。
switch(pressA(st)){
case 2:speakSure=true;break;
case 3:
{
if(hitSmith){showBuyGrid=true;isShowGrid=true;speakSure=false;break;}//如果碰的的鐵匠的就顯示
if(hitDrugstore) {showBuyGrid=true;isShowGrid=true;speakSure=false;break;}//如果碰撞的是藥店的人顯示藥店的。
pressA_Num=1;
speak_Num=-1;
speakSure=false;
}
default:break;
}
}
/////////////////////////////
public void showDrugstoreGrid(Graphics g){//顯示藥店的物品欄
if(hitDrugstore && showBuyGrid)
{ cur.DrugstoreGrid(g,curSwap);//寫字//畫物品//畫光標
}
}
////////////////////////
public void showSmithGrid(Graphics g){//顯示鐵匠的物品欄
if(hitSmith && showBuyGrid){
cur.SmithGrid(g,curSwap);//寫字//畫物品//畫光標
}
}
///////////////
public void showPlayerGrid(Graphics g){//顯示玩家的物品欄,在gameboard.draw 下被調用。
if(isShowGrid){this.showPlayerArmsGrid(g);////顯示玩家的屬性欄
cur.PlayerGrid(g,curSwap);//在玩家物品欄,和上面的光標
}
}
///////////////////
public void changPlayerAttribute(Vector gvs,int Pnum){//改變玩家的屬性。
// "綠石","銅戒","小紅","小藍","辯認",
// "紅石","銀戒","中紅","中藍","回城",
// "藍石","金戒","大紅","大藍","骷髏",
// "粉石","鉆戒","戰甲","頭盔","鋼靴",
// "戰手","長劍","戰盾","戰盔","戰靴",
// "護手","青鋒","莫邪","腰帶","古書",
int number=((Goods)gvs.elementAt(Pnum)).number;
switch(number){
case 2: ((Goods)gvs.elementAt(Pnum)).n--; playerAddHp(50); break;//加紅
case 7: ((Goods)gvs.elementAt(Pnum)).n--; playerAddHp(100); break;
case 12: ((Goods)gvs.elementAt(Pnum)).n--; playerAddHp(200); break;
case 3: ((Goods)gvs.elementAt(Pnum)).n--; playerAddMp(30); break;//加藍
case 8: ((Goods)gvs.elementAt(Pnum)).n--; playerAddMp(60); break;
case 13: ((Goods)gvs.elementAt(Pnum)).n--; playerAddMp(120); break;
case 9:
if(MyControl.load.backMapId!=0){
((Goods)gvs.elementAt(Pnum)).n--;
pressB();
goHome(); }
break;//回城
default: break;
}
}
public int hitBox(Box box[]){//與箱子的碰撞.
int b=-1;
for(int i=0;i<box.length;i++)
{if(collidesWith(box[i],true))
{b=i;
return b; }
}
return b;
}
///////////////////////////
private void showPlayerArmsGrid(Graphics g){//顯示玩家的屬性欄
Image grid0=MyControl.load.gridImg[0];//屬性欄
int d=15;//行距
int grid0x=w-grid0.getWidth();
int grid0y=h-grid0.getHeight();
int BuyGridxPos=grid0x+5,BuyGridyPos=grid0y+6;
g.drawImage(grid0,grid0x,grid0y,Graphics.LEFT|Graphics.TOP);
g.setColor(0xffffff);
g.drawString(playerName,BuyGridxPos,BuyGridyPos+5*d,0);
g.drawString(playerLevel+"級",BuyGridxPos+4*d,BuyGridyPos+5*d,0);
g.drawString("HP "+playerHp+"/"+playerMaxHp,BuyGridxPos,BuyGridyPos+6*d,0);
g.drawString("MP "+playerMp+"/"+playerMaxMp,BuyGridxPos+3*d,BuyGridyPos+6*d,0);
g.drawString("攻"+playerHit,BuyGridxPos,BuyGridyPos+7*d,0);
g.drawString("防"+playerRecovery,BuyGridxPos+3*d,BuyGridyPos+7*d,0);
g.drawString("經驗: "+playerEx+"/"+playerNextEx,BuyGridxPos,BuyGridyPos+8*d,0);
g.drawString("金幣: "+cur.getPlearMoney(),BuyGridxPos,BuyGridyPos+9*d,0);
}
//////////////
////按 3 時,關閉所有打開的窗口。
private void pressB(){
showBuyGrid=false;//關閉買賣物品窗口。
isShowGrid=false;//關閉玩家屬性窗口.
speakSure=false;//關閉對話窗口。
speak_Num=-1;//為說話的選取給初值。
pressA_Num=1;//為按1鍵的次數給初值。
cur.setCurx();cur.setCury();cur.setNum(0);//給買賣物品欄給初值。
curSwap=false;//給交換窗口的開關給初值。
}
int orientation=-1;
/////////////
private void playerWar(int st){//戰斗狀態。
int xn=16;
sx=0;sy=0;
if((st&GameCanvas.RIGHT_PRESSED)!=0){
if(player_x+1<=mapw-imgw) { sx=speed;}//邊界檢測//????????????????????????????????????????????????????????
this.setFrame(8+xn*(step++%4)); }//右 //這里要修正:視窗沒到邊界時,這里可不用檢測.
if((st&GameCanvas.LEFT_PRESSED)!=0){
if(player_x-1>=2) { sx=-speed;}
this.setFrame(10+xn*(step++%4)); }//左
if((st&GameCanvas.UP_PRESSED)!=0){
if(player_y-1>=0) {sy=-speed;}
this.setFrame(9+xn*(step++%4)); }//上
if((st&GameCanvas.DOWN_PRESSED)!=0){
if(player_y+1<=maph-imgh) { sy=speed;}
this.setFrame(11+xn*(step++%4)); }//下
if(st== 6){ this.setFrame(14+xn*(step++%4)); }//左上
if(st==68){ this.setFrame(15+xn*(step++%4)); }//左下
if(st==34){ this.setFrame(13+xn*(step++%4)); }//右上
if(st==96){ this.setFrame(12+xn*(step++%4)); }//右下
if((st&GameCanvas.DOWN_PRESSED)!=0||(st&GameCanvas.UP_PRESSED)!=0||(st&GameCanvas.RIGHT_PRESSED)!=0||(st&GameCanvas.LEFT_PRESSED)!=0){}
else{ step++;
switch(action){
case 2: this.setFrame(xn*(step%4)+9);break;
case 64:this.setFrame(xn*(step%4)+11);break;
case 4: this.setFrame(xn*(step%4)+10);break;
case 32:this.setFrame(xn*(step%4)+8);break;
case 6: this.setFrame(xn*(step%4)+14);break;
case 68:this.setFrame(xn*(step%4)+15);break;
case 34:this.setFrame(xn*(step%4)+13);break;
case 96:this.setFrame(xn*(step%4)+12);break;
}
}
}
////////////
public void playerAction(int st,int mapw,int maph,Box box[],Monsters monsterCaves,Monsters monsters){
if((!isShowGrid)&&(!isWarfare)){playerMove(st,mapw,maph);}//如果顯示屬性欄,人物不能移動。
else {sx=0;sy=0;}//防止走動時,按開物品欄后,人會走個不停。
if((st!=0)&&((st&GameCanvas.GAME_A_PRESSED)==0)){action=st;}//記錄當前的按鍵方向
if(isWarfare){
playerWar(st);
if(playerMp>0) {//如果 Mp 沒有就不能攻擊。
int mapId=MyControl.load.backMapId;
switch(mapId){
case 1: monsters.hitPlayer(this); break;//村外
case 2: monsterCaves.hitPlayer(this); break;//山洞
default: isWarfare=false; break;//防止在村中觸發戰斗狀態。
}
}else{
isWarfare=false;
}
}
//在不與npc相碰撞時,按 7 鍵,打開玩家自已的物品欄。
if(((st&GameCanvas.GAME_C_PRESSED)!=0)&&(!hitNpcOk)){//打開玩家屬性欄。
this.isShowGrid=true; //將物品欄的開關分開設
curSwap=true;//給交換窗口的開關給初值。
}
//在交易狀態下,按 9 鍵,在交易欄和玩家物品欄間交換光標。
if((st&GameCanvas.GAME_D_PRESSED)!=0){
if((showBuyGrid)){curSwap=!curSwap;} }
//所有的取消都有 3 鍵
if((st&GameCanvas.GAME_B_PRESSED)!=0){ pressB(); }//窗口的取消。
//所有的確認鍵,都用 1 鍵;
//(1) 與npc 說話
if(hitNpcOk){pressA_NpcSpeak(st);}//與npc 說話的確認。在與NPC相碰撞時才可以確認說話,否則無效。
//(2) 在打開玩家物品欄時。(包括交易狀態)
if((isShowGrid))
{ if(curSwap){//在交易狀態下,光標在玩家物品欄時,按1就是賣。交易欄沒開,光標在玩家物品欄,按1就是使用。
cur.curPlayerGridAction(st,showBuyGrid);}
else{//在交易狀態下的按鍵的移動按1就是買。//光標在交易欄中
cur.curNpcGridAction(st,hitDrugstore, hitSmith ); }
}
if((st&GameCanvas.GAME_A_PRESSED)!=0){
//箱子的碰撞
int mapId=MyControl.load.backMapId;
int b=hitBox(box);
if(b>=0){ cur.playerHitBox(box[b]); }
//與怪物相遇,按1鍵就攻擊。
if(mapId!=0) isWarfare=true;
}//end press A
}//end playerAction
///////////
/////////
}//end player
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -