From: Matthijs Kooijman Date: Tue, 12 Jun 2007 06:15:27 +0000 (+0200) Subject: * Make the Bomberman draw itself. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=a4a0e436bb55c33e9f8a624f90a5512671b14559;p=matthijs%2FABM2.git * Make the Bomberman draw itself. * Make the Bomberman respond to key events. --- diff --git a/ABM2/Playground.cpp b/ABM2/Playground.cpp index 38c905f..05de6c1 100755 --- a/ABM2/Playground.cpp +++ b/ABM2/Playground.cpp @@ -42,7 +42,8 @@ bool Playground::Start() if ((double)rand()/RAND_MAX <= 0.9) field[i][j] = new Tile(foreground, 0, i, j); */ // put in a player - bomberman = new Bomberman(20, 66); + CMMPointer player_sprite = this->getKernel()->getSpriteManager()->getSprite(SPR_PLAYER); + bomberman = new Bomberman(player_sprite, 20, 66); if (field[0][0] != NULL) { delete field[0][0]; @@ -76,14 +77,14 @@ void Playground::Update() } } - #ifdef WIN32 bomberman->Update(); - if (CInputTask::keyDown(DIK_RIGHT)) this->move_right(); - if (CInputTask::keyDown(DIK_LEFT)) this->move_left(); - if (CInputTask::keyDown(DIK_UP)) this->move_up(); - if (CInputTask::keyDown(DIK_DOWN)) this->move_down(); + if (CInputTask::keyDown(SDLK_RIGHT)) this->move_right(); + if (CInputTask::keyDown(SDLK_LEFT)) this->move_left(); + if (CInputTask::keyDown(SDLK_UP)) this->move_up(); + if (CInputTask::keyDown(SDLK_DOWN)) this->move_down(); + #ifdef WIN32 d3dspt->End(); // end sprite drawing // do fps thingie @@ -289,31 +290,24 @@ void Playground::move_right() // Bomberman class // ============================================= -Bomberman::Bomberman(int xloc, int yloc) +Bomberman::Bomberman(const CMMPointer &sprite, 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; + this->sprite = sprite; + this->x = xloc; + this->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 + this->sprite->blit( + this->x, + this->y, + 1.0, 1.0, 0, 0, COLOUR_RGBA(255, 255, 255, 255) + ); } void Bomberman::move(int xloc, int yloc) diff --git a/ABM2/Playground.h b/ABM2/Playground.h index 879b4b0..9989674 100755 --- a/ABM2/Playground.h +++ b/ABM2/Playground.h @@ -16,7 +16,7 @@ enum TMoveDirection { N,NNE,NE,NEE,E,SEE,SE,SSE,S,SSW,SW,SWW,W,NWW,NW,NNW }; //( class Bomberman { public: - Bomberman(int xloc, int yloc); + Bomberman(const CMMPointer &sprite, int xloc, int yloc); ~Bomberman(); void Update(); void move(int xloc, int yloc); @@ -34,9 +34,7 @@ public: int getFieldCenterY(); private: int x,y; -#ifdef WIN32 - LPDIRECT3DTEXTURE9 texture; -#endif // WIN32 + CMMPointer sprite; }; class Tile diff --git a/ABM2/main.cpp b/ABM2/main.cpp index 66f44f9..8e3adf9 100755 --- a/ABM2/main.cpp +++ b/ABM2/main.cpp @@ -15,8 +15,9 @@ #define SCREEN_HEIGHT 480 SpriteData defaultSprites[] = { - {SPR_FIELD, "Data/FIELD0.png", SCREEN_WIDTH, SCREEN_HEIGHT}, - {SPR_TILE, "Data/Tiles0.png", FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT}, + {SPR_FIELD, "Data/FIELD0.png", SCREEN_WIDTH, SCREEN_HEIGHT}, + {SPR_TILE, "Data/Tiles0.png", FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT}, + {SPR_PLAYER, "Data/POWBOMB.png", FIELD_UNIT_WIDTH, FIELD_UNIT_HEIGHT}, {SPR_NONE, NULL, 0, 0} };