📄 jumpingcoin.hpp
字号:
//-------------------------------------------------------------------------------------
//
// 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 _JUMPING_COIN_HPP_
#define _JUMPING_COIN_HPP_
class JumpingCoin: public GameObject
{
private:
JSprite* mAnimatedCoin;
float mAlpha;
float mAlphaDelta;
JTexture* mTexture_2;
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)
{
mTexture_2 = mEngine->LoadTexture("Res/mario_1.png", true);
mAnimatedCoin = new JSprite(mTexture_2, 128, 64, 32, 32);
//mAnimatedCoin->StartAnimation();
mAnimatedCoin->SetHotSpot(15.0f, 15.0f);
//mAnimatedCoin->SetDuration(80);
mCurrAnimation = mAnimatedCoin;
mAlpha = 255.0f;
mXVelocity = 0.0f;
mYVelocity = 0.0f;
}
JumpingCoin::~JumpingCoin()
{
delete mAnimatedCoin;
}
void JumpingCoin::Update(float dt)
{
mAlpha -= mAlphaDelta * dt;
if (mAlpha < 0.0f)
{
SetActive(false);
return;
}
float gravity = 0.0003f;//DEFAULT_GRAVITY/2.0f;
float distance = mYVelocity*dt + gravity*dt*dt/2;
mYVelocity += gravity*dt;
mY += distance;
mCurrAnimation->Update(dt);
}
void JumpingCoin::Render()
{
float x, y;
mMap->GetPosition(&x, &y);
//mCurrAnimation->SetColor(ARGB((int)mAlpha, 255, 255, 255));
mCurrAnimation->SetScale(0.8f, 0.8f);
mCurrAnimation->SetPosition(mX-x, mY-y + 6.0f);
//mEngine->EnableTextureFilter(false);
mCurrAnimation->Render();
//mEngine->EnableTextureFilter(true);
}
void JumpingCoin::Action(float x, float y)
{
mX = x;
mY = y;
mAlpha = 255.0f;
mAlphaDelta = mAlpha/1000.0f; // fade out in 1 seconds
//mXVelocity = 0.0f;
mYVelocity = -0.16f;
mCurrAnimation->SetAlpha(255.0f);
//mCurrAnimation->EnableAlpha(true, -mAlphaDelta);
mCurrAnimation->StartAnimation();
SetActive(true);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -