void ControlSystem::update(Controls control) { if (player_health_->is_dead) { return; } switch (control) { case UP: case DOWN: case LEFT: case RIGHT: move(control); break; case PICK_UP_ITEM: pickUpItem(); break; case DESCEND: descend(); break; case PAUSE_TURN: player_turn_->turn_taken = true; break; default: break; } }
//判断碰撞类型 CollisionType Hero::checkCollision(Point heroPosition) { //cocos2d-x坐标转换为Tilemap坐标 targetTileCoord = sGlobal->gameMap->tileCoordForPosition(heroPosition); //如果勇士坐标超过地图边界,返回kWall类型,阻止其移动 if (heroPosition.x < 0 || targetTileCoord.x > sGlobal->gameMap->getMapSize().width - 1 || targetTileCoord.y < 0 || targetTileCoord.y > sGlobal->gameMap->getMapSize().height - 1) return kWall; //获取墙壁层对应坐标的图块ID int targetTileGID = sGlobal->gameMap->getWallLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有墙 if (targetTileGID) { return kWall; } //获取怪物层对应坐标的图块ID targetTileGID = sGlobal->gameMap->getEnemyLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有怪物 if (targetTileGID) { //开始战斗 fight(); return kEnemy; } //获取物品层对应坐标的图块ID targetTileGID = sGlobal->gameMap->getItemLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有物品 if (targetTileGID) { //拾取物品 pickUpItem(); return kItem; } //获取门层对应坐标的图块ID targetTileGID = sGlobal->gameMap->getDoorLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有门 if (targetTileGID) { //打开门 openDoor(targetTileGID); return kDoor; } //从npc字典中查询 int index = targetTileCoord.x + targetTileCoord.y * sGlobal->gameMap->getMapSize().width; NPC *npc = sGlobal->gameMap->npcDict.at(index); if (npc != NULL) { actWithNPC(); return kNPC; } //从Teleport字典中查询 Teleport *teleport = sGlobal->gameMap->teleportDict.at(index); if (teleport != NULL) { doTeleport(teleport); return kTeleport; } //可以通行 return kNone; }
void KyraEngine_HoF::handleInput(int x, int y) { setNextIdleAnimTimer(); if (_unk5) { _unk5 = 0; return; } if (!_screen->isMouseVisible()) return; if (_savedMouseState == -2) { snd_playSoundEffect(13); return; } setNextIdleAnimTimer(); if (x <= 6 || x >= 312 || y <= 6 || y >= 135) { bool exitOk = false; assert(_savedMouseState + 6 >= 0); switch (_savedMouseState + 6) { case 0: if (_sceneExit1 != 0xFFFF) exitOk = true; break; case 1: if (_sceneExit2 != 0xFFFF) exitOk = true; break; case 2: if (_sceneExit3 != 0xFFFF) exitOk = true; break; case 3: if (_sceneExit4 != 0xFFFF) exitOk = true; break; default: break; } if (exitOk) { inputSceneChange(x, y, 1, 1); return; } } if (checkCharCollision(x, y) && _savedMouseState >= -1) { runSceneScript2(); return; } else if (pickUpItem(x, y)) { return; } else { int skipHandling = 0; if (checkItemCollision(x, y) == -1) { resetGameFlag(0x1EF); skipHandling = handleInputUnkSub(x, y) ? 1 : 0; if (queryGameFlag(0x1EF)) { resetGameFlag(0x1EF); return; } if (_unk5) { _unk5 = 0; return; } } if (_deathHandler > -1) skipHandling = 1; if (skipHandling) return; if (checkCharCollision(x, y)) { runSceneScript2(); return; } if (_itemInHand >= 0) { if (y > 136) return; dropItem(0, _itemInHand, x, y, 1); } else { if (_savedMouseState == -2 || y > 135) return; if (!_unk5) { inputSceneChange(x, y, 1, 1); return; } _unk5 = 0; } } }
void KyraEngine_MR::handleInput(int x, int y) { if (_inventoryState) return; setNextIdleAnimTimer(); if (_unk5) { _unk5 = 0; return; } if (!_screen->isMouseVisible()) return; if (_savedMouseState == -3) { snd_playSoundEffect(0x0D, 0x80); return; } setNextIdleAnimTimer(); int skip = 0; if (checkCharCollision(x, y) && _savedMouseState >= -1 && runSceneScript2()) { return; } else if (_itemInHand != 27 && pickUpItem(x, y, 1)) { return; } else if (checkItemCollision(x, y) == -1) { resetGameFlag(1); skip = runSceneScript1(x, y); if (queryGameFlag(1)) { resetGameFlag(1); return; } else if (_unk5) { _unk5 = 0; return; } } if (_deathHandler >= 0) skip = 1; if (skip) return; if (checkCharCollision(x, y)) { if (runSceneScript2()) return; } else if (_itemInHand >= 0 && _savedMouseState >= 0) { if (_itemInHand == 27) { makeCharFacingMouse(); } else if (y <= 187) { if (_itemInHand == 43) removeHandItem(); else dropItem(0, _itemInHand, x, y, 1); } return; } else if (_savedMouseState == -3) { return; } else { if (y > 187 && _savedMouseState > -4) return; if (_unk5) { _unk5 = 0; return; } } inputSceneChange(x, y, 1, 1); }