📄 gmcanvas.java
字号:
{
//System.out.println(e.getMessage());
}
break;
case BT_AWAIT_HOST: // Wait for connection from client
////System.out.println("AWAIT HOST!");
tickCount++;
if (BlueTooth.gameFound)
{
BlueTooth.send(0x11110000);
disc.startReceive();
btStatus = BT_AWAIT_RECEIVE;
}
else if (BlueTooth.ConnectCancelled)
{
bBTSetup = false;
btStatus = 0;
}
// //System.out.println("AWAIT END!");
break;
case BT_AWAIT_RECEIVE:
////System.out.println("AWAIT RET!");
int i = disc.retrieve();
if (i==0x11110000)
{
// New Game
gameMode = GM_INIT;
tickCount = 0;
sendBlueTooth();
bBTSetup = false;
bMultiplayer = true;
// if (bHost)
// //System.out.println("Host here!");
// else
// //System.out.println("Client here!");
}
////System.out.println("RET END!");
break;
}
}
else updateMenu((leftPressed[2] && !leftHeld[2]),(rightPressed[2] && !rightHeld[2]),(firePressed[2] && !fireHeld[2]));
getKeys(false);
}
}
// -------------------------------------------------------------------------------------------
// Handles game menu navigation and action
// -------------------------------------------------------------------------------------------
private void updateMenu(boolean up, boolean down, boolean fire)
{
// I guess most of this will be game dependandant so it will need rewritting
if (optionPage <= 2)
{
if (up)
{
if (forceMenu)
{
if (option == 0) option = 5;
else option = 0;
}
else
{
option--;
for (int i = 0; i < MAX_OPTIONS[optionPage]; i++)
{
if (option < 0) option = MAX_OPTIONS[optionPage] - 1;
if (option >= MAX_OPTIONS[optionPage]) option = 0;
if (options[option] || optionPage != 0 || (!options[option] && option == 0)) break;
option--;
}
if (optionPage == 2)
{
if (ge != null)
{
if (GameEffects.soundOn && option == 1) option = 0;
else if (!GameEffects.soundOn && option == 0) option = MAX_OPTIONS[optionPage] - 1;
}
else if (option == 0) option = MAX_OPTIONS[optionPage] - 1;
}
}
}
if (down)
{
if (forceMenu)
{
if (option == 0) option = 5;
else option = 0;
}
else
{
option++;
for (int i = 0; i < MAX_OPTIONS[optionPage]; i++)
{
if (option < 0) option = MAX_OPTIONS[optionPage] - 1;
if (option >= MAX_OPTIONS[optionPage]) option = 0;
if (options[option] || optionPage != 0 || (!options[option] && option == 0)) break;
option++;
}
if (optionPage == 2)
{
if (ge != null)
{
if (!GameEffects.soundOn && option == 0) option = 1;
else if (GameEffects.soundOn && option == 1) option = 2;
}
else if (option == 0) option = 1;
}
}
}
}
if (fire)
{
switch (option)
{
case 0: // Continue game
if (optionPage == 0)
{
if (gameMode == GM_TITLE || gameMode == GM_TITLE2)
{
if (!options[0])
{
bMultiplayer = false;
if (disc != null) disc.close();
gameMode = GM_INIT;
tickCount = 0;
}
else
{
Standard.getGame(this);
if (ge != null) ge.stopSound();
optionPage = 0;
}
}
else changePause();
}
else if (optionPage == 1)
{
// Host Game
bMultiplayer = false;
bBTSetup = true;
btStatus = BT_SETUP_HOST; // Setup Host
}
else if (optionPage == 2)
{
// Change sound
if (ge != null)
{
GameEffects.soundOn = !GameEffects.soundOn;
ge.stopSound();
option = 1;
}
}
else if (optionPage == 3)
{
optionPage = 2;
option = 2;
}
else if (optionPage == 4)
{
optionPage = 2;
option = 3;
}
break;
case 1: // New Game
if (optionPage == 0)
{
bMultiplayer = false;
if (disc != null) disc.close();
gameMode = GM_INIT;
tickCount = 0;
}
else if (optionPage == 1)
{
// Join game
bMultiplayer = false;
bBTSetup = true;
btStatus = BT_SETUP_JOIN; // Setup Host
}
else if (optionPage == 2)
{
// Change sound
if (ge != null)
{
GameEffects.soundOn = !GameEffects.soundOn;
ge.playMenu();
option = 0;
}
}
else if (optionPage == 3)
{
option = 2;
optionPage = 2;
}
else if (optionPage == 4)
{
option = 3;
optionPage = 2;
}
break;
case 2:
if (optionPage == 0)
{
optionPage = 1;
option = 0;
}
else if (optionPage == 2)
{
optionPage = 3;
option = 0;
}
else if (optionPage == 1)
{
optionPage = 0;
option = 2;
}
break;
case 3:
if (optionPage == 0)
{
optionPage = 2;
if (ge != null && GameEffects.soundOn) option = 0;
else option = 1;
}
else if (optionPage == 2)
{
optionPage = 4;
option = 0;
}
break;
case 4: // Tutorial
if (optionPage == 0)
{
bMultiplayer = false;
gameMode = GM_INIT;
tickCount = 0;
option = 0;
}
if (optionPage == 2)
{
optionPage = 0;
option = 3;
}
break;
case 5: // Exit
if (forceMenu)
{
changePause();
if (bMultiplayer)
{
if (disc != null) disc.close();
bMultiplayer = false;
}
options[0] = false;
option = 1;
optionPage = 0;
gameMode = GM_TITLE;
fireHeld[0] = true;
tickCount = 0;
}
else
{
if (disc != null) disc.close();
bMultiplayer = false;
gameMode = GM_EXIT;
StringBuffer buf = new StringBuffer(dict.getString(Dictionary.INT_CONN+Standard.hsSubmit));
Standard.wrapperLines(GAME_FONT, fontHeight, buf, DISPLAY_WIDTH-24, (DISPLAY_HEIGHT>>1)-8);
}
break;
}
}
}
// P = player, d = dude they control
private void playInput(int p, int d)
{
// Check which keys have been pressed and set some vars
// process the input on the character
}
private void btAbort()
{
btIn = true;
//System.out.println("btAbort 1");
if (btResent > BT_DELAY)
{
getKeys(false);
//System.out.println("btAbort 2");
if (firePressed[2])
{
bMultiplayer = false;
updateTicks = true;
btResent = 0;
disc.close();
// if (thisDude == 0) dude[1].status = 0;
// else dude[0].status = 0;
}
}
}
// -------------------------------------------------------------------------------------------
// Like getKeyStates
// -------------------------------------------------------------------------------------------
private void getKeys(boolean bSend)
{
int key = (bSend) ? 0 : 2;
if (((keyStates & UP_PRESSED) != 0) &&
((keyStates & DOWN_PRESSED) == 0))
{
if (upPressed[key]) upHeld[key] = true;
else upHeld[key] = false;
upPressed[key] = true;
}
else
{
upPressed[key] = false;
upHeld[key] = false;
}
if (((keyStates & DOWN_PRESSED) != 0) &&
((keyStates & UP_PRESSED) == 0))
{
if (downPressed[key]) downHeld[key] = true;
else downHeld[key] = false;
downPressed[key] = true;
}
else
{
downPressed[key] = false;
downHeld[key] = false;
}
if (((keyStates & LEFT_PRESSED) != 0) &&
((keyStates & RIGHT_PRESSED) == 0))
{
if (leftPressed[key]) leftHeld[key] = true;
else leftHeld[key] = false;
leftPressed[key] = true;
}
else
{
leftPressed[key] = false;
leftHeld[key] = false;
}
if (((keyStates & RIGHT_PRESSED) != 0) &&
((keyStates & LEFT_PRESSED) == 0))
{
if (rightPressed[key]) rightHeld[key] = true;
else rightHeld[key] = false;
rightPressed[key] = true;
}
else
{
rightPressed[key] = false;
rightHeld[key] = false;
}
// implement a toggle, so fire only happens once per click
// (will therefore not register very rapid multiple-clicks)
if ((keyStates & FIRE_PRESSED) != 0)
{
if (!fireHeld[key] && bBTSetup && (btStatus == BT_AWAIT_RECEIVE || btStatus == BT_AWAIT_CLIENT || btStatus == BT_AWAIT_HOST))
disc.interuptServer(bHost);
if (firePressed[key]) fireHeld[key] = true;
else fireHeld[key] = false;
firePressed[key] = true;
}
else
{
firePressed[key] = false;
fireHeld[key] = false;
}
if (bMultiplayer && bSend) sendBlueTooth();
}
// -------------------------------------------------------------------------------------------
// Send key states to other device:- note that this works best if keys are checked last
// -------------------------------------------------------------------------------------------
private void sendBlueTooth()
{
int c = 0x01000000;
if (leftPressed[0]) c += 0x00010000;
if (rightPressed[0]) c += 0x00020000;
if (upPressed[0]) c += 0x00040000;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -