//load加载整个背景 void MyPlayLayer::loadBackground(){ cur_bg=CCSprite::create("image/playbackground/bg1.png"); cur_bg->setPosition(ccp(winsize.width/2,winsize.height/2)); this->addChild(cur_bg,0); loadNextMap(); addCollisions(); }
void PathFinder::calculate() { //FixedCoordinate tempCoord(18,10); //mAgentNextGoalPositions[tempCoord] = 1; //mAgentNextGoalPositions.erase(tempCoord); //for (int i = 0; i < 1; i++) //{ // tempCoord.x = 20; // tempCoord.y = 9+i; // mAgentNextGoalPositions[tempCoord] = i+2; //} //tempCoord.x = 18; //tempCoord.y = 10; //std::map<FixedCoordinate, KeyType, FixedCoordinateCompare>::iterator it; //it = mAgentNextGoalPositions.find(tempCoord); //if (it != mAgentNextGoalPositions.end()) //{ // bool test = false; //} //bool bananas = false; std::map<KeyType, Agent*>* pAgents = mpAgentHandler->checkOutAllAgents(); std::map<KeyType, Agent*>::iterator agentIt; static PotentialSquare agentPotentialMap[GOAL_FIELD_SIZE]; // calculate a new goal for the agents without a goal for (agentIt = pAgents->begin(); agentIt != pAgents->end(); ++agentIt) { PotentialInformation& potentialInfo = agentIt->second->getPotentialInformation(); if (agentIt->second->arrivedAtGoal()) { // Remove the goal position from the map mAgentGoalPositions.erase(potentialInfo.getBestGoalPosition()); potentialInfo.updateGoalAndPheromones(); // If we don't have a goal calculate one, that means didn't have a valid nextGoal. if (potentialInfo.getBestGoalPosition() == INVALID_COORDINATE) { calculateSurrondingField(GoalType_Goal, agentIt->second, agentPotentialMap); sortGoals(agentPotentialMap); potentialInfo.setGoals(agentPotentialMap); } // Remove next goal position from the map else { mAgentNextGoalPositions.erase(potentialInfo.getBestGoalPosition()); } } // If we don't have a goal this is our first time // TODO - This should never appear here later else if (potentialInfo.getBestGoalPosition() == INVALID_COORDINATE) { calculateSurrondingField(GoalType_Goal, agentIt->second, agentPotentialMap); sortGoals(agentPotentialMap); potentialInfo.setGoals(agentPotentialMap); } if (agentIt->second->getPosition().x >= 16.75f) { bool weAreHere = true; } } // Check for collisions in goal and solve them addCollisions(*pAgents, GoalType_Goal); solveConflicts(GoalType_Goal, *pAgents); // Calculate a new next goal for the agents without a next goal for (agentIt = pAgents->begin(); agentIt != pAgents->end(); ++agentIt) { PotentialInformation& potentialInfo = agentIt->second->getPotentialInformation(); // If we don't have a next goal calculate one if (potentialInfo.getBestNextGoalPosition() == INVALID_COORDINATE) { calculateSurrondingField(GoalType_NextGoal, agentIt->second, agentPotentialMap); sortGoals(agentPotentialMap); potentialInfo.setNextGoals(agentPotentialMap); } } // Check for collisions in next goals and solve them addCollisions(*pAgents, GoalType_NextGoal); solveConflicts(GoalType_NextGoal, *pAgents); mpAgentHandler->checkInAllAgents(); mFrame++; if (mFrame % FRAME_TO_DISPLAY == 0) { // Only print the current frame and map each 10th frame std::list<std::wostream*>::iterator it; for (it = mpOutStreams->begin(); it != mpOutStreams->end(); ++it) { **it << "Current Frame: " << mFrame << std::endl; } printMap(); } }