X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=ABM2%2FPlayground.cpp;h=ef34150251d1d2b02055b82743d55af86dc2019f;hb=5fb8c983f7ac6de040c33787f20b16027d7c08d2;hp=a7edd74752e1ab3e1cc067bf63c36489bc87f890;hpb=0835c5605c80efd286ccb7eff92fffc07689f359;p=matthijs%2FABM2.git diff --git a/ABM2/Playground.cpp b/ABM2/Playground.cpp index a7edd74..ef34150 100755 --- a/ABM2/Playground.cpp +++ b/ABM2/Playground.cpp @@ -1,13 +1,20 @@ #include "Playground.h" +#include "Engine/engine.h" #include "Engine/VideoUpdate.h" #include "SchemeReader.h" +#if WIN32 LPD3DXSPRITE d3dspt; LPD3DXFONT font; +#endif + +Playground::Playground(CKernel* kernel) : ITask(kernel) { } + bool Playground::Start() { + #if WIN32 background = NULL; foreground = NULL; font = NULL; @@ -61,35 +68,39 @@ bool Playground::Start() } } + #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]) { case BRICK: - //field[i][j] = new Item(foreground, 0, FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT, i, j); + subsprite = SPR_SUB_BRICK; break; case SOLID: - field[i][j] = new Item(foreground, 1, FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT, i, j); + subsprite = SPR_SUB_SOLID; break; } + if (subsprite != -1) + field[i][j] = new Tile(tile_sprite, subsprite, i, j); + else + field[i][j] = 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(0, 0, 255, 255)); for (int i=0; iUpdate(); if (CInputTask::keyDown(DIK_RIGHT)) this->move_right(); if (CInputTask::keyDown(DIK_LEFT)) this->move_left(); @@ -165,7 +170,7 @@ void Playground::Update() RECT rect3 = {310,10,500,36}; sprintf(buf, "(%d, %d) - (%d,%d)", bomberman->getFieldCenterX(), bomberman->getFieldCenterY(), bomberman->getOffsetX(), bomberman->getOffsetY()); font->DrawTextA(NULL, (char *)&buf, -1, &rect3, DT_LEFT, D3DCOLOR_XRGB(255,255,255)); - + #endif // WIN32 old_counter = GetTickCount(); } @@ -177,10 +182,12 @@ 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() @@ -351,23 +358,29 @@ void Playground::move_right() Bomberman::Bomberman(int xloc, int yloc) { + #ifdef WIN32 HRESULT res = D3DXCreateTextureFromFile(d3ddev, L"data/powkick.png", &texture); if (res != D3D_OK) texture = NULL; + #endif // WIN32 x = xloc; y = yloc; } Bomberman::~Bomberman() { + #ifdef WIN32 if (texture != NULL) texture->Release(); + #endif // WIN32 } void Bomberman::Update() { + #ifdef WIN32 D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner D3DXVECTOR3 position((FLOAT)x, (FLOAT)y, 0.0f); // position at 50, 50 with no depth RECT rect = {0,0,40,36}; d3dspt->Draw(texture, &rect, ¢er, &position, D3DCOLOR_XRGB(255,255,255)); + #endif // WIN32 } void Bomberman::move(int xloc, int yloc) @@ -473,28 +486,32 @@ void Bomberman::move_to_direction(TMoveDirection dir) } // ============================================= -// Item class +// Tile class // ============================================= -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() { + 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(0, 0, 0, 255) + ); +#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 }