예제 #1
0
/** @param a_ms timse (in milliseconds) since the last update. updates the game logic */
void Game::update(int a_ms)
{
	Player * p;
	Enemy * e;

	for(int i = 0; i < m_playerList.getSize(); ++i)
	{
		p = (Player*)m_playerList.get(i);
		
		if(p != (Player*)m_playerList.get(0))
		{
			e = (Enemy*)p;
			if(m_powerUpTimeLeft > 0)
				e->setIcon(1);
			else
				e->setIcon(2);
			e->ai(a_ms);
		}

		int nextMove = p->getNextMove();

		if(nextMove == PLAYER_MOVE_UP && (p->getY() <= 0 || m_map.getAt(p->getX(),p->getY()-1) == '#'))
			p->setNextMove(PLAYER_MOVE_NONE); 
		if(nextMove == PLAYER_MOVE_DOWN && (p->getY() >= m_map.getHeight() - 1 || m_map.getAt(p->getX(),p->getY()+1) == '#'))
			p->setNextMove(PLAYER_MOVE_NONE);
		if(nextMove == PLAYER_MOVE_LEFT && (p->getX() <= 0 || m_map.getAt(p->getX() - 1, p->getY()) == '#'))
			p->setNextMove(PLAYER_MOVE_NONE);
		if(nextMove == PLAYER_MOVE_RIGHT && (p->getX() >= m_map.getWidth() - 1 || m_map.getAt(p->getX() + 1,p->getY()) == '#'))
			p->setNextMove(PLAYER_MOVE_NONE);

		if(p != (Player*)m_playerList.get(0))
			e->move();
		else
			p->update(a_ms);

		if(m_map.getAt(p->getX(),p->getY()) == 'O')
		{
			if(p == (Player*)m_playerList.get(0))
				m_running = -1;
			else if(p == (Player*)m_playerList.get(1))
				m_running = -2;

		}
	}
	timeTilRotation -= a_ms;
	if(timeTilRotation <= 0)
	{
		rotateMap();
		int rotationTime = rand() % 6 + 1;
		timeTilRotation += rotationTime * 1000;
	}

}