⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staticcoin.hpp

📁 超级玛丽
💻 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 _STATIC_COIN_HPP_
#define _STATIC_COIN_HPP_


class StaticCoin: public GameObject
{
private:
	JSprite* mAnimatedCoin;
	JSprite* mEated;
	bool isEat;
	JTexture* mTexture_2;
	Mario *mMario;

public:
	StaticCoin(GameStatePlay* app);
	virtual ~StaticCoin();

	virtual void Update(float dt);
	virtual void Render();
	virtual void SetEat();

	void Spawn(int col, int row);

	bool sc;

};


StaticCoin::StaticCoin(GameStatePlay* app): GameObject(app)
{
	mTexture_2 = mEngine->LoadTexture("Res/mario_1.png", true);
	
	mAnimatedCoin = new JSprite(mTexture_2, 128, 64, 32, 32);
	mAnimatedCoin->AddFrame(128,96,32,32);
	mAnimatedCoin->AddFrame(128,96,32,32);
	mAnimatedCoin->AddFrame(128,64,32,32);

	//mAnimatedCoin->StartAnimation();
	mAnimatedCoin->SetHotSpot(15.0f, 15.0f);
	//mAnimatedCoin->SetDuration(80);

	mEated = new JSprite(mTexture_2,128,64,32,32);
	/*
	mEated->AddFrame(129,97,30,30);
	mEated->AddFrame(129,97,30,30,true);
	mEated->AddFrame(97,97,30,30,true);
	//mEated->StartAnimation();*/
	mEated->SetHotSpot(15.0f, 15.0f);
	//mEated->SetDuration(80);

	mCurrAnimation = mAnimatedCoin;

	isEat = true;

	mXVelocity = 0.0f;
	mYVelocity = 0.0f;

	sc = true;

}


StaticCoin::~StaticCoin()
{
	
	delete mAnimatedCoin;
	delete mEated;
}


void StaticCoin::Update(float dt)
{

	mCurrAnimation->Update(dt);
}


void StaticCoin::SetEat()
{
	if(isEat){
		JumpingCoin* coin = mApp->GetJumpingCoin();
		coin->Action(mX+16.0f, mY-16.0f);
		mApp->PlaySfx(SFX_COIN);
		mCurrAnimation = mEated;
		SetActive(false);
		isEat = false;
		sc = false;
	}
}

void StaticCoin::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 StaticCoin::Spawn(int col, int row)
{
	mX = (float)(col<<TILE_SHIFT)+16.0f;
	mY = (float)(row<<TILE_SHIFT)+8.0f;

	mCurrAnimation->StartAnimation();
	
	SetActive(true);
	
}


#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -