Example #1
0
void HUD::Draw(void)
{
	ProcessNumber(m_PlayerScore, m_PlayerScoreLocation, 7);
	ProcessNumber(m_PlayerHighScore, m_PlayerHighScoreLocation, 5);

	for (int ship = 0; ship < m_PlayerHitsLeft; ship++)
	{
		float scale = 1;
		float rotation = Pi * 1.5f;
		Vector2f location = Vector2f(10 + ship * 10, 30);
		pShip->Update(&rotation, &location, &scale);
		pShip->Draw(&ShipColor);
	}

	// Draw Game Over text
	if (m_GameOver)
	{
		int size = 15;
		int Textsize = m_GameText[0].size();
		int space = float((-size * 3) * (Textsize - 1) / 2);

		for (int letter = 0; letter < Textsize; letter++)
		{
			if ((int)m_GameText[0][letter] > 64 && (int)m_GameText[0][letter] < 91)
				DrawLetter(Vector2i(m_GameOverLocation.x + space, m_GameOverLocation.y), (int)m_GameText[0][letter] - 65, size);

			space += float(size * 2.666);
		}

		//Instructions
		if (!m_NewScore)
		{
			size = 4;

			for (int line = 1; line < 5; line++)
			{
				Textsize = m_GameText[line].size();
				space = float((-size * 3) * (Textsize - 1) / 2);

				for (int letter = 0; letter < Textsize; letter++)
				{
					if ((int)m_GameText[line][letter] > 64 && (int)m_GameText[line][letter] < 91)
						DrawLetter(Vector2i(m_GameTextLocation.x + space, m_GameTextLocation.y + ((line - 1) * 30)),
						(int)m_GameText[line][letter] - 65, size);

					space += size * 3;
				}
			}
		}

		//High score text If game over, and player shot hits something, new score is ignored for high score. Change when game over.
		size = 5;
		Textsize = m_GameText[5].size();
		space = float((-size * 3) * (Textsize - 1) / 1.45);

		for (int letter = 0; letter < Textsize; letter++)
		{
			if ((int)m_GameText[5][letter] > 64 && (int)m_GameText[5][letter] < 91)
				DrawLetter(Vector2i(m_HighScoreListLocaiton.x + space, m_HighScoreListLocaiton.y - 40),
				(int)m_GameText[5][letter] - 65, size);

			space += size * 3;
		}

		//High score list
		for (int line = 0; line < 5; line++)
		{
			space = 0;

			for (int letter = 0; letter < 3; letter++)
			{
				if ((int)m_HiScores[(m_HighScoreDisplay * 5) + line].Name[letter] > -1 &&
					(int)m_HiScores[(m_HighScoreDisplay * 5) + line].Name[letter] < 26)
					DrawLetter(Vector2i(m_HighScoreListLocaiton.x + 40 + space, m_HighScoreListLocaiton.y + (line * 30)),
						m_HiScores[(m_HighScoreDisplay * 5) + line].Name[letter], size);

				space += size * 3;
			}

			ProcessNumber(m_HiScores[(m_HighScoreDisplay * 5) + line].Score,
				Vector2i(m_HighScoreListLocaiton.x, m_HighScoreListLocaiton.y + (line * 30)), 9);

			ProcessNumber((m_HighScoreDisplay * 5) + line + 1, 
				Vector2i(m_HighScoreListLocaiton.x - 160, m_HighScoreListLocaiton.y + (line * 30)), 9);
		}
		// End Game Over text.

		// If new high score
		if (m_NewScore)
		{
			if (!m_Done)
			{
				int displayScoreY = 170;
				size = 5;
				Textsize = m_GameText[6].size();
				space = float((-size * 3) * (Textsize - 1) / 1.45);

				for (int letter = 0; letter < Textsize; letter++)
				{
					if ((int)m_GameText[6][letter] > 64 && (int)m_GameText[6][letter] < 91)
						DrawLetter(Vector2i(m_HighScoreListLocaiton.x + space, m_HighScoreListLocaiton.y + displayScoreY),
						(int)m_GameText[6][letter] - 65, size);

					space += size * 3;
				}

				Textsize = m_GameText[7].size();
				space = float((-size * 3) * (Textsize - 1) / 1.8);

				for (int letter = 0; letter < Textsize; letter++)
				{
					if ((int)m_GameText[7][letter] > 64 && (int)m_GameText[7][letter] < 91)
						DrawLetter(Vector2i(m_HighScoreListLocaiton.x + space, m_HighScoreListLocaiton.y + displayScoreY + 30),
						(int)m_GameText[7][letter] - 65, size);

					space += size * 3;
				}

				//Display high score editing
				space = -45;

				for (int letter = 0; letter < 3; letter++)
				{
						DrawLetter(Vector2i(m_HighScoreListLocaiton.x + space, m_HighScoreListLocaiton.y + displayScoreY + 70),
							m_NewHiScore.Name[letter], size);

					space += size * 3;
				}
			}
		}
	}
}
Example #2
0
//--------------------------------------------------------------------------------------------------
static void ProcessChar
(
    Parser_t* parserPtr,
    char c
)
//--------------------------------------------------------------------------------------------------
{
    switch (parserPtr->next)
    {
        case EXPECT_OBJECT_OR_ARRAY:

            // Throw away whitespace characters until '{' or '[' is found.
            if (c == '{')
            {
                PushContext(parserPtr, LE_JSON_CONTEXT_OBJECT, GetEventHandler(parserPtr));
                parserPtr->next = EXPECT_MEMBER_OR_OBJECT_END;
                Report(parserPtr, LE_JSON_OBJECT_START);
            }
            else if (c == '[')
            {
                PushContext(parserPtr, LE_JSON_CONTEXT_ARRAY, GetEventHandler(parserPtr));
                parserPtr->next = EXPECT_VALUE_OR_ARRAY_END;
                Report(parserPtr, LE_JSON_ARRAY_START);
            }
            else if (!isspace(c))
            {
                Error(parserPtr, LE_JSON_SYNTAX_ERROR, "Document must start with '{' or '['.");
            }
            return;

        case EXPECT_MEMBER_OR_OBJECT_END:

            // Throw away whitespace until a '"' or '}' is found.
            if (c == '}')   // Object end found.
            {
                Report(parserPtr, LE_JSON_OBJECT_END);
                PopContext(parserPtr);
            }
            else if (c == '"')  // Start of member name (string) found.
            {
                PushContext(parserPtr, LE_JSON_CONTEXT_MEMBER, GetEventHandler(parserPtr));
                parserPtr->next = EXPECT_STRING;
            }
            else if (!isspace(c))
            {
                Error(parserPtr,
                      LE_JSON_SYNTAX_ERROR,
                      "Expected end of object (}) or beginning of object member name (\").");
            }
            return;

        case EXPECT_COLON:

            // Throw away whitespace until a ':' is found.
            if (c == ':')
            {
                parserPtr->next = EXPECT_VALUE;
            }
            else if (!isspace(c))
            {
                Error(parserPtr,
                      LE_JSON_SYNTAX_ERROR,
                      "Expected ':' after object member name.");
            }
            return;

        case EXPECT_VALUE:

            ParseValue(parserPtr, c);
            return;

        case EXPECT_COMMA_OR_OBJECT_END:

            // Throw away whitespace until a ',' or '}' is found.
            if (c == '}')   // Object end found.
            {
                Report(parserPtr, LE_JSON_OBJECT_END);
                PopContext(parserPtr);
            }
            else if (c == ',')  // Comma separator found.
            {
                parserPtr->next = EXPECT_MEMBER;
            }
            else if (!isspace(c))
            {
                Error(parserPtr,
                      LE_JSON_SYNTAX_ERROR,
                      "Expected end of object (}) or beginning of object member name (\").");
            }
            return;

        case EXPECT_MEMBER:

            // Throw away whitespace until a '"' is found.
            if (c == '"')  // Start of member name (string) found.
            {
                PushContext(parserPtr, LE_JSON_CONTEXT_MEMBER, GetEventHandler(parserPtr));
                parserPtr->next = EXPECT_STRING;
            }
            else if (!isspace(c))
            {
                Error(parserPtr,
                      LE_JSON_SYNTAX_ERROR,
                      "Expected beginning of object member name (\").");
            }
            return;

        case EXPECT_VALUE_OR_ARRAY_END:

            if (c == ']')
            {
                Report(parserPtr, LE_JSON_ARRAY_END);
                PopContext(parserPtr);
            }
            else
            {
                ParseValue(parserPtr, c);
            }
            return;

        case EXPECT_COMMA_OR_ARRAY_END:

            // Throw away whitespace until a ',' or ']' is found.
            if (c == ']')   // Array end found.
            {
                Report(parserPtr, LE_JSON_ARRAY_END);
                PopContext(parserPtr);
            }
            else if (c == ',')  // Comma separator found.
            {
                parserPtr->next = EXPECT_VALUE;
            }
            else if (!isspace(c))
            {
                Error(parserPtr,
                      LE_JSON_SYNTAX_ERROR,
                      "Expected end of array (]) or a comma separator (,).");
            }
            return;

        case EXPECT_STRING:

            ParseString(parserPtr, c);
            return;

        case EXPECT_NUMBER:

            if ((c == '.') || isdigit(c))
            {
                AddToBuffer(parserPtr, c);
            }
            else
            {
                ProcessNumber(parserPtr);
                ProcessChar(parserPtr, c);
            }
            return;

        case EXPECT_TRUE:

            ParseConstant(parserPtr, c, "true");
            if (strcmp(parserPtr->buffer, "true") == 0)
            {
                Report(parserPtr, LE_JSON_TRUE);
                PopContext(parserPtr);
            }
            return;

        case EXPECT_FALSE:

            ParseConstant(parserPtr, c, "false");
            if (strcmp(parserPtr->buffer, "false") == 0)
            {
                Report(parserPtr, LE_JSON_FALSE);
                PopContext(parserPtr);
            }
            return;

        case EXPECT_NULL:

            ParseConstant(parserPtr, c, "null");
            if (strcmp(parserPtr->buffer, "null") == 0)
            {
                Report(parserPtr, LE_JSON_NULL);
                PopContext(parserPtr);
            }
            return;

        case EXPECT_NOTHING:    ///< Parsing stopped.
            return;
    }

    LE_FATAL("Internal error: Invalid JSON parser expectation %d.", parserPtr->next);
}