JumpingBlock.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:3k
- #ifndef _JUMPINGBLOCK_HPP
- #define _JUMPINGBLOCK_HPP
- //-----------------------------------------------------------------------------------------------------
- class JumpingBlock: public GameObject
- {
- private:
- int mCol;
- int mRow;
- JQuad* mBlock;
- Question* question;
- int questionNO;
- bool mGoingUp;
- bool banana;
- float mOldY;
-
- TileMap* mMap;
- u8 mTileInfo;
- short mTile;
-
- public:
- bool questioned;
- JumpingBlock(GameStatePlay* app);
- virtual ~JumpingBlock();
- virtual void Update(float dt);
- virtual void Render();
- void SelectBlock(int n);
-
- void Animate(int col, int row);
- };
- JumpingBlock::JumpingBlock(GameStatePlay* app): GameObject(app)
- {
- mMap = mApp->GetTileMap();
- mBlock = new JQuad(mTexture, 0.0f, 96.0f, 32.0f, 32.0f);
-
- // questioned = false;
- }
- JumpingBlock::~JumpingBlock()
- {
-
- }
- void JumpingBlock::Update(float dt)
- {
- if (mGoingUp)
- {
- if (mTileInfo == BLOCK_BANANA)
- {
- mMap->SetTileInfo(mCol, mRow, 0);
- banana = true;
- questioned = false;
- mApp->SetBanana(mApp->GetBanana()+1);
-
-
- }
- else if (mTileInfo == BLOCK_APPLE)
- {
- //JumpingCoin* banana = mApp->GetJumpingCoin();
- mMap->SetTileInfo(mCol, mRow, 0);
- banana = false;
- questioned = false;
- mApp->SetBanana(mApp->GetApple()+1);
-
- }
- else if(mTileInfo == BLOCK_QUES)
- {
- banana = false;
-
- }
- else
- {
- mY -= BLOCK_SPEED*dt;
- if (mY < mOldY-16.0f)
- {
- mGoingUp = false;
- }
- }
- //if(!questioned)
-
-
- }
- else
- {
- mY += BLOCK_SPEED*dt;
- if (mY > mOldY)
- {
- mY = mOldY;
- mActive = false;
- mMap->SetTile(mCol, mRow, mTile);
- mMap->SetTileInfo(mCol, mRow, mTileInfo);
- if (mTileInfo == BLOCK_APPLE)
- {
- questioned = false;
- mApp->SetApple(mApp->GetApple()+1);
- }
-
- if(mTileInfo == BLOCK_QUES)
- {
- mMap->SetTile(mCol, mRow,TILE_BRICK );
- mMap->SetTileInfo(mCol, mRow, 1);
- SelectBlock(1);
- }
- }
- }
- }
- void JumpingBlock::Render()
- {
- float x, y;
- mMap->GetPosition(&x, &y);
- if(!banana)
- {
- mEngine->RenderQuad(mBlock, mX-x, mY-y);
- }
-
-
-
- banana = false;
-
- }
- void JumpingBlock::SelectBlock(int n)
- {
- float x, y, w, h;
-
- mBlock->GetTextureRect(&x, &y, &w, &h);
- mBlock->SetTextureRect((float)(n*32), y, w, h);
- }
- void JumpingBlock::Animate(int col, int row)
- {
- short tile = mMap->GetTile(col, row);
- u8 info = mMap->GetTileInfo(col, row);
-
- //if (tile != 0)
- {
-
- if (info == BLOCK_QUES || info == BLOCK_WEASEL)
- {
- if (info == BLOCK_QUES)
- {
- SelectBlock(0);
- questioned = true;
- questionNO=mApp->questionNO;
- questionNO++;
- mApp->questionNO=questionNO;
- SelectBlock(1);
- mApp->PlaySfx(SFX_HITWALL);
- }
-
- mTile = tile;
- mTileInfo = info;
-
- mCol = col;
- mRow = row;
- mGoingUp = true;
- mActive = true;
- mX = (float) (col << TILE_SHIFT);
- mY = (float) (row << TILE_SHIFT);
-
- mOldY = mY;
- mMap->SetTile(col, row, TILE_BRICK);
- //SelectBlock(1);
- mMap->SetTileInfo(col, row, BLOCK_SOLID);
- }
- else if (info == BLOCK_BANANA||info == BLOCK_APPLE)
- {
- // questioned = false;
- mCol = col;
- mRow = row;
- mMap->SetTile(col, row, 0);
- mMap->SetTileInfo(col, row, 0);
-
-
- }
- else if (info == BLOCK_SOLID)
- {
-
- }
- }
- }
- #endif