Exemplo n.º 1
0
Arquivo: Menu.cpp Projeto: 3dik/MPong
//RunEditProfile
bool Menu::RunEditProfile (wstring sName, bool *pbModified)
{
    Err fErr (m_Err, L"RunEditProfile");
    if (sName.empty () || pbModified == NULL)
    {
        return fErr.Set (sERR_ARGUMENTS);
    }

    *pbModified = false;

    Config *pProfile;
    bool bCreated;
    if (!m_pProfiles->GetByName (sName, &pProfile, &bCreated))
    {
        return false;
    }

    wstring sMenuEdit, sLeft, sRight, sSpecial, sSet, sOk, sUndefined;
    if (!m_pLanguage->Get (L"ProfileEditTitle", &sMenuEdit) ||
        !m_pLanguage->Get (L"ProfileEditLeft", &sLeft) ||
        !m_pLanguage->Get (L"ProfileEditRight", &sRight) ||
        !m_pLanguage->Get (L"ProfileEditSpecial", &sSpecial) ||
        !m_pLanguage->Get (L"ProfileEditSet", &sSet) ||
        !m_pLanguage->Get (L"ProfileEditOk", &sOk) ||
        !m_pLanguage->Get (L"ProfileEditUndefined", &sUndefined))
    {
        return false;
    }
    sLeft += L": ";
    sRight += L": ";
    sSpecial += L": ";

    wstring sLeftVal, sRightVal, sSpecialVal;
    if (!pProfile->Get (sKEY_LEFT, &sLeftVal) ||
        !pProfile->Get (sKEY_RIGHT, &sRightVal) ||
        !pProfile->Get (sKEY_SPECIAL, &sSpecialVal))
    {
        return false;
    }

    unsigned int nAction;
    do
    {
        if (sLeftVal.empty ())
        {
            sLeftVal = sUndefined;
        }
        if (sRightVal.empty ())
        {
            sRightVal = sUndefined;
        }
        if (sSpecialVal.empty ())
        {
            sSpecialVal = sUndefined;
        }
        Screen EditScreen;
        if (!EditScreen.Init (&m_Err, m_pProfiles, m_pWindow, sMenuEdit + sName) ||
            !EditScreen.AddLabel (sLeft + sLeftVal, Vector2f (300, 150)) ||
            !EditScreen.AddButton (sSet, Vector2f (50, 140),
                                   eProfileEditButtonLeft) ||
            !EditScreen.AddLabel (sRight + sRightVal, Vector2f (300, 250)) ||
            !EditScreen.AddButton (sSet, Vector2f (50, 240),
                                   eProfileEditButtonRight) ||
            !EditScreen.AddLabel (sSpecial + sSpecialVal,
                                  Vector2f (300, 350)) ||
            !EditScreen.AddButton (sSet, Vector2f (50, 340),
                                   eProfileEditButtonSpecial) ||
            !EditScreen.AddButton (m_sAbort, Vector2f (700, 540),
                                   eProfileEditButtonAbort) ||
            !EditScreen.AddButton (sOk, Vector2f (700, 600),
                                   eProfileEditButtonOk))
        {
            return false;
        }
        if (!EditScreen.Run ())
        {
            return false;
        }
        if (EditScreen.IsQuit ())
        {
            m_bClose = true;
            break;
        }
        if (!EditScreen.GetSelectId (&nAction))
        {
            return false;
        }

        wstring *psCurKey = NULL;
        switch (nAction)
        {
            case (eProfileEditButtonLeft):
                psCurKey = &sLeftVal;
                break;
            case (eProfileEditButtonRight):
                psCurKey = &sRightVal;
                break;
            case (eProfileEditButtonSpecial):
                psCurKey = &sSpecialVal;
                break;
            case (eProfileEditButtonOk):
                pProfile->Set (sKEY_LEFT, sLeftVal);
                pProfile->Set (sKEY_RIGHT, sRightVal);
                pProfile->Set (sKEY_SPECIAL, sSpecialVal);
                if (!pProfile->Save ())
                {
                    return false;
                }
                *pbModified = true;
                nAction = eProfileEditButtonAbort;
                break;
        }

        if (psCurKey != NULL)
        {
            wstring sCode;
            if (!AwaitInput (&sCode))
            {
                return false;
            }
            if (!sCode.empty ())
            {
                *psCurKey = sCode;
            }
        }
    } while (!m_bClose && nAction != eProfileEditButtonAbort);

    return true;
}//RunEditProfile
Exemplo n.º 2
0
int MainProgram()
{
	Screen screen;

	if (screen.Init(0xFFFF00FF) == false)
	{
		std::cout << "Init went wrong" << endl;
		return 1;
	}

	int playerWidth, playerHeight, bulletWidth, bulletHeight;
	Uint32 *imageData = ReadBmp("P:\\My Documents\\Visual Studio 2013\\Projects\\SDLGame\\Debug\\firefox.bmp", playerWidth, playerHeight);
	Uint32 *bulletImage = ReadBmp("P:\\My Documents\\Visual Studio 2013\\Projects\\SDLGame\\Debug\\AimReticle3.bmp", bulletWidth, bulletHeight);
	int elapsed;
	
	float position[2] = { 0, 0 };
	{
		float bulletPos[2] = { 0, 0 };
		float bulletSize[2] = { bulletWidth, bulletHeight };
		Bullet bullet(bulletPos, bulletImage, );

	}

	while (true)
	{
		
		const Uint8* newKeyboardState = SDL_GetKeyboardState(NULL);
		
		if (screen.ProcessEvents() == false)
			break;

		ProcessKeyboard(newKeyboardState, screen);
		elapsed = SDL_GetTicks();

		for (int y = 0; y < screen.SCREEN_HEIGHT; ++y)
		{
			for (int x = 0; x < screen.SCREEN_WIDTH; ++x)
			{
				//screen.SetPixel(x, y, (sin(elapsed / 1000.0) + 1) * 127, sin(((elapsed / 1000.0 + 50) * 2) + 1) * 127, sin(((elapsed / 1000.0 + 120) * 3) + 1) * 127);
			}
		}

		if (imageData == nullptr)
			break;

		position[0] += velocity[0];
		position[1] += velocity[1];

		if (position[1] < 0)
		{
			position[1] = 0;
		}
		else if (position[1] + playerHeight > screen.SCREEN_HEIGHT)
		{
			position[1] = (float)(screen.SCREEN_HEIGHT - playerHeight);
		}
		if (position[0] < 0)
		{
			position[0] = 0;
		}
		else if (position[0] + playerWidth > screen.SCREEN_WIDTH)
		{
			position[0] = (float)(screen.SCREEN_WIDTH - playerWidth);
		}

		for (int y = 0; y < playerHeight; ++y)
		{
			for (int x = 0; x < playerWidth; ++x)
			{
				screen.SetPixel(x + (int)position[0], y + (int)position[1], imageData[(y * playerWidth) + x]);
			}
		}

		screen.Update();
	}
	delete[] imageData;
	screen.Close();
	return 0;
}