Esempio n. 1
0
bool ZombieManager::hitDetect(CCRect rect)
{
	bool bRet = false;
	vector<Zombie*>::iterator it = m_Zombies.begin();

	vector<Zombie*> rest;
	for( ; it!=m_Zombies.end(); ++it)
	{
		CCRect rect_zombie = (*it)->myBoundingBox();
		if( isCollide(rect, rect_zombie) )
		{
			(*it)->onHurt(101, -350.0f, 0.0f);
			bRet = true;
		}
		else if(inVisibleRigion(rect_zombie))
		{
			rest.push_back(*it);
		}
		else
		{
			removeChild(*it, true);
		}
	}
	m_Zombies = rest;
	return bRet;
}
Esempio n. 2
0
void Level::run()
{
	gravityEffect();
	ship.move();
	for (auto &obstacle : obstacles) {
		if (isCollide(ship, obstacle)) {
			state = STOPPING;
		}
	}
	for (auto &hole : blackHoles) {
		if (isCollide(ship, hole) && hole.isEnable()) {
			state = STOPPING;
		}
	}
	if (isCollide(ship, spaceStation)) {
		state = WINNING;
	}
}
Esempio n. 3
0
void BaseActor::onCollide(BaseActor* actor)
{
	if (isCollide(actor))
	{
		onMessage("onCollide", (void*)actor);
		actor->onMessage("onCollide", (void*)this);
	}
	eachChildren([&] (BaseActor& child) { child.collide(actor); });
}
Esempio n. 4
0
bool Map::isBirdCollision(const Player& player) const
{
  if(player.isCrouched())
    return false;

  const sf::Vector2f player_pos = player.getPosition();
  const sf::Vector2f bird_pos   = _bird.getPosition();
  return isCollide( player_pos.x, player_pos.x + player.getWidth(),
                    bird_pos.x, bird_pos.x + _bird.getGlobalBounds().width );
}
Esempio n. 5
0
void Tank::headLeft(int deg, bool check)
{
    hdegree = checkDegree(hdegree - deg);
    hrotate();

    if (check == false)
    {
        while (isCollide() == true)
        {
            isCol = true;
            headRight(check = true);
        }
        isCol = false;
    }
}
Esempio n. 6
0
void Tank::rotateRight(bool check)
{
    int deg = rspeed;
    degree = checkDegree(degree + deg);
    rotate();

    hdegree = checkDegree(hdegree + deg);
    hrotate();

    if (check == false)
    {
        while (isCollide() == true)
            rotateLeft(check = true);
    }
}
Esempio n. 7
0
bool Map::isTreeCollision(const Player& player) const
{
  // Only check first tree
  const sf::Sprite& tree           = _trees.front();
  const sf::Vector2f& tree_pos     = tree.getPosition();
  const sf::Vector2f& player_pos   = player.getPosition();
  const sf::FloatRect& tree_bounds = tree.getGlobalBounds();

  // If higher than tree, no collision
  if( player_pos.y < tree_pos.y - tree_bounds.height )
    return false;

  return isCollide(player_pos.x, player_pos.x + player.getWidth(),
                   tree_pos.x, tree_pos.x + tree_bounds.width);
}
Esempio n. 8
0
void Tank::moveBack(bool check)
{
    float x1,y1;

    // новые координаты
    x1 = x() - cos(degree * (PI / 180))*speed;
    y1 = y() - sin(degree * (PI / 180))*speed;

    setPos(x1,y1);
    head->setPos(x1,y1);

    if (check == false)
    {
        while (isCollide() == true)
            moveForward(check = true);
    }
}
Esempio n. 9
0
void Tank::rotateLeft(int deg, bool check)
{
    degree = checkDegree(degree - deg);
    rotate();

    hdegree = checkDegree(hdegree - deg);
    hrotate();

    if (check == false)
    {
        while (isCollide() == true)
        {
            isCol = true;
            rotateRight(deg, check = true);
        }
        isCol = false;
    }
}
Esempio n. 10
0
int main()
{
	REG_DISPCTL = MODE3 | BG2_ENABLE;

	//Draw Start Screen
	drawImage3(0, 0, TITLESCREEN_WIDTH, TITLESCREEN_HEIGHT, titleScreen);

	//var to keep track of current position in game
	int inGame = 0;
	int inTitle = 1;

	while(1)
	{

		//START GAME
		if(inTitle == 1 && KEY_DOWN_NOW(BUTTON_START)) {
			inGame = 1;
			inTitle = 0;
			int bgcolor = GRAY;
			DMA[3].src = &bgcolor;
			DMA[3].dst = videoBuffer;
			DMA[3].cnt = 38400 | DMA_SOURCE_FIXED | DMA_DESTINATION_INCREMENT | DMA_ON;

			drawLevel1Board();
			refillLives();
			resetBoard();
		}

		//JUMP BACK TO TITLE SCREEN
		if(KEY_DOWN_NOW(BUTTON_SELECT)) {
			inGame = 0;
			inTitle = 1;
			drawImage3(0, 0, TITLESCREEN_WIDTH, TITLESCREEN_HEIGHT, titleScreen);
		}

		//GAME PLAY
		if(inGame == 1) {
			if(KEY_DOWN_NOW(BUTTON_RIGHT)) {
				moveRight();
			} else if(KEY_DOWN_NOW(BUTTON_LEFT)) {
				moveLeft();
			} else if(KEY_DOWN_NOW(BUTTON_UP)) {
				moveUp();
			} else if(KEY_DOWN_NOW(BUTTON_DOWN)) {
				moveDown();
			}

			waitForVblank();
			clearOld();
			drawCurr();

			//test if reach end of level
			if(isWin() == 1) {
				drawImage3(0, 0, YOUWIN_WIDTH, YOUWIN_HEIGHT, youwin);
				inGame = 0;
				inTitle = 0;
			}

			//test for Collisions with Enemies
			if(isCollide() > 0) {
				if(currLives() > 0) {
					resetBoard();
				} else {
					//out of lives = game over
					inGame = 0;
					inTitle = 0;
					drawImage3(0, 0, GAMEOVER_WIDTH, GAMEOVER_HEIGHT, gameover);
				}
			}

		}
	}
	return 0;

}
Esempio n. 11
0
std::vector<std::map<std::pair<int, int>, std::string> > Map::analyzeFlowMap(){
  bool found = false;
  //  std::vector<std::map<std::pair<int, int>, std::string> > solution = analyzeDotPair(DotsMap.begin(), initMapInfo, found);
  std::vector<PathNodeT*>* pathList = new std::vector<PathNodeT*>;
  std::map<std::string, DotPairT*>::iterator map_it = DotsMap.begin();

  PointT start = map_it->second->loc1;
  PointT end = map_it->second->loc2;
  
  std::queue<PathNodeT*> BFS;
  std::map<std::pair<int, int>, std::string> tmpMap;
  std::map<std::pair<int, int>, std::string> curMapInfo = initMapInfo;
  PathNodeT* curPathNode = new PathNodeT;
  PointT curPoint;
  PointT nextPoint;
  
  curPathNode->prev = NULL;
  curPathNode->cur = start;
  curPathNode->pathMap = curMapInfo;
  
  BFS.push(curPathNode);
  int count1=0;
  while (!BFS.empty()){
    curPathNode = BFS.front();
    curPoint = curPathNode->cur;
    tmpMap = curPathNode->pathMap;
    BFS.pop();
    /*
    if (tmpMap.size() > size * size * factor){
      delete curPathNode;
      break;
    }
    */
    /*
    if (curPoint.x == end.x && curPoint.y == end.y){
      pathList->push_back(curPathNode);
      continue;
    }
    */
    nextPoint =PointT(curPoint.x - 1, curPoint.y);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      std::cout<<++count1<<map_it->first<<std::endl;
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    
    nextPoint =PointT(curPoint.x + 1, curPoint.y);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      std::cout<<++count1<<map_it->first<<std::endl;

      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    nextPoint =PointT(curPoint.x, curPoint.y - 1);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      std::cout<<++count1<<map_it->first<<std::endl;

      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    nextPoint =PointT(curPoint.x, curPoint.y + 1);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      std::cout<<++count1<<map_it->first<<std::endl;

      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    delete curPathNode;
  }
  // Add one path to map and analyze next dot pair
  std::vector<std::map<std::pair<int, int>, std::string> > solutions;
    
  
  //  for (std::vector<PathNodeT*>::iterator it = pathList->begin(); it != pathList->end(); ++it) {
  omp_lock_t lock;
  omp_init_lock(&lock);
  int count = 0;
  #pragma omp parallel for schedule(dynamic)
  for(int i = 0; i < pathList->size(); ++i){
    
    //nextMapInfo = (*it)->pathMap;
    if (!found){
    std::map<std::pair<int, int>, std::string> nextMapInfo;
    std::vector<std::map<std::pair<int, int>, std::string> > tmpSolutions;
    PathNodeT* tmp;

    nextMapInfo = pathList->at(i)->pathMap;
    /*
    tmp = *it;
    while(tmp){
      nextMapInfo.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(tmp->cur.x, tmp->cur.y), map_it->first));
      //nextColorMap.push_back(DotT(map_it->first, tmp->cur));
      tmp = tmp->prev;
    }*/
    std::map<std::string, DotPairT*>::iterator tmpIt = map_it;
    ++tmpIt;
    if (tmpIt == DotsMap.end()){
      omp_set_lock(&lock);
      solutions.push_back(nextMapInfo);
      omp_unset_lock(&lock);
      /* Modified */
      found = true;
      //break;
      //return solutions;
      /* Modified */
    }
    else{
      tmpSolutions = analyzeDotPair(tmpIt, nextMapInfo, found);// Modified
      omp_set_lock(&lock);
      solutions.insert(solutions.end(), tmpSolutions.begin(), tmpSolutions.end());
      omp_unset_lock(&lock);
      //if(!found)
        //std::cout<<++count<<"\t"<<pathList->size()<<std::endl;
      
      /* Modified */
      //if (found){
      //	break;
      //}
        
    }
    }
  }
  
  return solutions;
}
Esempio n. 12
0
void Map::generatePathsForPair(std::string color){
  std::vector<PathNodeT*>* pathList = new std::vector<PathNodeT*>;
  
  PointT start = DotsMap[color]->loc1;
  PointT end = DotsMap[color]->loc2;
  
  std::queue<PathNodeT*> BFS;
  std::map<std::pair<int, int>, std::string> tmpMap;
  PathNodeT* curPathNode = new PathNodeT;
  PointT curPoint;
  PointT nextPoint;
  int count = 0;
  curPathNode->prev = NULL;
  curPathNode->cur = start;
  curPathNode->pathMap = initMapInfo;
  
  BFS.push(curPathNode);
  
  while (!BFS.empty()){
    curPathNode = BFS.front();
    curPoint = curPathNode->cur;
    tmpMap = curPathNode->pathMap;
    BFS.pop();
    if (tmpMap.size()> size*size*factor){
      delete curPathNode;
      break;
    }
    /*
     if (curPoint.x == end.x && curPoint.y == end.y){
     pathList->push_back(curPathNode);
     continue;
     }
     */
    nextPoint =PointT(curPoint.x - 1, curPoint.y);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, tmpMap)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    
    nextPoint =PointT(curPoint.x + 1, curPoint.y);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, tmpMap)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    nextPoint =PointT(curPoint.x, curPoint.y - 1);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, tmpMap)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    nextPoint =PointT(curPoint.x, curPoint.y + 1);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, tmpMap)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), color));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    delete curPathNode;
  }
  
  std::vector<MapInfo> tmp;
  
  for (std::vector<PathNodeT*>::iterator it = pathList->begin();
       it != pathList->end();
       ++it)
    tmp.push_back((*it)->pathMap);
  
  possiblePaths[color] = pathList;
  
  return;
}
Esempio n. 13
0
std::vector<std::map<std::pair<int, int>, std::string> > Map::analyzeDotPair(std::map<std::string, DotPairT*>::iterator map_it, std::map<std::pair<int, int>, std::string> curMapInfo, bool &found){
  if (found){
    std::vector<std::map<std::pair<int, int>, std::string> > something;
    return something;
  }

  std::vector<PathNodeT*>* pathList = new std::vector<PathNodeT*>;
  
  PointT start = map_it->second->loc1;
  PointT end = map_it->second->loc2;
  
  std::queue<PathNodeT*> BFS;
  std::map<std::pair<int, int>, std::string> tmpMap;
  PathNodeT* curPathNode = new PathNodeT;
  PointT curPoint;
  PointT nextPoint;
  
  curPathNode->prev = NULL;
  curPathNode->cur = start;
  curPathNode->pathMap = curMapInfo;
  
  BFS.push(curPathNode);
  
  while (!BFS.empty()){
    curPathNode = BFS.front();
    curPoint = curPathNode->cur;
    tmpMap = curPathNode->pathMap;
    BFS.pop();
    /*
    if ((tmpMap.size() - curMapInfo.size()) >= (size * size - curMapInfo.size()) * factor){
      delete curPathNode;
      break;
    }
     */
    /*
    if (curPoint.x == end.x && curPoint.y == end.y){
      pathList->push_back(curPathNode);
      continue;
    }
    */
    nextPoint =PointT(curPoint.x - 1, curPoint.y);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    
    nextPoint =PointT(curPoint.x + 1, curPoint.y);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    nextPoint =PointT(curPoint.x, curPoint.y - 1);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    
    nextPoint =PointT(curPoint.x, curPoint.y + 1);
    if (nextPoint.x == end.x && nextPoint.y == end.y){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      pathList->push_back(new PathNodeT(curPathNode, nextPoint, tmpMap));
      continue;
    }
    if (!isCollide(curPathNode, nextPoint, curMapInfo)){
      tmpMap = curPathNode->pathMap;
      tmpMap.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(nextPoint.x, nextPoint.y), map_it->first));
      BFS.push(new PathNodeT(curPathNode, nextPoint, tmpMap));
    }
    delete curPathNode;
  }
  // Add one path to map and analyze next dot pair
  std::map<std::pair<int, int>, std::string> nextMapInfo;
  
  std::vector<std::map<std::pair<int, int>, std::string> > solutions;
  std::vector<std::map<std::pair<int, int>, std::string> > tmpSolutions;
  PathNodeT* tmp;
  for (std::vector<PathNodeT*>::iterator it = pathList->begin(); it != pathList->end(); ++it) {
    nextMapInfo = (*it)->pathMap;
    /*
    tmp = *it;
    while(tmp){
      nextMapInfo.insert(std::pair<std::pair<int, int>, std::string>(std::pair<int, int>(tmp->cur.x, tmp->cur.y), map_it->first));
      //nextColorMap.push_back(DotT(map_it->first, tmp->cur));
      tmp = tmp->prev;
    }*/
    std::map<std::string, DotPairT*>::iterator tmpIt = map_it;
    ++tmpIt;
    if (tmpIt == DotsMap.end()){
      solutions.push_back(nextMapInfo);
      /* Modified */
      found = true;
      return solutions;
      /* Modified */
    }
    else{
      tmpSolutions = analyzeDotPair(tmpIt, nextMapInfo, found);// Modified
      /* Modified */
      if (found){
        return tmpSolutions;
      }
        solutions.insert(solutions.end(), tmpSolutions.begin(), tmpSolutions.end());
    }
  }
  //std::cout<<"pass one "<<map_it->first<<std::endl;
  
  return solutions;
}