* Make the Bomberman draw itself.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Tue, 12 Jun 2007 06:15:27 +0000 (08:15 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Tue, 12 Jun 2007 06:15:27 +0000 (08:15 +0200)
 * Make the Bomberman respond to key events.

ABM2/Playground.cpp
ABM2/Playground.h
ABM2/main.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
index 879b4b005b7241050d3973950882bbf2d6168f84..99896744af2675deb649af4f06644b6cdc340999 100755 (executable)
@@ -16,7 +16,7 @@ enum TMoveDirection { N,NNE,NE,NEE,E,SEE,SE,SSE,S,SSW,SW,SWW,W,NWW,NW,NNW }; //(
 class Bomberman\r
 {\r
 public:\r
-       Bomberman(int xloc, int yloc);\r
+       Bomberman(const CMMPointer<Sprite> &sprite, int xloc, int yloc);\r
        ~Bomberman();\r
        void Update();\r
        void move(int xloc, int yloc);\r
@@ -34,9 +34,7 @@ public:
        int getFieldCenterY();\r
 private:\r
        int x,y;\r
-#ifdef WIN32\r
-       LPDIRECT3DTEXTURE9 texture;\r
-#endif // WIN32\r
+       CMMPointer<Sprite> sprite;\r
 };\r
 \r
 class Tile\r
index 66f44f96f44e538283b34931bdd5b7e29fc0bffd..8e3adf95344b497686b387df3141fd3db0b703ca 100755 (executable)
@@ -15,8 +15,9 @@
 #define SCREEN_HEIGHT 480\r
 \r
 SpriteData defaultSprites[] = {\r
-       {SPR_FIELD, "Data/FIELD0.png", SCREEN_WIDTH, SCREEN_HEIGHT},\r
-       {SPR_TILE, "Data/Tiles0.png", FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT},\r
+       {SPR_FIELD,    "Data/FIELD0.png",     SCREEN_WIDTH,      SCREEN_HEIGHT},\r
+       {SPR_TILE,     "Data/Tiles0.png",     FIELD_UNIT_WIDTH,  FIELD_UNIT_HEIGHT},\r
+       {SPR_PLAYER,   "Data/POWBOMB.png",    FIELD_UNIT_WIDTH,  FIELD_UNIT_HEIGHT},\r
        {SPR_NONE, NULL, 0, 0}\r
 };\r
 \r