//------------------------ Left Mouse Released ---------------------------- void GameScreenController::leftMouseReleased(const int& x, const int& y) { PurchasePanel* purPanPtr = gameScreenPtr->rendererPtr->purchasePanPtr; GameScreenUpdate* gameUpdater = gameScreenPtr->updatePtr; // If there is cannon being purchased and waiting to be planted if (purPanPtr->canName != "") { const Vector2i& tileNumber = getTileNumber(x, y); // Should fulfull two conditions that the used doesn't released the touch in the HUD and // the tile chosen is available if ( (y >= 32 && y <= 32 * 14) && (gameUpdater->tileStatus.at(tileNumber.y).at(tileNumber.x) == 0)) { gameUpdater->createCannon(purPanPtr->canName, tileNumber.x, tileNumber.y); // Set value that indicates it has cannon gameUpdater->tileStatus.at(tileNumber.y).at(tileNumber.x) = 1; purPanPtr->canName = ""; } else { // Not both conditions are met, so bring the money back if (purPanPtr->canName == "normalcannon") { Settings::cash += 10; } else if (purPanPtr->canName == "splashCannon") { Settings::cash += 30; } else if (purPanPtr->canName == "icecannon") { Settings::cash += 40; } // Set to no cannon purPanPtr->canName = ""; } } }
int TileLoader::getGid(int x, int y, const char* layerName) { /* find the gid of the x,y passed */ int tileNum = getTileNumber(x, y); bool found = false; // Load the data element from the matching layer tinyxml2::XMLElement* xmlLayerElement = mXmlMapElement->FirstChildElement("layer"); while (!found && xmlLayerElement != NULL) { if (xmlLayerElement->Attribute("name") == std::string(layerName)) { found = true; } else { xmlLayerElement = xmlLayerElement->NextSibling()->ToElement(); } } if (xmlLayerElement == NULL) { throw std::runtime_error("TileLoader: No layer was found by the name " + std::string(layerName)); } tinyxml2::XMLElement* xmlLayerDataElement = xmlLayerElement->FirstChildElement("data"); if (xmlLayerDataElement == NULL) { throw std::runtime_error("TileLoader: No data element was found in layer " + std::string(layerName)); } tinyxml2::XMLElement* xmlTileElement = xmlLayerDataElement->FirstChildElement("tile"); if (xmlTileElement == NULL) { throw std::runtime_error("TileLoader: No tile element was found in layer " + std::string(layerName)); } // Increment through the tilemap until you reach the correct tile element for(int tile = 0; tile < tileNum; tile++) { xmlTileElement = xmlTileElement->NextSibling()->ToElement(); } if (xmlTileElement == NULL) { throw std::runtime_error("TileLoader: No tile element was found in layer during search " + std::string(layerName)); } return xmlTileElement->IntAttribute("gid"); }
//------------------------ Mouse Motion ----------------------------------- void GameScreenController::mouseMotion(const int& x, const int& y) { HeadsUpDisplay* hudPtr = gameScreenPtr->rendererPtr->hudPtr; if (gameScreenPtr->updatePtr->isGameOver()) { if (hudPtr->isOverRestartButton(x, y)) { hudPtr->setRestartButtonOpaque(true); } else { hudPtr->setRestartButtonOpaque(false); } if (hudPtr->isOverMenuButton(x, y)) { hudPtr->setMenuButtonOpaque(true); } else { hudPtr->setMenuButtonOpaque(false); } return; } PurchasePanel* purPanPtr = gameScreenPtr->rendererPtr->purchasePanPtr; Vector2f& mapPos = gameScreenPtr->updatePtr->mapPos; // Place the cursor cannon in the area where it will be planted if the tile is available if (purPanPtr->canName != "") { const Vector2i& tileNum = getTileNumber(x, y); purPanPtr->cursorX = (tileNum.x * 32) + mapPos.x; purPanPtr->cursorY = (tileNum.y * 32) + mapPos.y; } // For showing cannon specifications int buttonId = purPanPtr->getButtonId(x, y); switch (buttonId) { case 0: hudPtr->setCannonSpecs(CannonType::NORMAL_CANNON); break; case 1: hudPtr->setCannonSpecs(CannonType::SPLASH_CANNON); break; case 2: hudPtr->setCannonSpecs(CannonType::ICE_CANNON); break; default: hudPtr->setCannonSpecs(CannonType::NONE); break; } }