From 4ab7ea7617b0c8cb1ab19bea1d439b3d1bb9839c Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 11 Jun 2007 22:17:24 +0200 Subject: [PATCH] * Add SPR_SUB constants. * Rename Item to Tile. * Modify Tile constructor for SDL. --- ABM2/Engine/engine.h | 6 +++++ ABM2/Playground.cpp | 54 +++++++++++++++++++------------------------- ABM2/Playground.h | 16 +++++-------- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/ABM2/Engine/engine.h b/ABM2/Engine/engine.h index 58bb4c4..73b7016 100755 --- a/ABM2/Engine/engine.h +++ b/ABM2/Engine/engine.h @@ -66,4 +66,10 @@ enum SpriteID { SPR_PLAYER, }; +enum { + SPR_SUB_BRICK = 0, + SPR_SUB_SOLID = 1, + SPR_SUB_CLEAR = 2, +}; + #endif diff --git a/ABM2/Playground.cpp b/ABM2/Playground.cpp index 41c8b4b..27f1f72 100755 --- a/ABM2/Playground.cpp +++ b/ABM2/Playground.cpp @@ -79,27 +79,33 @@ bool Playground::Start() } } + CMMPointer tile_sprite = this->getKernel()->getSpriteManager()->getSprite(SPR_TILE); // put in non-destructible blocks for (int i=0; iPlayField[j*PLAYGROUND_NUMFIELD_X+i]) { case BRICK: - //field[i][j] = new Item(foreground, 0, FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT, i, j); + subsprite = SPR_SUB_BRICK; break; case SOLID: - #ifdef WIN32 - field[i][j] = new Item(foreground, 1, FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT, i, j); - #endif // WIN32 + subsprite = SPR_SUB_SOLID; break; } + if (subsprite != -1) + field[i][j] = new Tile(tile_sprite, subsprite, i, j); + } + } /* // put in desctructible blocks with chance 90% for (int i=0; i s = this->getKernel()->getSpriteManager()->getSprite(SPR_FIELD); s->blit(0, 0, 1.0, 1.0, 0, 0, COLOUR_RGBA(0, 0, 255, 255)); - #ifdef WIN32 - if(CInputTask::keyDown(DIK_ESCAPE))CKernel::GetSingleton().KillAllTasks(); - - d3dspt->Begin(NULL); // begin sprite drawing - - // draw the sprite - D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner - D3DXVECTOR3 position(0.0f, 0.0f, 0.0f); // position at 50, 50 with no depth - d3dspt->Draw(background, NULL, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255)); - for (int i=0; iUpdate(); if (CInputTask::keyDown(DIK_RIGHT)) this->move_right(); if (CInputTask::keyDown(DIK_LEFT)) this->move_left(); @@ -494,32 +491,27 @@ void Bomberman::move_to_direction(TMoveDirection dir) } // ============================================= -// Item class +// Tile class // ============================================= -#ifdef WIN32 -Item:: Item(LPDIRECT3DTEXTURE9 t, int texnr, int subwidth, int subheight, int colnr, int rownr) +Tile::Tile(const CMMPointer &sprite, int subsprite, int col, int row) { - texture = t; - col = colnr; - row = rownr; - tex_num = texnr; - subitem_height = subheight; - subitem_width = subwidth; + this->sprite = sprite; + this->col = col; + this->row = row; + this->subsprite = subsprite; } -#endif // WIN32 -Item::~Item() +Tile::~Tile() { } - -#ifdef WIN32 -void Item::Draw() +void Tile::Draw() { +#ifdef WIN32 D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner 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 RECT rect = {tex_num*subitem_width,0,(tex_num+1)*subitem_width,subitem_height}; d3dspt->Draw(texture, &rect, ¢er, &position, D3DCOLOR_ARGB(255, 255,255,255)); +#endif // WIN32 } -#endif // WIN32 diff --git a/ABM2/Playground.h b/ABM2/Playground.h index 20d1052..9cb5e22 100755 --- a/ABM2/Playground.h +++ b/ABM2/Playground.h @@ -39,19 +39,15 @@ private: #endif // WIN32 }; -class Item +class Tile { public: -#ifdef WIN32 - Item(LPDIRECT3DTEXTURE9 t, int texnr, int subwidth, int subheight, int colnr, int rownr); -#endif // WIN32 - ~Item(); + Tile(const CMMPointer &sprite, int subsprite, int col, int row); + ~Tile(); void Draw(); - int col, row, tex_num, subitem_height, subitem_width; private: -#ifdef WIN32 - LPDIRECT3DTEXTURE9 texture; -#endif // WIN32 + CMMPointer sprite; + int col, row, subsprite; }; class Playground : public ITask @@ -69,7 +65,7 @@ private: #endif // WIN32 Bomberman *bomberman; - Item *field[PLAYGROUND_COLS][PLAYGROUND_ROWS]; + Tile *field[PLAYGROUND_COLS][PLAYGROUND_ROWS]; void move_up(); void move_down(); -- 2.30.2