JumpingBlock1.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:3k
- //-------------------------------------------------------------------------------------
- //
- // This is part of MarioDemo, a platformer demo for JGE++
- //
- // Copyright (C) 2006 James Hui (a.k.a. Dr.Watson)
- //
- // This program is free software; you can redistribute it and/or modify it
- // under the terms of the GNU General Public License as published by the Free
- // Software Foundation; either version 2 of the License, or (at your option) any
- // later version.
- //
- // This program is distributed in the hope that it will be useful, but WITHOUT
- // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License along with
- // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- // Place, Suite 330, Boston, MA 02111-1307 USA
- //
- // Bugs and comments can be forwarded to jhkhui@yahoo.com.
- //
- //-------------------------------------------------------------------------------------
- #ifndef _JUMPINGBLOCK_HPP
- #define _JUMPINGBLOCK_HPP
- //-----------------------------------------------------------------------------------------------------
- class JumpingBlock: public GameObject
- {
- private:
- int mCol;
- int mRow;
- JQuad* mBlock;
- bool mGoingUp;
- float mOldY;
- TileMap* mMap;
- u8 mTileInfo;
- short mTile;
-
- public:
- 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);
- }
- JumpingBlock::~JumpingBlock()
- {
- }
- void JumpingBlock::Update(float dt)
- {
- if (mGoingUp)
- {
- mY -= BLOCK_SPEED*dt;
- if (mY < mOldY-16.0f)
- {
- mGoingUp = false;
- if (mTileInfo == BLOCK_COIN)
- {
- JumpingCoin* coin = mApp->GetJumpingCoin();
- coin->Action(mX+16.0f, mY-16.0f);
- mApp->PlaySfx(SFX_COIN);
- mApp->PlaySfx(SFX_WANG);
- }
-
- }
- }
- 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_MUSHROOM)
- {
- mApp->SpawnMushroom(mCol, mRow);
- mApp->PlaySfx(SFX_MUSHROOM);
- }
- }
- }
- }
- void JumpingBlock::Render()
- {
- float x, y;
- mMap->GetPosition(&x, &y);
- mEngine->RenderQuad(mBlock, mX-x, mY-y);
- }
- 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_BRICK && info <= BLOCK_STAR)
- {
- if (info == BLOCK_BRICK)
- SelectBlock(0);
- else
- SelectBlock(1);
-
- 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, 0);
- mMap->SetTileInfo(col, row, BLOCK_SOLID);
- }
- else if (info == BLOCK_SOLID)
- {
- //mApp->PlaySfx(SFX_HITWALL);
- }
- }
- }
- #endif