* Add SPR_SUB constants.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 20:17:24 +0000 (22:17 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 20:17:24 +0000 (22:17 +0200)
 * Rename Item to Tile.
 * Modify Tile constructor for SDL.

ABM2/Engine/engine.h
ABM2/Playground.cpp
ABM2/Playground.h

index 58bb4c42dc58058044b79989b56a71d577468ea4..73b70168a0a96aeeb39dff6c586298c9c1fca1d3 100755 (executable)
@@ -66,4 +66,10 @@ enum SpriteID {
        SPR_PLAYER,\r
 };\r
 \r
+enum {\r
+       SPR_SUB_BRICK = 0,\r
+       SPR_SUB_SOLID = 1,\r
+       SPR_SUB_CLEAR = 2,\r
+};\r
+\r
 #endif\r
index 41c8b4b55fd81e407adec9a2e3202dc2f2fbdb0d..27f1f72ee591df6d8e244bdddfd71116348ce17a 100755 (executable)
@@ -79,27 +79,33 @@ bool Playground::Start()
                }\r
        }\r
 \r
+       CMMPointer<Sprite> tile_sprite = this->getKernel()->getSpriteManager()->getSprite(SPR_TILE);\r
        // put in non-destructible blocks\r
        for (int i=0; i<PLAYGROUND_COLS; i++) \r
+       {\r
                for (int j=0; j<PLAYGROUND_ROWS; j++)\r
+               {\r
+                       int subsprite = -1;\r
                        switch(scheme->PlayField[j*PLAYGROUND_NUMFIELD_X+i]) {\r
                                case BRICK:\r
-                                       //field[i][j] = new Item(foreground, 0, FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT, i, j);\r
+                                       subsprite = SPR_SUB_BRICK;\r
                                        break;\r
                                case SOLID:\r
-                                       #ifdef WIN32\r
-                                       field[i][j] = new Item(foreground, 1, FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT, i, j);\r
-                                       #endif // WIN32\r
+                                       subsprite = SPR_SUB_SOLID;\r
                                        break;\r
                        }\r
+                       if (subsprite != -1)\r
+                               field[i][j] = new Tile(tile_sprite, subsprite, i, j);\r
+               }\r
+       }\r
 /*\r
        // put in desctructible blocks with chance 90%\r
        for (int i=0; i<PLAYGROUND_COLS; i+=2) \r
                for (int j=0; j<PLAYGROUND_ROWS; ++j)\r
-                       if ((double)rand()/RAND_MAX <= 0.9) field[i][j] = new Item(foreground, 0, i, j);\r
+                       if ((double)rand()/RAND_MAX <= 0.9) field[i][j] = new Tile(foreground, 0, i, j);\r
        for (int i=1; i<PLAYGROUND_COLS; i+=2) \r
                for (int j=0; j<PLAYGROUND_ROWS; j+=2)\r
-                       if ((double)rand()/RAND_MAX <= 0.9) field[i][j] = new Item(foreground, 0, i, j);\r
+                       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
@@ -128,16 +134,6 @@ void Playground::Update()
        CMMPointer<Sprite> s = this->getKernel()->getSpriteManager()->getSprite(SPR_FIELD);\r
        \r
        s->blit(0, 0, 1.0, 1.0, 0, 0, COLOUR_RGBA(0, 0, 255, 255));\r
-       #ifdef WIN32\r
-       if(CInputTask::keyDown(DIK_ESCAPE))CKernel::GetSingleton().KillAllTasks();\r
-\r
-       d3dspt->Begin(NULL);    // begin sprite drawing\r
-\r
-       // draw the sprite\r
-       D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);    // center at the upper-left corner\r
-       D3DXVECTOR3 position(0.0f, 0.0f, 0.0f);    // position at 50, 50 with no depth\r
-       d3dspt->Draw(background, NULL, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));\r
-\r
        for (int i=0; i<PLAYGROUND_COLS; ++i) \r
        {\r
                for (int j=0; j<PLAYGROUND_ROWS; ++j)\r
@@ -146,6 +142,7 @@ 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
@@ -494,32 +491,27 @@ void Bomberman::move_to_direction(TMoveDirection dir)
 }\r
 \r
 // =============================================\r
-// Item class\r
+// Tile class\r
 // =============================================\r
 \r
-#ifdef WIN32\r
-Item:: Item(LPDIRECT3DTEXTURE9 t, int texnr, int subwidth, int subheight, int colnr, int rownr)\r
+Tile::Tile(const CMMPointer<Sprite> &sprite, int subsprite, int col, int row)\r
 {\r
-       texture = t;\r
-       col = colnr;\r
-       row = rownr;\r
-       tex_num = texnr;\r
-       subitem_height = subheight;\r
-       subitem_width = subwidth;\r
+       this->sprite = sprite;\r
+       this->col = col;\r
+       this->row = row;\r
+       this->subsprite = subsprite;\r
 }\r
-#endif // WIN32\r
 \r
-Item::~Item()\r
+Tile::~Tile()\r
 {\r
 }\r
-\r
-#ifdef WIN32\r
-void Item::Draw()\r
+void Tile::Draw()\r
 {\r
+#ifdef WIN32\r
        D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);    // center at the upper-left corner\r
        D3DXVECTOR3 position((FLOAT)PLAYGROUND_BORDER_LEFT+subitem_width*col, (FLOAT)PLAYGROUND_BORDER_TOP+subitem_height*row, 0.0f);    // position at 50, 50 with no depth\r
        RECT rect = {tex_num*subitem_width,0,(tex_num+1)*subitem_width,subitem_height};\r
        d3dspt->Draw(texture, &rect, &center, &position, D3DCOLOR_ARGB(255, 255,255,255));\r
+#endif // WIN32\r
 }\r
 \r
-#endif // WIN32\r
index 20d10522c07eee8628b45c322b86460ac338aa7f..9cb5e22063f7ca47c2ccfc8d137da2bef014159c 100755 (executable)
@@ -39,19 +39,15 @@ private:
 #endif // WIN32\r
 };\r
 \r
-class Item\r
+class Tile\r
 {\r
 public:\r
-#ifdef WIN32\r
-       Item(LPDIRECT3DTEXTURE9 t, int texnr, int subwidth, int subheight, int colnr, int rownr);\r
-#endif // WIN32\r
-       ~Item();\r
+       Tile(const CMMPointer<Sprite> &sprite, int subsprite, int col, int row);\r
+       ~Tile();\r
        void Draw();\r
-       int col, row, tex_num, subitem_height, subitem_width;\r
 private:\r
-#ifdef WIN32\r
-       LPDIRECT3DTEXTURE9 texture;\r
-#endif // WIN32\r
+       CMMPointer<Sprite> sprite;\r
+       int col, row, subsprite;\r
 };\r
 \r
 class Playground : public ITask\r
@@ -69,7 +65,7 @@ private:
 #endif // WIN32\r
 \r
        Bomberman *bomberman;\r
-       Item *field[PLAYGROUND_COLS][PLAYGROUND_ROWS];\r
+       Tile *field[PLAYGROUND_COLS][PLAYGROUND_ROWS];\r
 \r
        void move_up();\r
        void move_down();\r