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

📄 mario.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 _MARIO_HPP_
#define _MARIO_HPP_

class JumpingBlock;

class Mario: public MoveableObject
{
private:

//	TileMap* mMap;
//	
//	bool mFlipped;
//	bool mJumping;
	
	JSprite* mRun;
	JSprite* mIdle;
	JSprite* mJump;
	JSprite* mDuck;

	float mTall;
    int mCoinCount;
	int mCurLife;
	

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

	virtual void Update(float dt);
	//virtual void Render(float xOffset, float yOffset);

	virtual void HitBottom();
	virtual void StandingOnNothing(int col, int row);
	
	virtual void HitTop(int colLeft, int colRight, int row);

	virtual void RightGlide();
	virtual void LeftGlide();

	virtual void Blood();
	virtual void BloodP();

	int GetCoinCount();

	int GetCurLife();

	void SetCoinCount(int count);
	void SetCurLife(int life);

	bool md;

	int mFlashTime;

};

void Mario::RightGlide()
{
	
	mX += DEFAULT_WALK_SPEED/30;
	
}
void Mario::LeftGlide()
{
	
	mX -= DEFAULT_WALK_SPEED/30;
	
}

void Mario::SetCoinCount(int count)
{
	mCoinCount = count;
}

void Mario::SetCurLife(int life)
{
	mCurLife = life;
}


int Mario::GetCoinCount()
{
	return mCoinCount;
}

int Mario::GetCurLife()
{
	return mCurLife;
}

void Mario::Blood()
{
	mCurLife -= 10;
}

void Mario::BloodP()
{
	mCurLife += 10;
}

Mario::Mario(GameStatePlay* app): MoveableObject(app)
{
	mFlashTime = 0;
	md = false;
	//mMap = mApp->GetTileMap();
	//这里的mTexture是GameStatePlay里的mTexture也就是Mario的纹理
	mIdle = new JSprite(mTexture, 0, 0, 100, 95);
	mIdle->SetHotSpot(0.0f, 95.0f);
	mJump = new JSprite(mTexture, 300, 0, 100, 95);
	mJump->SetHotSpot(0.0f, 95.0f);
	mDuck = new JSprite(mTexture, 400, 0, 100, 95);
	mDuck->SetHotSpot(0.0f, 95.0f);
    
	//设置与走路相关的动画
	mRun = new JSprite(mTexture, 0, 0, 100, 95);
	mRun->SetHotSpot(0.0f, 95.0f);
	mRun->AddFrame(100,0,100,95);
	mRun->AddFrame(200,0,100,95);
	mRun->StartAnimation();
    
	//设置初始动作为mIdle
	mCurrAnimation = mIdle;
	mCurrAnimation->SetFlip(true);

	mX = 32.0f;
	mY = VIRTUAL_HEIGHT - 64.0f - 1.0f;

	mTall = 64.0f;
//	mFlipped = true;
//	mJumping = false;

//	mXVelocity = 0.0f;
//	mYVelocity = 0.0f;

	mYRenderOffset = 3.0f;

	mHScale = 0.70f;
	mVScale = 0.70f;

	mLeftAdjustment = 23;
	mRightAdjustment = 47;

	mHitLeftAdjustment = 12;
	mHitRightAdjustment = 58;

	mFallLeftAdjustment = -20;
	mFallRightAdjustment = -10;

	mRealHeight = 60;

	mCurLife = 50;
	mCoinCount = 0;
}


Mario::~Mario()
{
	
	delete mRun;
	delete mIdle;
	delete mDuck;
	delete mJump;

}



void Mario::HitTop(int left, int right, int row)
{

	int colLeft = (left>>TILE_SHIFT)<<TILE_SHIFT;
	int colRight = (right>>TILE_SHIFT)<<TILE_SHIFT;
					
	JumpingBlock* block = mApp->GetJumpingBlock();
    
	
	if(this->mMap->GetTileInfo(colLeft>>TILE_SHIFT, row)==BLOCK_COIN)
	{
		this->mCoinCount++;
	}


	if (left < colLeft+24)
		block->Animate(colLeft>>TILE_SHIFT, row);
	else
		block->Animate(colRight>>TILE_SHIFT, row);
}


void Mario::HitBottom()
{
	mCurrAnimation = mIdle;
	MoveableObject::HitBottom();
}




void Mario::StandingOnNothing(int col, int row)
{
	mCurrAnimation = mJump;
	MoveableObject::StandingOnNothing(col, row);
}

void Mario::Update(float dt)
{
	if( mFlashTime>0 )
		{
			if(mFlashTime%4==0 || mFlashTime%4==3 )
				mCurrAnimation->SetAlpha(255.0f);
			else
				mCurrAnimation->SetAlpha(64.0f);
			mFlashTime--;
		}
		else
			mCurrAnimation->SetAlpha(255.0f);


	if (mEngine->GetAnalogX() < 64)           
	{
		mXVelocity = -DEFAULT_WALK_SPEED;
		
		if (!mJumping)
			mCurrAnimation = mRun;

		mCurrAnimation->SetFlip(false);
		mIdle->SetFlip(false);
	}
	else if (mEngine->GetAnalogX() > 192)             
	{
		mXVelocity = DEFAULT_WALK_SPEED;
		
		if (!mJumping)
			mCurrAnimation = mRun;

		mCurrAnimation->SetFlip(true);
		mIdle->SetFlip(true);
	}
	else                                          
	{
		
			mXVelocity = 0.0f;
			if (!mJumping)
				mCurrAnimation = mIdle;
		
	}



	if (!mJumping)
	{
#ifdef WIN32
		if (mEngine->GetAnalogY() < 64 || mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
#else
		if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
#endif
		{                                                //这一段描述了Mario的跳跃情况
			mCurrAnimation = mJump;
			mJumping = true;
			mYVelocity = BIGM_INITIAL_JUMP_VEL;
			mApp->PlaySfx(SFX_JUMP2);
		}
		else if (mEngine->GetAnalogY() > 192)
		{
			mCurrAnimation = mDuck;
			mXVelocity = 0.0f;
		}
	
	
		
	}



	MoveableObject::Update(dt);
		
	if (mY > VIRTUAL_HEIGHT)
	{
		//mApp->Destroy();
		//mApp->Create();
		md = true;
	}
	//mCurrAnimation->Update(dt);

	mMap->SetTarget(mX - 210.0f, mY - 84.0f);

}

//
//void Mario::Render(float xOffset, float yOffset)
//{
//	mCurrAnimation->SetScale(0.70f, 0.70f);
//	mCurrAnimation->SetPosition(mX-xOffset, mY-yOffset + 6.0f);
//	mCurrAnimation->Render(mEngine);
//
//}

#endif

⌨️ 快捷键说明

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