* Make the Bomberman draw itself.
[matthijs/ABM2.git] / ABM2 / Playground.cpp
index 38c905f9907d117325c924dfadf071b1888c7440..05de6c177cc8b08dd4611efc48e77e820df789f3 100755 (executable)
@@ -42,7 +42,8 @@ bool Playground::Start()
                        if ((double)rand()/RAND_MAX <= 0.9) field[i][j] = new Tile(foreground, 0, i, j);\r
 */     \r
        // put in a player\r
-       bomberman = new Bomberman(20, 66);\r
+       CMMPointer<Sprite> player_sprite = this->getKernel()->getSpriteManager()->getSprite(SPR_PLAYER);\r
+       bomberman = new Bomberman(player_sprite, 20, 66);\r
        if (field[0][0] != NULL)\r
        {\r
                delete field[0][0];\r
@@ -76,14 +77,14 @@ void Playground::Update()
                }\r
        }\r
 \r
-       #ifdef WIN32\r
        bomberman->Update();\r
-       if (CInputTask::keyDown(DIK_RIGHT)) this->move_right();\r
-       if (CInputTask::keyDown(DIK_LEFT)) this->move_left();\r
-       if (CInputTask::keyDown(DIK_UP)) this->move_up();\r
-       if (CInputTask::keyDown(DIK_DOWN)) this->move_down();\r
+       if (CInputTask::keyDown(SDLK_RIGHT)) this->move_right();\r
+       if (CInputTask::keyDown(SDLK_LEFT)) this->move_left();\r
+       if (CInputTask::keyDown(SDLK_UP)) this->move_up();\r
+       if (CInputTask::keyDown(SDLK_DOWN)) this->move_down();\r
 \r
 \r
+       #ifdef WIN32\r
        d3dspt->End();    // end sprite drawing\r
 \r
        // do fps thingie\r
@@ -289,31 +290,24 @@ void Playground::move_right()
 // Bomberman class\r
 // =============================================\r
 \r
-Bomberman::Bomberman(int xloc, int yloc)\r
+Bomberman::Bomberman(const CMMPointer<Sprite> &sprite, int xloc, int yloc)\r
 {\r
-       #ifdef WIN32\r
-       HRESULT res = D3DXCreateTextureFromFile(d3ddev, L"data/powkick.png", &texture);\r
-       if (res != D3D_OK) texture = NULL;\r
-       #endif // WIN32\r
-       x = xloc;\r
-       y = yloc;\r
+       this->sprite = sprite;\r
+       this->x = xloc;\r
+       this->y = yloc;\r
 }\r
 \r
 Bomberman::~Bomberman()\r
 {\r
-       #ifdef WIN32\r
-       if (texture != NULL) texture->Release();\r
-       #endif // WIN32\r
 }\r
 \r
 void Bomberman::Update()\r
 {\r
-       #ifdef WIN32\r
-       D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);    // center at the upper-left corner\r
-       D3DXVECTOR3 position((FLOAT)x, (FLOAT)y, 0.0f);    // position at 50, 50 with no depth\r
-       RECT rect = {0,0,40,36};\r
-       d3dspt->Draw(texture, &rect, &center, &position, D3DCOLOR_XRGB(255,255,255));\r
-       #endif // WIN32\r
+       this->sprite->blit(\r
+               this->x,\r
+               this->y,\r
+               1.0, 1.0, 0, 0, COLOUR_RGBA(255, 255, 255, 255)\r
+       );\r
 }\r
 \r
 void Bomberman::move(int xloc, int yloc)\r