void BaselinePattern::updatePlayerChoice(Poppy* poppy, Pot* pot) { /********* TODO: * FIX COLLECTED DATA FOR BIN AND PLACE TIME. THIS TIME IS WRONG *********/ //Store bin and place time int id = poppy->getId(); for (int i = 0; i < pData.size(); ++i) if (pData[i].poppyID == id) { pData[i].binPlaceIn = getColorId(pot->getBlinkColor()); pData[i].binPlaceTime = player->totalElapsed; } if ( ((pot->getPosition() - poppy->getPosition()).length() <= (POT_RADIUS)) && (poppy != stage->selected)) { if (poppy->isActive()) { playerPoppyIndex++; poppy->setActive(false); if (pot->getId() == poppy->getPotIdRef()) { player->numCorrect++; } } } }
void BlinkyBlocks::loadModules(TiXmlNode *nodeBlock) { Color defaultColor=DARKGREY; TiXmlElement* element = nodeBlock->ToElement(); uint64_t currentID=0; const char *attr= element->Attribute("color"); if (attr) { string str(attr); int pos1 = str.find_first_of(','), pos2 = str.find_last_of(','); defaultColor.rgba[0] = (float)(atof(str.substr(0,pos1).c_str())/255.0); defaultColor.rgba[1] = (float)(atof(str.substr(pos1+1,pos2-pos1-1).c_str())/255.0); defaultColor.rgba[2] = (float)(atof(str.substr(pos2+1,str.length()-pos1-1).c_str())/255.0); std::cerr << "new default color :" << defaultColor << std::endl; } attr= element->Attribute("blocksize"); if (attr) { string str(attr); int pos1 = str.find_first_of(','), pos2 = str.find_last_of(','); blockSize.pt[0] = atof(str.substr(0,pos1).c_str()); blockSize.pt[1] = atof(str.substr(pos1+1,pos2-pos1-1).c_str()); blockSize.pt[2] = atof(str.substr(pos2+1,str.length()-pos1-1).c_str()); std::cerr << "blocksize =" << blockSize[0] << "," << blockSize[1] << "," << blockSize[2] << std::endl; } /* Reading a block */ TiXmlNode *block = nodeBlock->FirstChild("block"); Cell3DPosition position; int orientation=0; Color color; bool master; while (block) { element = block->ToElement(); color=defaultColor; master=false; orientation=0; // set the color attr = element->Attribute("color"); if (attr) { string str(attr); int pos1 = str.find_first_of(','), pos2 = str.find_last_of(','); color.set((float)(atof(str.substr(0,pos1).c_str())/255.0), (float)(atof(str.substr(pos1+1,pos2-pos1-1).c_str())/255.0), (float)(atof(str.substr(pos2+1,str.length()-pos1-1).c_str())/255.0)); std::cerr << "new color :" << color << std::endl; } // set the position attr = element->Attribute("position"); if (attr) { string str(attr); int pos1 = str.find_first_of(','), pos2 = str.find_last_of(','); position.set(atoi(str.substr(0,pos1).c_str()), atoi(str.substr(pos1+1,pos2-pos1-1).c_str()), atoi(str.substr(pos2+1,str.length()-pos1-1).c_str())); std::cerr << "position : " << position << std::endl; } uint16_t idColor = getColorId(color); tabBlinkyBlocks.push_back(BlinkyBlock(currentID++,position,idColor)); block = block->NextSibling("block"); } // end while (block) }
void BaselinePattern::setup() { stage->ground = new Ground(Vector3(0, 0, 0), GROUND_COLOR, GROUND_COLOR, SIGNAL_LENGTH); //Make some pots Pot* pot1 = new Pot(Vector3(3, POT_HEIGHT / 2, 3), POT_RADIUS, Cpot1, Cpot1, 1, Spot1); pot1->setId(0); Pot* pot2 = new Pot(Vector3(3, POT_HEIGHT / 2, -3), POT_RADIUS, Cpot2, Cpot2, 1, Spot2); pot2->setId(1); Pot* pot3 = new Pot(Vector3(-3, POT_HEIGHT / 2, 3), POT_RADIUS, Cpot3, Cpot3, 1, Spot3); pot3->setId(2); Pot* pot4 = new Pot(Vector3(-3, POT_HEIGHT / 2, -3), POT_RADIUS, Cpot4, Cpot4, 1, Spot4); pot4->setId(3); stage->pots.push_back(pot1); stage->pots.push_back(pot2); stage->pots.push_back(pot3); stage->pots.push_back(pot4); //Make some poppies numImportantPoppies = player->level + 2; numDistractingPoppies = 0; poppyRadius = POPPY_RADIUS * pow(0.95, numImportantPoppies - 1); int assignCount[stage->pots.size()]; for (int i = 0; i < stage->pots.size(); ++i) assignCount[i] = 0; player->totalProblems = numImportantPoppies; // For base class Pattern for (int i = 0; i < numImportantPoppies; ++i) { Poppy* poppy = new Poppy(Vector3(randRangeDouble(-2,2),poppyRadius,randRangeDouble(-2,2)), BLAND_COLOR, BLAND_COLOR, 0, poppyRadius); poppy->setId(i); if (stage->pots.size() > 0) { // Do not assign the majority of the poppies to the same pot int r; do { r = rand() % stage->pots.size(); } while (assignCount[r] > 0 && assignCount[r] >= (numImportantPoppies + 1) / 2); poppy->setPotIdRef(stage->pots[r]->getId()); // Used tempoarily to play pot sound poppy->setBlinkColor(stage->pots[r]->getBaseColor()); assignCount[r]++;; } stage->poppies.push_back(poppy); poppyData data; data.playerLevel = player->level; data.stageId = (int)player->progression.size(); data.poppyID = poppy->getId(); data.poppyType = getColorId(poppy->getBlinkColor()); data.poppyFlashTime = -999; // Instantiate with bad data data.binPlaceIn = -999; data.binPlaceTime = -999; pData.push_back(data); } for (int i = 0; i < numDistractingPoppies; ++i) { Poppy* poppy = new Poppy(Vector3(randRangeDouble(-1,1),poppyRadius,randRangeDouble(-1,1)), BLAND_COLOR, BLAND_COLOR, 0, poppyRadius); poppy->setId(i); stage->poppies.push_back(poppy); } //stage.negativeFeedback = new Sound(SOUNDFILE_NEGATIVE_FEEDBACK); //stage.positiveFeedback = new Sound(SOUNDFILE_POSITIVE_FEEDBACK); }
void TdwPalette::mousePressEvent(QMouseEvent *e) { if(readOnly || palette.isEmpty()) return; setCurrentColor(getColorId(e->pos())); }