void clsStateMenu::Init(LPDIRECT3DDEVICE9 d3ddev, LPD3DXSPRITE _SpriteHandler)
{
	//D3DXCreateSprite(d3ddev, &_SpriteHandler);
	Background = CreateSurfaceFromFile(d3ddev,"images\\Background.png");
	MenuButton = new clsAnimation(_SpriteHandler,"images\\menu_a.png",300,50,4,1, 100);
	MenuButtonHightLight = new clsAnimation(_SpriteHandler,"images\\menu_b.png",300,50,4,1, 100);
}
Ejemplo n.º 2
0
void CMarioGame::LoadResources(LPDIRECT3DDEVICE9 d3ddv)
{
    srand((unsigned)time(NULL));

    // TO-DO: not a very good place to initial sprite handler
    D3DXCreateSprite(d3ddv, &_SpriteHandler);


    _Background = CreateSurfaceFromFile(_d3ddv, BACKGROUND_FILE);

    HRESULT res = D3DXCreateSprite(_d3ddv, &_SpriteHandler);

    //khởi tạo mario
    mario_x = 20;
    mario_y = GROUND_Y;

    _IsOnGround = true;

    mario_vx = 0;
    mario_vx_last = 1.0f;
    mario_vy = 0;

    marioSprite = new CSprite(_SpriteHandler, MARIO_IMAGE, 36, 34, 50, 18);

    mario = new Mario(mario_x, mario_y, 36, 34, mario_vx, 0, 0, MARIO_ACCELERATION_X , 0, NULL, marioSprite, NULL, NULL);

    // One sprite only :)
    ground_middle = new CSprite(_SpriteHandler, GROUND_MIDDLE, 32, 32, 1, 1);
    brick = new CSprite(_SpriteHandler, BRICK, 32, 32, 1, 1);

    fallDown = new CSprite(_SpriteHandler, CHECK_FALL, 4, 619, 1, 1);
    //fallBox = new Object(600, 0, 4, 619, 0, 0, fallDown);
    //_CollisionBox = new Object(mario_x, mario_y, 32, 32, mario_vx, mario_vy, mario_right);
    _IsFallOfGround = false;


}
//---------------------------------------------------------------------
// Creates a DirectComposition visual tree and places each visual 
// inside the application window
//---------------------------------------------------------------------
HRESULT CApplication::CreateDCompositionVisualTree()
{
    static const WCHAR *filename = L"220Strawberry.png";
    static const float tileSize = 0.3f * WINDOW_SIZE;
    static const int visualChildCount = sizeof(_visualChild) / sizeof(_visualChild[0]);
    static const float d = 2.0f * WINDOW_SIZE;

    HRESULT hr = ((_device == nullptr) || (_hwnd == NULL)) ? E_UNEXPECTED : S_OK;

    int bitmapWidth = 0;
    int bitmapHeight = 0;

    CComPtr<IDCompositionSurface> surface;

    // Create DirectComposition surface from the bitmap file
    if (SUCCEEDED(hr))
    {
        hr = CreateSurfaceFromFile(filename, &bitmapWidth, &bitmapHeight, &surface);
    }

    if (SUCCEEDED(hr))
    {
        _bitmapWidth = bitmapWidth;
        _bitmapHeight = bitmapHeight;

        hr = _device->CreateVisual(&_visual);
    }

    // Set the content of each visual to be the surface that was created from the bitmap
    if (SUCCEEDED(hr))
    {
        for (int i = 0; SUCCEEDED(hr) && i < visualChildCount; ++i)
        {
            hr = _device->CreateVisual(&_visualChild[i]);

            if (SUCCEEDED(hr))
            {
                hr = _visual->AddVisual(_visualChild[i], FALSE, nullptr);
            }

            if (SUCCEEDED(hr))
            {
                hr = _visualChild[i]->SetContent(surface);
            }
        }
    }

    // Using DirectComposition transforms to scale and place each visual such that the tiles 
    // are side by side within the application window
    if (SUCCEEDED(hr))
    {
        for (int i = 0; SUCCEEDED(hr) && i < visualChildCount; ++i)
        {
            //setting up scale transform on each visual
            CComPtr<IDCompositionScaleTransform> scaleTransform;

            if (SUCCEEDED(hr))
            {
                hr = _device->CreateScaleTransform(&scaleTransform);
            }
            
            float sx = tileSize / bitmapWidth;

            if (SUCCEEDED(hr))
            {
                hr = scaleTransform->SetScaleX(sx);
            }

            float sy = tileSize / bitmapHeight;

            if (SUCCEEDED(hr))
            {
                hr = scaleTransform->SetScaleY(sy);
            }

            //Setting up a translate transform on each visual
            CComPtr<IDCompositionTranslateTransform> translateTransform;

            if (SUCCEEDED(hr))
            {
                hr = _device->CreateTranslateTransform(&translateTransform);
            }

            float x = (visualChildCount - 1 - i) * TILE_SPACING;
            float y = TILE_SPACING + 30;

            if (SUCCEEDED(hr))
            {
                hr = translateTransform->SetOffsetX(x);
            }

            if (SUCCEEDED(hr))
            {
                hr = translateTransform->SetOffsetY(y);
            }

            // Creating a transform group to group the two transforms together such that 
            // they can be applied at once.
            IDCompositionTransform *transforms[] = 
            { 
                scaleTransform,
                translateTransform,
            };

            CComPtr<IDCompositionTransform> transformGroup;
            if (SUCCEEDED(hr))
            {
                _device->CreateTransformGroup(transforms, sizeof(transforms)/sizeof(transforms[0]), &transformGroup);
            }
            if (SUCCEEDED(hr))
            {
                _visualChild[i]->SetTransform(transformGroup);
            }
        }
    }

    return hr;
}