Exemplo n.º 1
0
inline bool bmlparser::getline(bool allow_empty)
{
nextline:
	if (!m_data)
	{
null:
		m_thisline = "";
		m_indent = "";
		return true;
	}
	
	m_thisline = cutline(m_data);
	size_t indentlen = bml_size_white(m_thisline);
	if (indentlen == m_thisline.length())
	{
		if (allow_empty) goto nextline;
		else goto null;
	}
	
	int sharedindent = min(indentlen, m_indent.length());
	bool badwhite = (memcmp(m_thisline.bytes().ptr(), m_indent.bytes().ptr(), sharedindent)!=0);
	
	m_indent = cut(m_thisline, 0, indentlen, 0);
	
	return !badwhite;
}
Exemplo n.º 2
0
void GameHandler::step_physic()
{
	if (gamestate == PAUSED || gamestate == CUTPAUSED_PAUSED)
		return;
	else if (gamestate == CUTPAUSED)
	{
		if (--cutpausecontdown)
			return;
		else
		{
			gamestate = RUNNING;
			// Effectively cut lines at the end of the cutpause
			for (float i = 0.0; i < gameopt.rows; i += gameopt.rowwidth)
			{
				if (linesbeingcut[i])
					cutline(i, i + gameopt.rowwidth);
			}

			linesbeingcut = linesfalse;
			newrandompiece();
		}
	}
	bool checklineandnewpiece = false, callgameover = false;

	nextpiece_rot += gameopt.physicstep;
	nextpiece_rot = fmod(nextpiece_rot, 2*M_PI);

	physichandler.step(level, [&](float x, float y)
	{
		if (gamestate == GAMEOVER)
			return;
		// The falling piece has landed:
		// time to generate another piece if the screen is not full
		physichandler.untagfallingpiece();

		if (y > 0)
			checklineandnewpiece = true;
		else
			callgameover = true;
	});
	if (checklineandnewpiece && gameopt.gametype == GameOptions::CUTTING)
	{
		float totalcuttedarea = 0.0;
		int cuttedlines = 0;
		updatelinearea();
		for (float i = 0.0; i < gameopt.rows; i += gameopt.rowwidth)
		{
			if (linearea[i] > gameopt.cuttingrowarea)
			{
				// Cutting should happened
				totalcuttedarea = linearea[i];
				cuttedlines++;
				linesbeingcut[i] = true;
			}
		}
		if (cuttedlines != 0)
		{
			// Update score
			int scoreadd = ceil(pow((cuttedlines*3),pow((totalcuttedarea/(10*cuttedlines)),10))*20+cuttedlines*cuttedlines*40);
			score += scoreadd;
			linesortiles += cuttedlines;
			level = linesortiles/10;

			updatescoregraphic();

			// Set all pieces velocity to 0
			physichandler.iteratepieces([&](PhysicPiece * php){
				php->standstill();
			});

			gamestate = CUTPAUSED;
			//TODO: make this parametric
			cutpausecontdown = 60;

			// Return!! Avoid creating newpiece
			return;
		}

		newrandompiece();
	}
	else if (checklineandnewpiece && gameopt.gametype == GameOptions::STACK)
	{
		score += 100;
		linesortiles += 1;
		level = 0;

		updatescoregraphic();
		newrandompiece();
	}

	if (callgameover)
	{
		physichandler.gameover();
		gamestate = GAMEOVER;
	}
	if (gamestate == GAMEOVER)
	{
		bool nopiece = true;
		physichandler.iteratepieces([&](PhysicPiece * php){
			nopiece = false;
			//If piece fallen outside of the screen
			if (php->getY() > gameopt.rows + 4 * gameopt.rowwidth )
			{
				GamePiece * pgp = static_cast<GamePiece*>(php->getUserData());
				deletepiece(pgp);
			}
		});
		if (nopiece)
		{
			//END GAME
		}
	}

}