?? rpgcanvas.java
字號:
menuState = MENU_START;
break;
}
break;
case FIRE_PRESSED:
switch (menuState) {
case MENU_START:
if(!isFirstStart)reinit();
gameState = GAME_START;
isFirstStart = false;
removeCommand(backGame);
this.addCommand(mainMenu);
break;
case MENU_LOAD:
loadGame();
isFirstStart = false;
gameState = GAME_START;
removeCommand(backGame);
this.addCommand(mainMenu);
break;
case MENU_VOL:
isVolOn = !isVolOn;
// isFirstStart = false;
playVol();
break;
case MENU_QUIT:
this.midlet.exitMIDlet();
break;
case MENU_ABOUT:
gameState = GAME_ABOUT;
gameAboutY = 0;
break;
case MENU_SAVE:
saveGameState();
gameState = GAME_START;
break;
}
break;
}
}
//進入游戲介紹狀態
else if(gameState == GAME_ABOUT){
switch(key){
case UP_PRESSED:
gameAboutY += fHeight;
if(gameAboutY >= 0)gameAboutY = 0;
break;
case DOWN_PRESSED:
gameAboutY -= fHeight;
if(gameAboutY <= screenheight - tempH)gameAboutY = screenheight -tempH;
break;
default:
break;
}
}
//進入游戲狀態
else if (gameState == GAME_START) {
//輸入模式為0時
if (inputmode == 0) {
if ((key & FIRE_PRESSED) != 0) {
System.out.println("@@@@@@@@");
ismessage = false;
load.npc[0].pause = false;
if (isSoldier) {
// isAttack = true;
isChoose = true;
inputmode = 1;
choose1 = "攻擊";
choose2 = "放棄";
}
else if (isProperty) {
isProperty = false;
if (isBoss) {
isChoose = true;
inputmode = 1;
choose1 = "攻擊";
choose2 = "放棄";
} else if (isFood) {
load.property[2].setVisible(false);
randX = getrand(480);
randY = getrand(450);
roleBloodHeight += 3;
if (roleBloodHeight > 40)
roleBloodHeight = 40;
load.property[2] = new Property(load.food, randX,
randY);
isFood = false;
} else if (isSword) {
load.property[3].setVisible(false);
mroleProperty[1]++;
isSword = false;
}
else if (isGold) {
load.property[5].setVisible(false);
randX = getrand(480);
randY = getrand(450);
load.property[5] = new Property(load.gold, randX,
randY);
isGold = false;
mroleProperty[4]++;
}
else if (catchcat) {
load.property[0].setVisible(false);
catchcat2 = true;
catchcat = false;
}
}
else if (iscollide == true) {
showyesorno = true;
inputmode = 1;
choose1 = "好的";
choose2 = "不了";
}
else if (isSeller) {
inputmode = 3;
choose1 = "買";
choose2 = "賣";
choose3 = "放棄";
sellerAsk = true;
isSeller = false;
}
}
//
// else if((key & GAME_A_PRESSED) != 0){
// isJump = true;
// }
else if ((key & UP_PRESSED) != 0) {
// System.out.println(key);
mrole.setFrame(mrole.directionup++);
if (mrole.directionup > 15)
mrole.directionup = 12;
if (mrole.y - 4 <= 0)
mrole.y = 0;
else
mrole.move(0, -4);
if (screeny - 4 > 0)
screenmove(0, -4);
else
screeny = 0;
}
else if ((key & DOWN_PRESSED) != 0) {
mrole.setFrame(mrole.directiondown++);
if (mrole.directiondown > 3)
mrole.directiondown = 0;
if (mrole.y + 24 + 4 >= imgbackgroundheight)
mrole.y = imgbackgroundheight - 24;
else
mrole.move(0, 4);
if (screeny + 4 + screenheight < imgbackgroundheight)
screenmove(0, 4);
else
screeny = imgbackgroundheight - 3 - 177;
}
else if ((key & LEFT_PRESSED) != 0) {
mrole.setFrame(mrole.directionleft++);
if (mrole.directionleft > 7)
mrole.directionleft = 4;
if (mrole.x - 4 <= 0)
mrole.x = 0;
else
mrole.move(-4, 0);
if (screenx - 4 > 0)
screenmove(-4, 0);
else
screenx = 0;
}
else if ((key & RIGHT_PRESSED) != 0) {
mrole.setFrame(mrole.directionright++);
if (mrole.directionright > 11)
mrole.directionright = 8;
if (mrole.x >= imgbackgroundwidth - 16 - 4)
mrole.x = imgbackgroundwidth - 16;
else
mrole.move(4, 0);
if (screenx + 4 + screenwidth < imgbackgroundwidth)
screenmove(4, 0);
else
screenx = imgbackgroundwidth - 4 - screenwidth;
}
// System.out.println(key);
}
//輸入模式為1, 即游戲對話存在兩種選擇時
else if (inputmode == 1) {
if ((key & DOWN_PRESSED) != 0) {
selecty += 10;
if (selecty >= 162) {
selecty = 162;
}
}
else if ((key & UP_PRESSED) != 0) {
selecty -= 10;
if (selecty <= 152) {
selecty = 152;
}
}
else if ((key & FIRE_PRESSED) != 0) {
inputmode = 0;
// ismessage = false;
//選擇第一項時
if (selecty == 152) {
if (isSoldier) { //與野怪接觸時
isAttack = true;
isChoose = false;
warEnd = true;
tempNum = getrand(3);
removeCommand(mainMenu);
} else if (isBoss) { //與boss接觸
isBossAttack = true;
isChoose = false;
isBoss = false;
warEnd = false;
tempNum = getrand(4);
removeCommand(mainMenu);
}
else if(isSelectAttack){
// isSelectAttack = false;
isChoose = false;
isJump = true;
attackWidth = 70;
attackHeight = 64;
}
else if (forSell) { //與商人接觸 ,選擇賣商品時
if (mroleProperty[1] > 0) {
forSell = false;
isSell = false;
inputmode = 0;
mroleProperty[4]++;
mroleProperty[1]--;
} else
inputmode = 1;
} else { //與老人接觸
mainroleanswer = true;
missionmessage = "幫助老人找他的貓";
showyesorno = false;
}
}
//選擇第二項時
else if (selecty == 162) {
if (isSoldier) { //與野怪接觸
isAttack = false;
isChoose = false;
} else if (isBoss) { //與boss接觸
isBossAttack = false;
isChoose = false;
isBoss = false;
}
else if(isSelectAttack){
isSelectAttack = false;
isChoose = false;
roleAttack = true;
inputmode = 3;
}
else if (forSell) { //選擇賣商品時
forSell = false;
isSell = false;
inputmode = 0;
} else { //與老人接觸
mainroleanswer = false;
showyesorno = false;
}
// inputmode = 0;
}
}
// showyesorno = false;
}
//輸入模式為2時,即游戲進入場景2的狀態控制
else if (inputmode == 2) {
if ((key & UP_PRESSED) != 0) {
mrole.setFrame(mrole.directionup++);
if (mrole.directionup > 15)
mrole.directionup = 12;
if (mrole.roomy - 4 <= 0)
mrole.roomy = 0;
else
mrole.moveroom(0, -4);
}
if ((key & DOWN_PRESSED) != 0) {
mrole.setFrame(mrole.directiondown++);
if (mrole.directiondown > 3)
mrole.directiondown = 0;
if (mrole.roomy + 24 + 4 >= 177) {
mrole.roomy = 177 - 24;
} else
mrole.moveroom(0, 4);
}
if ((key & LEFT_PRESSED) != 0) {
mrole.setFrame(mrole.directionleft++);
if (mrole.directionleft > 7)
mrole.directionleft = 4;
if (mrole.roomx - 4 <= 0)
mrole.roomx = 0;
else
mrole.moveroom(-4, 0);
}
if ((key & RIGHT_PRESSED) != 0) {
mrole.setFrame(mrole.directionright++);
if (mrole.directionright > 11)
mrole.directionright = 8;
if (mrole.roomx >= 180 - 16 - 4)
mrole.roomx = 180 - 16;
else
mrole.moveroom(4, 0);
}
}
//輸入模式為3時,即對話具有三種選擇的狀態
if (inputmode == 3) {
if ((key & DOWN_PRESSED) != 0) {
attackSelecty += 10;
if (attackSelecty >= screenheight - 15) {
attackSelecty = screenheight - 15;
}
}
else if ((key & UP_PRESSED) != 0) {
attackSelecty -= 10;
if (attackSelecty <= screenheight - 35) {
attackSelecty = screenheight - 35;
}
}
else if ((key & FIRE_PRESSED) != 0) {
//選擇第一項時
// roleWord=" 星星燎燃 烈火濺射 深海狂嘯";
if (attackSelecty == screenheight - 15) {
if (isRoleAttack) { //與野怪或boss接觸 ,選擇第一招
tempNum = 6;
attackWidth = 80;
attackHeight = 80;
roleWord = "深海狂嘯";
roleBeat = true;
roleAttack = false;
isRoleAttack = false;
} else if (roleChoose) { //與商人接觸
roleChoose = false;
sellerAsk = false;
inputmode = 0;
} else if (forBuy) { //選擇買商品時
forBuy = false;
isBuy = false;
inputmode = 0;
}
}
//選擇第二項時
else if (attackSelecty == screenheight - 25) {
if (isRoleAttack) { //與野怪或boss接觸 ,選擇第二招
tempNum = 5;
attackWidth = 80;
attackHeight = 64;
roleWord = "烈火濺射";
roleBeat = true;
roleAttack = false;
isRoleAttack = false;
} else if (roleChoose) { //與商人接觸
roleChoose = false;
sellerAsk = false;
inputmode = 1;
isSell = true;
choose1 = "換錢:寶物-》黃金";
choose2 = "放棄";
} else if (forBuy) { //選擇買商品時
if (mroleProperty[4] > 0) {
forBuy = false;
isBuy = false;
inputmode = 0;
mroleProperty[4]--;
mroleProperty[1]++;
} else
inputmode = 3; //當黃金數為0時,交易失敗
}
}
//選擇第三項時
else if (attackSelecty == screenheight - 35) {
if (isRoleAttack) { //與野怪或boss接觸 ,選擇第三招
tempNum = 4;
attackWidth = 48;
attackHeight = 48;
roleWord = "星星燎燃";
roleBeat = true;
roleAttack = false;
isRoleAttack = false;
} else if (roleChoose) { //與商人接觸
roleChoose = false;
sellerAsk = false;
inputmode = 3;
isBuy = true;
choose1 = "補血:黃金-》血氣";
choose2 = "加功:黃金-》寶物";
choose3 = "放棄";
} else if (forBuy) { //選擇買商品時
if (mroleProperty[4] > 0) {
forBuy = false;
isBuy = false;
inputmode = 0;
mroleProperty[4]--;
roleBloodHeight += 3;
if (roleBloodHeight >= 40)
roleBloodHeight = 40;
} else
inputmode = 3; //當黃金數為0時,交易失敗
}
}
}
}
}
}
public void commandAction(Command com, Displayable displayable) {
//選擇退出游戲
if (com == exitGame) {
this.midlet.exitMIDlet();
}
//游戲菜單
else if (com == mainMenu) {
removeCommand(mainMenu);
addCommand(backGame);
gameState = GAME_MENU;
}
//返回菜單
else if (com == backMenu) {
removeCommand(backMenu);
if(!isFirstStart)addCommand(backGame);
if (gameState == GAME_ABOUT)
gameState = GAME_MENU;
}
//返回游戲
else if (com == backGame) {
if (gameState == GAME_MENU) {
gameState = GAME_START;
removeCommand(backGame);
addCommand(mainMenu);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -