Esempio n. 1
0
bool getInput (Level* level)
{
    char input;

    input = getch();

    switch (input)
    {
    case 'w':
        moveHero(level, d_up);
        break;

    case 'a':
        moveHero(level, d_left);
        break;

    case 's':
        moveHero(level, d_down);
        break;

    case 'd':
        moveHero(level, d_right);
        break;

    case 'q':
        return false;
        break;
    }

    return true;
}
Esempio n. 2
0
void Hero::collisionHeroWithY(std::vector<lv::Object> &objSolid, float frametime)
{
	for (int i = 0; i < objSolid.size(); i++)
	{
		float SolidCenterX = objSolid[i].rect.left + objSolid[i].rect.width / 2;
		float SolidCenterY = objSolid[i].rect.top; +objSolid[i].rect.height / 2;
		H_RotationForSolid = (atan2(getHeroCenter().y - SolidCenterY, getHeroCenter().x - SolidCenterX)) * 180 / 3.14159265;
		H_Top1_Rotation = (atan2(objSolid[i].Tops.top - getHeroCenter().y, objSolid[i].Tops.left - getHeroCenter().x)) * 180 / 3.14159265;
		H_Top2_Rotation = (atan2(objSolid[i].Tops.height - getHeroCenter().y, objSolid[i].Tops.width - getHeroCenter().x)) * 180 / 3.14159265;

		if (playerHitbox.getGlobalBounds().intersects(objSolid[i].rect))
		{



			if (H_RotationForSolid >= objSolid[i].rotation.left && H_RotationForSolid <= objSolid[i].rotation.top)
			{

				moveHero(0, -H_Gravi*H_Speed*frametime);
				H_onGround = true;
			}
			else
			{
				if (H_Top1_Rotation >= D_3&& H_Top1_Rotation <= D_4)
				{
					moveHero(0, -H_Gravi*H_Speed*frametime);
					H_onGround = true;
					collisionY = true;
				}
				else
				{
					if (H_Top2_Rotation >= D_3&& H_Top2_Rotation <= D_4)
					{
						moveHero(0, -H_Gravi*H_Speed*frametime);
						H_onGround = true;
						collisionY = true;
					}
				}

			}
			if (H_Jump == true)
			{
				H_JumpIndex = 0;
				collisionY = true;
			}


		}
		else { collisionY = false; }


	}
}
Esempio n. 3
0
void Hero::collisionHeroWithX(std::vector<lv::Object> &objSolid, float frametime)
{
	for (int i = 0; i < objSolid.size(); i++)
	{
		float SolidCenterX = objSolid[i].rect.left + objSolid[i].rect.width / 2;
		float SolidCenterY = objSolid[i].rect.top; +objSolid[i].rect.height / 2;
		H_RotationForSolid = (atan2(getHeroCenter().y - SolidCenterY, getHeroCenter().x - SolidCenterX)) * 180 / 3.14159265;
		H_Top1_Rotation = (atan2(objSolid[i].Tops.top - getHeroCenter().y, objSolid[i].Tops.left - getHeroCenter().x)) * 180 / 3.14159265;
		H_Top2_Rotation = (atan2(objSolid[i].Tops.height - getHeroCenter().y, objSolid[i].Tops.width - getHeroCenter().x)) * 180 / 3.14159265;


		if (playerHitbox.getGlobalBounds().intersects(objSolid[i].rect))
		{
			if (H_Top1_Rotation >= D_3&& H_Top1_Rotation <= D_4)
			{
				continue;
			}

			//Лево
			if (H_RotationForSolid >= objSolid[i].rotation.top && H_RotationForSolid <= 0)
			{

				moveHero(H_Speed*frametime, 0);


			}
			if (H_RotationForSolid >= 0 && H_RotationForSolid <= objSolid[i].rotation.height)
			{

				moveHero(H_Speed*frametime, 0);

			}
			// Право
			if (H_RotationForSolid >= -179.999 && H_RotationForSolid <= objSolid[i].rotation.left)
			{

				moveHero(-H_Speed*frametime, 0);


			}
			if (H_RotationForSolid >= objSolid[i].rotation.width && H_RotationForSolid <= 180)
			{

				moveHero(-H_Speed*frametime, 0);

			}

		}

	}

}
Esempio n. 4
0
void Hero::heroControl(std::vector<lv::Object> &solidObj, std::vector<lv::Object> &groundObj, float frametime)
{

	heroKeyPressed(K_ON);//функция управления персонажем
	HeroJump(frametime);

	H_Animation.setPosition(getHeroPossition().x, getHeroPossition().y);// из за не пропорционально расположения скарлет в кадре приходится двигать отдельные анимации и возвращять все обратно 


	switch (state)//тут делаются различные действия в зависимости от состояния
	{ //// тут надо разбираться с анимацией
	case left: if (FireState != Fire){ moveHero(-H_Speed*frametime, 0); if (H_onGround == true) { H_Animation.play(H_MassAnim[3]); } }  break;//состояние идти влево
	case right:if (FireState != Fire){ moveHero(H_Speed*frametime, 0); if (H_onGround == true) { H_Animation.play(H_MassAnim[2]); } }break; //состояние идти вправо      
	};
	if (isMove == false && FireState != Fire &&  StayState == StayRight){ H_Animation.play(H_MassAnim[2]); H_Animation.stop(0); } // Пока нету анимаций стоя 

	if (isMove == false && FireState != Fire &&  StayState == StayLeft){ H_Animation.play(H_MassAnim[3]); H_Animation.stop(0); } // Пока нету анимаций стоя 

	if (FireState == Fire && state == left){
		moveHero(-H_Speed*frametime, 0); if (H_onGround == true)
		{
			H_Animation.setPosition(getHeroPossition().x - 81, getHeroPossition().y); H_Animation.play(H_MassAnim[5]);
		}
	}// бегим в лево и стреляем 

	if (FireState == Fire && state == right){
		moveHero(H_Speed*frametime, 0); if (H_onGround == true)
		{
			H_Animation.play(H_MassAnim[4]);
		}
	} // бегим в право и стреляем 

	if (FireState == Fire && isMove == false && StayState == StayLeft)
	{
		H_Animation.setPosition(getHeroPossition().x - 81, getHeroPossition().y); H_Animation.play(H_MassAnim[6]);
	};//стоим в лево и стреляем 

	if (FireState == Fire && isMove == false && StayState == StayRight){ H_Animation.play(H_MassAnim[7]); };// стоим в право и стреляем 

	if (JumpState == JumpStay  && H_onGround == false && StayState == StayLeft){ H_Animation.play(H_MassAnim[3]); }

	if (JumpState == JumpStay  && H_onGround == false && StayState == StayRight){ H_Animation.play(H_MassAnim[2]); }

	if (JumpState == JumpStay  && H_onGround == false && state == right){ H_Animation.play(H_MassAnim[2]); }

	if (isMove == false){ ; state = stay; }

	if (!H_Jump){ JumpState = NoJump; }

}
Esempio n. 5
0
void Hero::updateGravi(float frametime)
{
	if (H_GraviForUpdate)
	{
		moveHero(0, H_Gravi*H_Speed*frametime);
	}

}
Esempio n. 6
0
void RoleShow::changeHero(int currentHero,const CCPoint& offsetPoint)
{

	if(m_currentHero == currentHero) return;

	heroAngle = 2;
	if(currentHero == k_battle_blackwidow)
	{
		firegunEffect();
	} else
	{
		if(pFiregun)
		{
			pFiregun->stopAllActions();
			pFiregun->removeFromParent();
			pFiregun = NULL;
		}
	}

	m_currentHero = currentHero;
	m_offsetPoint = offsetPoint;

	TString zhujiaoname;
	zhujiaoname += "hero";
	zhujiaoname += currentHero;
	zhujiaoname += "_middle1.png";
	zhujiao->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(zhujiaoname.data()));

	TString zhujiaolegname;
	zhujiaolegname += "hero";
	zhujiaolegname += currentHero;
	zhujiaolegname += "_middleleg.png";
	zhujiaoleg -> setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(zhujiaolegname.data()));

	zhujiaogun->cleanup();
	if (currentHero != 3)
	{
		TString zhujiaogunname;
		zhujiaogunname += "hero";
		zhujiaogunname += currentHero;
		zhujiaogunname += "_gun1.png";
		zhujiaogun->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(zhujiaogunname.data()));

		zhujiaogun -> setVisible(true);
		zhujiao->setPosition(ccp(5, -offsetPoint.y));
	}
	else
	{
		zhujiaogun -> setVisible(false);
		float pY = zhujiao->getPositionY();
		zhujiao->setPosition(ccp(7, -20-offsetPoint.y));

	}

	moveHero();
}
Esempio n. 7
0
/*1 黑寡妇 2 金刚狼 3 钢铁侠
*/
void RoleShow::showHeroAnimation(int currentHero,const CCPoint& offsetPoint)
{
	if(currentHero == k_battle_blackwidow)
	{
		firegunEffect();
	}
	
	m_currentHero = currentHero;
	m_offsetPoint = offsetPoint;

	//窗口大小
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	TString zhujiaoname;
	zhujiaoname += "hero";
	zhujiaoname += currentHero;
	zhujiaoname += "_middle1.png";
	zhujiao = CCSprite::create();
	zhujiao->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(zhujiaoname.data()));
	zhujiao->setAnchorPoint(ccp(0.5f, 0.0f));
	//zhujiao->setPosition(ccp(x-20, y-15-offsetY));
	zhujiao->setPosition(ccp(0-offsetPoint.x, 0-offsetPoint.y));

	addChild(zhujiao, 1004);

	TString zhujiaolegname;
	zhujiaolegname += "hero";
	zhujiaolegname += currentHero;
	zhujiaolegname += "_middleleg.png";
	zhujiaoleg = CCSprite::createWithSpriteFrameName(zhujiaolegname.data());
//	zhujiaoleg -> setPosition(ccp(x, y-offsetY));
	zhujiaoleg->setAnchorPoint(ccp(0.5f, 0.0f));
	zhujiaoleg -> setPosition(ccp(20-offsetPoint.x, -15-offsetPoint.y));

	addChild(zhujiaoleg, 1002);


	//主角动画   主角 关卡信息都要根据传入的来
	TString zhujiaogunname;
	zhujiaogunname += "hero";
	zhujiaogunname += currentHero;
	zhujiaogunname += "_gun1.png";
	zhujiaogun = CCSprite::create();
	zhujiaogun->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(zhujiaogunname.data()));
	float anchorPointY = 20/zhujiaogun -> getContentSize().height;
	zhujiaogun->setAnchorPoint(ccp(0.5f, -anchorPointY));
	zhujiaogun->setPosition(ccp(0-offsetPoint.x, 20-offsetPoint.y));
	addChild(zhujiaogun, 1003);

	moveHero();
}
Esempio n. 8
0
void Hero::HeroJump(float frametime)
{

	if (H_Jump == true)
	{
		if (H_JumpIndex <= 1.1)
		{
			H_JumpIndex = H_JumpIndexOld;
			H_Jump = false;
			JumpState = NoJump;
			return;
		}

		moveHero(0, -H_JumpIndex*H_Speed*frametime);
		H_JumpIndex -= 0.1;
		H_onGround = false;
	}


}
Esempio n. 9
0
void RoleShow::roleChangeAngle(float dt)
{
	if(heroAngleOrien)
	{
		heroAngle++;
	} else 
	{
		heroAngle--;
	}

	if(heroAngle > 30 && heroAngleOrien)
	{
		heroAngle = 30;
		heroAngleOrien = false;
	} else if(heroAngle < -30)  
	{
		heroAngle = -30;
		heroAngleOrien = true;
	}

	moveHero();
	
}
Esempio n. 10
0
SGSPointList& SGSTerrain::calcHeroAvailabePath(SGSHero* hero)
{
  static SGSPointList valid_path_list; 
  SGSPointList::iterator path_list_iter;
  // clear the list;
  for (path_list_iter = valid_path_list.begin(); path_list_iter != valid_path_list.end();) {
    path_list_iter = valid_path_list.erase(path_list_iter);
  }

  int hero_stamina = hero->getStamina();
  // A* algorithm
  StepList open_list;
  StepList close_list;


  Step start_step;
  start_step.__pos = hero->getMapPosition();
  start_step.__stamina = hero_stamina;
  open_list.push_back(start_step);

  while(!open_list.empty()) {
    Step open_step = open_list.front();
    open_list.pop_front();

    for (int i = STEP_RIGHT; i <= STEP_UP; i++) {
      Step temp_move = moveHero(hero, (STEP_DIRECTION) i, open_step);
      if (temp_move.__stamina >=0 ) { // valid move
        if (!isInStepList(temp_move, open_list) && !isInStepList(temp_move, close_list)) {
          open_list.push_back(temp_move);
        } else if(isInStepList(temp_move, open_list)) { // in Open list
          StepList::iterator iter;
          if (open_list.size()) {
            for (iter = open_list.begin(); iter != open_list.end(); iter++) {
              Step one_step_in_openlist = *iter;
              if (one_step_in_openlist.__pos == temp_move.__pos) {
                if (one_step_in_openlist.__stamina < temp_move.__stamina) {
                  open_list.remove(one_step_in_openlist);
                  open_list.push_back(temp_move);
                  log("replace open list x = %d y = %d", temp_move.__pos.x, temp_move.__pos.y);
                }
              }
            }
          }
        } else { // in close list
          StepList::iterator iter;
          for (iter = close_list.begin(); iter != close_list.end(); iter++) {
            Step one_step_in_closelist = *iter;
            if (one_step_in_closelist.__pos == temp_move.__pos) {
              if (one_step_in_closelist.__stamina < temp_move.__stamina) {
                close_list.remove(one_step_in_closelist);
                open_list.push_back(temp_move);
              }
            } 

          }
        }

      } 
    }
    close_list.push_back(open_step);
  }

  StepList::iterator iter;
  for (iter = close_list.begin(); iter != close_list.end(); iter++) {
    Step one_step = *iter;
    valid_path_list.push_back(one_step.__pos);

  }
  return valid_path_list;

}
Esempio n. 11
0
SGSPointList& SGSTerrain::calcShortestPath(SGSHero* hero, SGSPoint& target_pos)
{
  static SGSPointList shortest_path_list; 
  SGSPointList::iterator shortest_path_list_iter;
  // clear the list;
  for (shortest_path_list_iter = shortest_path_list.begin(); shortest_path_list_iter != shortest_path_list.end();) {
    shortest_path_list_iter = shortest_path_list.erase(shortest_path_list_iter);
  }
  // A* algorithm
  StepPtrList open_list;
  StepPtrList close_list;

  Step* start_step = new Step;
  start_step->__pos = hero->getMapPosition();

  start_step->__stamina = 100;
  start_step->__parent = NULL;
  open_list.push_back(start_step);

  Step* last_step = NULL;

  while(!open_list.empty()) {
    Step* open_step = open_list.front();
    open_list.pop_front();
    if (open_step->__pos == target_pos) {
      last_step = open_step;
      break;
    }
    for (int i = STEP_RIGHT; i <= STEP_UP; i++) {
      Step* temp_move = new Step;
      *temp_move = moveHero(hero, (STEP_DIRECTION) i, *open_step);
      if (temp_move->__stamina >=0 ) { // valid move
        if (!isInStepPtrList(temp_move, open_list) && !isInStepPtrList(temp_move, close_list)) {
          temp_move->__parent = open_step;
          open_list.push_back(temp_move);
        } else if(isInStepPtrList(temp_move, open_list)) { // in Open list
          StepPtrList::iterator iter;
          for (iter = open_list.begin(); iter != open_list.end(); iter++) {
            Step* one_step_in_openlist = *iter;
            if (one_step_in_openlist->__pos == temp_move->__pos) {
              if (one_step_in_openlist->__stamina < temp_move->__stamina) {
                //iter = open_list.erase(iter);
                open_list.remove(one_step_in_openlist);
                delete one_step_in_openlist;
                open_list.push_back(temp_move);
                break;
              }
            } 
          }
        } else { // in close list
          StepPtrList::iterator iter;
          for (iter = close_list.begin(); iter != close_list.end(); iter++) {
            Step* one_step_in_closelist = *iter;
            if (one_step_in_closelist->__pos == temp_move->__pos) {
              if (one_step_in_closelist->__stamina < temp_move->__stamina) {
                close_list.remove(one_step_in_closelist);
                delete one_step_in_closelist;
                open_list.push_back(temp_move);
                break;
              }
            } 

          }
        }
        
      } else {
        delete temp_move;
      }
      
    }
    close_list.push_back(open_step);
  }
  while(last_step)
  {
    shortest_path_list.insert(shortest_path_list.begin(), last_step->__pos);
    last_step = last_step->__parent;
  }


  // clear the list;
  StepPtrList::iterator ptr_list_iter;
  for (ptr_list_iter = open_list.begin(); ptr_list_iter != open_list.end();) {
    Step* one_step_in_openlist = *ptr_list_iter;
    ptr_list_iter = open_list.erase(ptr_list_iter);
    delete one_step_in_openlist;
  }
  for (ptr_list_iter = close_list.begin(); ptr_list_iter != close_list.end();) {
    Step* one_step_in_closelist = *ptr_list_iter;
    ptr_list_iter = close_list.erase(ptr_list_iter);
    delete one_step_in_closelist;
  }  
  return shortest_path_list;

}