Example #1
0
void GameMap::onPlayerFinishOneStep( const Index2& index, MoveStatus ms )
{
	m_objects[index.first][index.second]->checkPlayerFinished(m_pPlayer);

	if (GameStateMgr::inst().curState()==gs_win)
	{
		m_curPath.clear();
	}
	else if(ms != msFullyFinish)
	{
		m_curPath.clear();
	}
	else
	{
		//dig surrounding
		dig(index);		

		if (m_restartPlayer)
		{
			m_restartPlayer = false;
			m_curPath.clear();
			auto x = pointToIndex2(m_pPlayer->getPosition());
			m_curPath = getPath( x, pointToIndex2(m_playerTarget) );
			stepPlayer();
		}
		else if (!m_curPath.empty())
		{
			m_curPath.pop_front();
			stepPlayer();
		}
	}
}
	void SpaceInvadersModel::step() {

		handleAllCollisions();
		//If the level ended during collision handling, notify observers and end step
		if (levelOver_) {
			notifyObservers();
			return;
		}
		//Perform steps for all MobileEntities
		stepPlayer();
		stepRegularAliens();
		stepBonusAlien();
		//Bullets just move every step, no separate function needed
		for (auto i : bullets_) {
			i->move(bulletMoveDistance_);
		}
		//Notify observers of state of game after step
		notifyObservers();
		winner_ = false; //This needs to be reset after notifying
	}
Example #3
0
void GameMap::onClick( const Point& pt )
{
	m_pPlayer->hideTip();

	Index2 click = pointToIndex2(pt);
	Index2 player = pointToIndex2(m_pPlayer->getPosition());

	CCLOG("click(%d, %d)", click.first, click.second);
	Rect asdf = this->getBoundingBox();
	if (m_bUsingHoe)
	{
		vector<Index2> surround = getSurrounding( player, 2);
		for (Index2& x : surround)
		{
			m_objects[x.first][x.second]->onEffectHoe(false, click==x);
		}
		m_bUsingHoe = false;
		return;
	}
	//
	if (m_bUsingBomb)
	{
		vector<Index2> surround = getSurrounding(player, 2);
		for (Index2& x : surround)
		{
			m_objects[x.first][x.second]->onEffectBomb(false, click==x);
		}
		m_bUsingBomb = false;
		return;
	}
	//
	if (m_bUsingMap)
	{
		m_bUsingMap = false;
		vector<Index2> surround = getSurrounding(player, 2);
		for (Index2& x : surround)
		{
			m_objects[x.first][x.second]->onEffectMap(false);
		}
	}

	Return_If(player == click);
	
	//
	if (m_curPath.empty())
	{
		m_restartPlayer = false;
		auto x = player;
		m_curPath = getPath( x, click );
		if (m_curPath.empty())
		{
			m_pPlayer->showTip("unknown.png");
		}
		else
		{
			stepPlayer();
		}
	}
	else
	{
		m_restartPlayer = true;
		m_playerTarget = pt;
	}
}