JumpingCoin.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:2k
- #ifndef _JUMPING_COIN_HPP_
- #define _JUMPING_COIN_HPP_
- class JumpingCoin: public GameObject
- {
- private:
- JSprite* mAnimatedCoin;
- float mAlpha;
- float mAlphaDelta;
- int mCol;
- int mRow;
- bool mGoingUp;
- TileMap* mMap;
- JQuad* mBanana;
- u8 mTileInfo;
- short mTile;
- public:
- JumpingCoin(GameStatePlay* app);
- virtual ~JumpingCoin();
- virtual void Update(float dt);
- virtual void Render();
- void Action(float x, float y);
- };
- JumpingCoin::JumpingCoin(GameStatePlay* app): GameObject(app)
- {
-
- mAnimatedCoin = new JSprite(mTexture, 97, 97, 30, 30);
- mAnimatedCoin->AddFrame(129,97,30,30);
- //mAnimatedCoin->AddFrame(129,97,30,30,true);
- mAnimatedCoin->AddFrame(97,97,30,30,true);
- mAnimatedCoin->SetHotSpot(15.0f, 15.0f);
- mMap = mApp->GetTileMap();
- mBanana = new JQuad(mTexture, 0.0f, 96.0f, 32.0f, 32.0f);
- mCurrAnimation = mAnimatedCoin;
- mAlpha = 255.0f;
-
- mXVelocity = 0.0f;
- mYVelocity = 0.0f;
- }
- JumpingCoin::~JumpingCoin()
- {
-
- delete mAnimatedCoin;
- }
- void JumpingCoin::Update(float dt)
- {
- if (mGoingUp)
- {
- if (mTileInfo == BLOCK_APPLE)
- {
- mMap->SetTileInfo(mCol, mRow, 0);
- }
- }
- }
- void JumpingCoin::Render()
- {
- float x, y;
- mMap->GetPosition(&x, &y);
-
- mCurrAnimation->SetScale(0.8f, 0.8f);
- mCurrAnimation->SetPosition(mX-x, mY-y + 6.0f);
- mCurrAnimation->Render();
- }
- void JumpingCoin::Action(float x, float y)
- {
- mX = x;
- mY = y;
- mAlpha =0.0f;
- mAlphaDelta = mAlpha/1000.0f;
-
- mYVelocity = -0.16f;
- mCurrAnimation->SetAlpha(255.0f);
- mCurrAnimation->StartAnimation();
- SetActive(true);
-
- }
- #endif