📄 game.java
字号:
if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
m_Paused = true;
changeState(STATE_PAUSE);
}
break;
case KEY_UP:
case KEY_2:
if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
//如姿势正常,则设为上跳
if (thisRole.getRolePose() == ROLEPOSE_NORMAL) {
thisRole.setRoleV( (byte) ( -thisRole.getMAX_V()));
thisRole.setSkateV( (byte) ( -thisRole.getMAX_SKATE_V()));
thisRole.setIsV(false);
thisRole.setRolePose(ROLEPOSE_JUMP);
}
}
break;
case KEY_DOWN:
case KEY_8:
if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
//如果角色姿势是正常,则设置角色姿势为下蹲
if (thisRole.getRolePose() == ROLEPOSE_NORMAL) {
thisRole.setRolePose(ROLEPOSE_DOWN);
//根据不同的姿势设置不同的图片
if (thisRole.getRoleTool() == ROLETOOL_NONE) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(1, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(40, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(38, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
else if (thisRole.getRoleTool() == ROLETOOL_BAT) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(5, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(29, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(17, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
else if (thisRole.getRoleTool() ==
ROLETOOL_BOTTLE) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(6, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(30, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(41, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
else {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(7, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(31, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(18, true);
break;
}
}
thisRole.setRoleY(thisRole.getSkateY() + 4 -
thisRole.player.currentFrameCollisionH);
}
}
break;
case KEY_FIRE:
case KEY_5:
case SOFT_KEY_LEFT:
if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
if (thisRole.getRolePose() != ROLEPOSE_DOWN) {
if (thisRole.getRoleTool() == ROLETOOL_BAT) {
thisRole.setRoleTool(ROLETOOL_BATHIT);
}
else if (thisRole.getRoleTool() == ROLETOOL_BOTTLE) {
thisRole.setRoleTool(ROLETOOL_BOTTLEHIT);
}
}
}
break;
}
break;
case STATE_GAME_SAVING:
if (bSelectKeyDown == false && bGameMenuAnimationOver()) {
bSelectKeyDown = true;
m_MenuFrameAnimation.setAnimation(1, false);
}
break;
case STATE_PAUSE:
checkKeys(MENU_GAME_PAUSE, true, keyCode);
break;
case STATE_END:
changeState(STATE_MAINMENU);
break;
}
} /// END FUNC keyPressed
/**
* @name keyReleased
* @brief indicate, that key has been released
* @param keyCode key code of the key, which state is to be changed
*/
protected void keyReleased(int keyCode) {
switch (gameState) {
case STATE_GAME:
switch (keyCode) {
case KEY_DOWN:
case KEY_8:
if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
if (thisRole.getRolePose() == ROLEPOSE_DOWN ||
thisRole.getRolePose() == ROLEPOSE_NORMAL) {
thisRole.setRolePose(ROLEPOSE_NORMAL);
if (thisRole.getRoleTool() == ROLETOOL_NONE) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(0, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(25, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(14, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
else if (thisRole.getRoleTool() == ROLETOOL_BAT) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(2, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(26, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(39, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
else if (thisRole.getRoleTool() == ROLETOOL_BOTTLE) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(3, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(27, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(15, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
else if (thisRole.getRoleTool() == ROLETOOL_MOTOHAT) {
switch (currentRole) {
case ROLE_BOY:
thisRole.player.setAnimation(4, true);
break;
case ROLE_GIRL:
thisRole.player.setAnimation(28, true);
break;
case ROLE_NINJA:
thisRole.player.setAnimation(16, true);
break;
}
// thisRole.setRoleY(thisRole.getSkateY() + 4 - thisRole.player.currentFrameCollisionH);
}
thisRole.setRoleY(thisRole.getSkateY() + 4 -
thisRole.player.currentFrameCollisionH);
}
}
break;
}
break;
}
}
/**
* 函数功能:每一小局开始前的初始化
* 参数:无
* 返回值:无
*/
protected void init() {
//首先释放掉其他以前的关卡的图片
if (loadingGuage2 == 0) {
imgDecTop = null;
imgDecBottom = null;
imgForeground = null;
imgLand = null;
imgBuilding = null;
imgSky = null;
System.gc();
loadingGuage2++;
System.out.println("OK1");
System.out.println("Mem1 = " + Runtime.getRuntime().freeMemory() / 1024);
}
else if (loadingGuage2 == 1) {
//载入本关卡的图片
switch (currentScreen) {
case 0:
//#if MOTO_V600 || MOTO_E398
//#else
imgSky = loadImage(IMAGE_SKY1);
imgBuilding = loadImage(IMAGE_BUILDING1);
//#endif
imgDecTop = loadImage(IMAGE_DECORATION1_1);
imgDecBottom = loadImage(IMAGE_DECORATION1_2);
imgLand = loadImage(IMAGE_LAND1);
imgForeground = loadImage(IMAGE_FOREGROUND1);
break;
case 1:
//#if MOTO_V600 || MOTO_E398
//#else
imgSky = loadImage(IMAGE_SKY2);
imgBuilding = loadImage(IMAGE_BUILDING2);
//#endif
imgDecTop = loadImage(IMAGE_DECORATION2_1);
imgDecBottom = loadImage(IMAGE_DECORATION2_2);
imgForeground = loadImage(IMAGE_FOREGROUND2);
imgLand = loadImage(IMAGE_LAND2);
break;
case 2:
//#if MOTO_V600 || MOTO_E398
//#else
imgSky = loadImage(IMAGE_SKY3);
imgBuilding = loadImage(IMAGE_BUILDING3);
//#endif
imgDecTop = loadImage(IMAGE_DECORATION3_1);
imgDecBottom = loadImage(IMAGE_DECORATION3_2);
imgForeground = loadImage(IMAGE_FOREGROUND3);
imgLand = loadImage(IMAGE_LAND3);
break;
case 3:
//#if MOTO_V600 || MOTO_E398
//#else
imgSky = loadImage(IMAGE_SKY4);
imgBuilding = loadImage(IMAGE_BUILDING4);
//#endif
imgDecTop = loadImage(IMAGE_DECORATION4_1);
imgDecBottom = loadImage(IMAGE_DECORATION4_2);
imgForeground = loadImage(IMAGE_FOREGROUND4);
imgLand = loadImage(IMAGE_LAND4);
break;
case 4:
//#if MOTO_V600 || MOTO_E398
//#else
imgSky = loadImage(IMAGE_SKY5);
imgBuilding = loadImage(IMAGE_BUILDING5);
//#endif
imgDecTop = loadImage(IMAGE_DECORATION5_1);
imgDecBottom = loadImage(IMAGE_DECORATION5_2);
imgForeground = loadImage(IMAGE_FOREGROUND5);
imgLand = loadImage(IMAGE_LAND5);
break;
case 5:
//#if MOTO_V600 || MOTO_E398
//#else
imgSky = loadImage(IMAGE_SKY6);
imgBuilding = loadImage(IMAGE_BUILDING6);
//#endif
imgDecTop = loadImage(IMAGE_DECORATION6_1);
imgDecBottom = loadImage(IMAGE_DECORATION6_2);
imgForeground = loadImage(IMAGE_FOREGROUND6);
imgLand = loadImage(IMAGE_LAND6);
break;
}
System.out.println("OK2");
loadingGuage2++;
}
else if (loadingGuage2 == 2) {
//初始化声音类
bInjureSound = false;
bPassSound = false;
//定义一个新的角色对象
thisRole = null;
switch (currentRole) {
case 0: // 载入男孩角色图片
thisRole = new Role(30, HORIZON - 30,
imgSkateboard, 34,
HORIZON - imgSkateboard.getHeight() + 4);
thisRole.player.setAnimation(0, true);
thisImgRoleHead = imgRoleHead[0];
break;
case 1: // 载入女孩角色图片
thisRole = new Role(30, HORIZON - 30,
imgSkateboard, 32,
HORIZON - imgSkateboard.getHeight() + 4);
thisRole.player.setAnimation(25, true);
thisImgRoleHead = imgRoleHead[1];
break;
case 2: // 载入忍者角色图片
thisRole = new Role(30, HORIZON - 30,
imgSkateboard, 34,
HORIZON - imgSkateboard.getHeight() + 4);
thisRole.player.setAnimation(14, true);
thisImgRoleHead = imgRoleHead[2];
break;
}
thisRole.setRolePose(ROLEPOSE_NORMAL);
thisRole.setRoleTool(ROLETOOL_NONE);
thisRole.setRoleStatus(ROLESTATUS_WELL);
System.out.println("OK3");
loadingGuage2++;
}
else if (loadingGuage2 == 3) {
//定义一个新的地图数组
bonusVector.removeAllElements();
toolVector.removeAllElements();
enemyVector.removeAllElements();
fraiseVector.removeAllElements();
myMap = new Map(currentScreen, currentRole);
for (int i = 0; i < myMap.mapWidth; i++) {
for (int j = 0; j < myMap.mapHeight; j++) {
if (myMap.backMap[i][j] != 0) {
switch (myMap.backMap[i][j]) {
case BONUS_SHOE:
bonusVector.addElement(new Bonus(imgBonus[0],
BONUS_SHOE, i, j));
break;
case BONUS_MONEY:
bonusVector.addElement(new Bonus(imgBonus[1],
BONUS_MONEY, i, j));
break;
case BONUS_GLOVE:
bonusVector.addElement(new Bonus(imgBonus[2],
BONUS_GLOVE, i, j));
break;
case BONUS_KEY:
bonusVector.addElement(new Bonus(imgBonus[3],
BONUS_KEY, i, j));
break;
case BONUS_BALLOON:
bonusVector.addElement(new Bonus(imgBonus[4],
BONUS_BALLOON, i, j));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -