X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=ABM2%2FPlayground.cpp;h=38c905f9907d117325c924dfadf071b1888c7440;hb=75d4212e8548f64904bad6d7f8978c077e6687d0;hp=edf532567810cc65b9604ebbf8327df29019df07;hpb=ef328ea4a5e0e2f76f474d3b452e8b35b7fb2995;p=matthijs%2FABM2.git diff --git a/ABM2/Playground.cpp b/ABM2/Playground.cpp index edf5325..38c905f 100755 --- a/ABM2/Playground.cpp +++ b/ABM2/Playground.cpp @@ -1,101 +1,45 @@ #include "Playground.h" +#include "Engine/engine.h" #include "Engine/VideoUpdate.h" #include "SchemeReader.h" -#if WIN32 -LPD3DXSPRITE d3dspt; -LPD3DXFONT font; +Playground::Playground(CKernel* kernel) : ITask(kernel) { } -#endif bool Playground::Start() { - #if WIN32 - background = NULL; - foreground = NULL; - font = NULL; - HRESULT res; - - D3DXCreateSprite(d3ddev, &d3dspt); // create the Direct3D Sprite object - res = D3DXCreateFont(d3ddev, 15, 10, 0, 1, false, 0, OUT_TT_ONLY_PRECIS, 0, 0, L"times new roman", &font); - if (res != S_OK) - { - switch (res) - { - case D3DERR_INVALIDCALL: - foreground = NULL; - break; - case D3DXERR_INVALIDDATA: - foreground = NULL; - break; - case E_OUTOFMEMORY: - foreground = NULL; - break; - default: - foreground = NULL; - } - } - - res = D3DXCreateTextureFromFile(d3ddev, L"data/field0.png", &background); - //res = D3DXCreateTextureFromFile(d3ddev, L"data/tiles0.png", &foreground); - res = D3DXCreateTextureFromFileEx(d3ddev, L"data/tiles0.png", D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN, - D3DPOOL_DEFAULT ,D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_ARGB(0, 248, 0, 248), NULL, NULL, &foreground); - if (res != D3D_OK) - { - switch (res) - { - case D3DERR_NOTAVAILABLE: - foreground = NULL; - break; - case D3DERR_OUTOFVIDEOMEMORY: - foreground = NULL; - break; - case D3DERR_INVALIDCALL: - foreground = NULL; - break; - case D3DXERR_INVALIDDATA: - foreground = NULL; - break; - case E_OUTOFMEMORY: - foreground = NULL; - break; - default: - foreground = NULL; - } - } - - #endif // init playing field - SchemeReader *scheme = new SchemeReader("data/schemes/BASIC.SCH"); - for (int i=0; i tile_sprite = this->getKernel()->getSpriteManager()->getSprite(SPR_TILE); // put in non-destructible blocks - for (int i=0; iPlayField[j*PLAYGROUND_NUMFIELD_X+i]) { + for (int col=0; colPlayField[row*PLAYGROUND_NUMFIELD_X+col]) { 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[col][row] = new Tile(tile_sprite, subsprite, col, row); + else + field[col][row] = NULL; + } + } /* // put in desctructible blocks with chance 90% for (int i=0; iBegin(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)); - + CMMPointer s = this->getKernel()->getSpriteManager()->getSprite(SPR_FIELD); + + s->blit(0, 0, 1.0, 1.0, 0, 0, COLOUR_RGBA(255, 255, 255, 255)); for (int i=0; iUpdate(); if (CInputTask::keyDown(DIK_RIGHT)) this->move_right(); if (CInputTask::keyDown(DIK_LEFT)) this->move_left(); @@ -184,12 +121,6 @@ void Playground::Stop() if (field[i][j] != NULL) delete field[i][j]; if (bomberman != NULL) delete bomberman; - #ifdef WIN32 - if (background != NULL) background->Release(); - if (foreground != NULL) foreground->Release(); - if (d3dspt != NULL) d3dspt->Release(); - if (font != NULL) font->Release(); - #endif // WIN32 } void Playground::move_down() @@ -488,30 +419,26 @@ 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; } -Item::~Item() +Tile::~Tile() { } - -void Item::Draw() +void Tile::Draw() { - 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)); + this->sprite->blit( + PLAYGROUND_BORDER_LEFT + this->col * FIELD_UNIT_WIDTH, + PLAYGROUND_BORDER_TOP + this->row * FIELD_UNIT_HEIGHT, + 1.0, 1.0, this->subsprite, 0, COLOUR_RGBA(255, 255, 255, 255) + ); } -#endif // WIN32