void GameplayLayer::_handleActionDiceDragMoved(EventCustom* event) { auto data = (ActionDiceDragData*) event->getUserData(); auto sprite = data->getSprite(); auto touch = data->getTouch(); auto dice = sprite->getDice(); auto touchLocation = this->convertTouchToNodeSpace(touch); sprite->setPosition(touchLocation); auto handler = DiceDragHandlerFactory::getHandler(dice); handler->dragMoved(data, this, this->_getDockableContainer()); }
void GameplayLayer::_handleActionDiceDragStarted(EventCustom* event) { auto data = (ActionDiceDragData*) event->getUserData(); auto sprite = data->getSprite(); auto dice = sprite->getDice(); sprite->startDragging(); auto room = Game::getInstance()->getRoomForCharacterCoordinate(); auto hasMonstersInRoom = room->getMonsters().size() > 0; auto handler = DiceDragHandlerFactory::getHandler(dice); handler->dragStarted(data, this, this->_getDockableContainer()); }
void GameplayLayer::_handleActionDiceDragEnded(EventCustom* event) { auto data = (ActionDiceDragData*) event->getUserData(); auto sprite = data->getSprite(); auto dice = sprite->getDice(); sprite->setLocalZOrder(sprite->getLocalZOrder() - DRAG_Z_ORDER_DELTA); OverlayUtil::removeOverlay(this); auto handler = DiceDragHandlerFactory::getHandler(dice); bool docked = handler->dragEnded(data, this, this->_getDockableContainer()); if (!docked) { sprite->restoreOriginalPosition(); } }
void ShieldDiceDragHandler::dragStarted(ActionDiceDragData* data, GameplayLayer* layer, DockableContainer* dockableContainer) { Vector<Node*> targetNodes; for (auto node : layer->getChildren()) { if (IS(node, ActionDiceSprite)) { auto diceSprite = (ActionDiceSprite*) node; auto dice = diceSprite->getDice(); if (DiceUtil::isSwordDice(dice)) { targetNodes.pushBack(node); } } } auto game = Game::getInstance(); if (game->getDamageTaken() > 0) { auto scene = (GameplayScene*) layer->getScene(); auto dungeonLayer = scene->getDungeonLayer(); auto character = game->getPlayer()->getCharacter(); auto characterSprite = character->getSprite(); auto position = characterSprite->getPosition() - Vec2(TILE_DIMENSION / 2, TILE_DIMENSION / 2) + characterSprite->getParent()->getPosition() + dungeonLayer->getParent()->getPosition(); characterSprite->setPosition(position); characterSprite->retain(); characterSprite->removeFromParent(); layer->addChild(characterSprite); characterSprite->release(); targetNodes.pushBack(characterSprite); } OverlayUtil::addOverlay(targetNodes, layer); }
void ShieldDiceDragHandler::dragMoved(ActionDiceDragData* data, GameplayLayer* layer, DockableContainer* dockableContainer) { auto touch = data->getTouch(); for (auto node : layer->getChildren()) { if (IS(node, ActionDiceSprite)) { auto diceSprite = (ActionDiceSprite*) node; auto dice = diceSprite->getDice(); if (DiceUtil::isSwordDice(dice)) { HighlightUtil::highlighNode(node, touch); } } } auto game = Game::getInstance(); if (game->getDamageTaken() > 0) { auto characterSprite = game->getPlayer()->getCharacter()->getSprite(); HighlightUtil::highlighNode(characterSprite, touch); } }
bool Board::canEscape(const playerId player) const { return getDice() == 6 && getFiguresOffBoard(player) > 0 && getFiguresOnField(player, 0) == 0; }
bool ShieldDiceDragHandler::dragEnded(ActionDiceDragData* data, GameplayLayer* layer, DockableContainer* dockableContainer) { auto docked = false; auto sprite = data->getSprite(); auto touch = data->getTouch(); for (auto node : layer->getChildren()) { if (IS(node, ActionDiceSprite)) { auto diceSprite = (ActionDiceSprite*) node; auto dice = diceSprite->getDice(); if (DiceUtil::isSwordDice(dice)) { auto rect = node->getBoundingBox(); if (rect.containsPoint(touch->getLocation())) { node->setColor(Color3B::WHITE); auto swordAndShield = DiceFace::create(IMG_DICE_ACTION_SWORD_AND_SHIELD); dice->setSelectedFace(swordAndShield, false); docked = true; break; } } } } auto game = Game::getInstance(); if (game->getDamageTaken() > 0) { auto character = game->getPlayer()->getCharacter(); auto characterSprite = character->getSprite(); auto rect = characterSprite->getBoundingBox(); if (rect.containsPoint(touch->getLocation())) { auto turn = game->getTurn(); if (IS(turn, PlayerTurn)) { auto playerTurn = (PlayerTurn*) turn; playerTurn->protectDamage(1); } docked = true; } auto scene = (GameplayScene*) layer->getScene(); auto dungeonLayer = scene->getDungeonLayer(); auto dungeonRoom = dungeonLayer->getRoomSpriteForCharacterCoordinate(); characterSprite->setLocalZOrder(CHARACTER_DICE_Z_ORDER); characterSprite->setColor(Color3B::WHITE); auto position = characterSprite->getPosition() + Vec2(TILE_DIMENSION / 2, TILE_DIMENSION / 2) - dungeonRoom->getPosition() - dungeonLayer->getParent()->getPosition(); characterSprite->setPosition(position); characterSprite->retain(); characterSprite->removeFromParent(); dungeonRoom->addChild(characterSprite); characterSprite->release(); } if (docked) { layer->dockActionDice(sprite); } return docked; }