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

📄 mushroom.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 _MUSHROOM_HPP_
#define _MUSHROOM_HPP_

#define MUSHROOM_INIT		0
#define MUSHROOM_RUN		1

class Mushroom: public MoveableObject
{
private:

	JTexture* mTexture_2;
	JSprite* mRun;
	JSprite* mDestroy;
	int mState;
	bool isDead;

	float mTargetY;
	
public:
	Mushroom(GameStatePlay* app);
	virtual ~Mushroom();


	virtual void Dead();

	virtual void HitLeft();
	virtual void HitRight();
	virtual void Update(float dt);

	void Spawn(int col, int row);
};


Mushroom::Mushroom(GameStatePlay* app): MoveableObject(app)
{
	mTexture_2 = mEngine->LoadTexture("Res/mario_1.png", true);	

	isDead = true;
	mRun = new JSprite(mTexture_2, 96, 32, 32, 32);
	mRun->SetHotSpot(0.0f, 32.0f);
	//mRun->AddFrame(288,96,64,64);
	mRun->SetDuration(200.0f);
	//mRun->StartAnimation();

	mDestroy = new JSprite(mTexture_2 , 224 , 96 ,32, 32);
	mDestroy->SetHotSpot(0.0f,32.0f);
	mDestroy->SetDuration(200.0f);

	mCurrAnimation = mRun;


	mYRenderOffset = 1.0f;

	mXVelocity = -DEFAULT_WALK_SPEED/2;
	mFlipped = false;

	mHScale = 1.00f;
	mVScale = 1.00f;

	mLeftAdjustment = 0;
	mRightAdjustment = 30;

	mHitLeftAdjustment = 0;
	mHitRightAdjustment = 30;

	mFallLeftAdjustment = 0;
	mFallRightAdjustment = 0;

	mRealHeight = 32;
}


Mushroom::~Mushroom()
{
	
	delete mRun;
	delete mDestroy;
}

void Mushroom::Dead()
{
	SetActive(false);
	if(isDead){
	mApp->PlaySfx(SFX_GROWING);
	isDead = false;
	}
	mCurrAnimation = mDestroy;
}

void Mushroom::Spawn(int col, int row)
{
	mCurrAnimation = mRun;
	isDead = true;
	mX = (float)(col<<TILE_SHIFT) + 1.0f;
	mY = (float)((row+1)<<TILE_SHIFT) - 1.0f;

	mTargetY = mY - 32.0f;

	mState = MUSHROOM_INIT;
	//mState = MUSHROOM_RUN;
	SetActive(true);
}


void Mushroom::HitLeft()
{

	mXVelocity = DEFAULT_WALK_SPEED/2;
	mFlipped = false;
}


void Mushroom::HitRight()
{

	mXVelocity = -DEFAULT_WALK_SPEED/2;
	mFlipped = false;
}



void Mushroom::Update(float dt)
{

	if (mState == MUSHROOM_INIT)
	{
		if (mY > mTargetY)
		{
			mY -= (BLOCK_SPEED/4)*dt;
			if (mY <= mTargetY)
			{
				mY = mTargetY;
				mState = MUSHROOM_RUN;
			}
		}
	}
	else
	{
		MoveableObject::Update(dt);
		if (mY > VIRTUAL_HEIGHT)
		{
			SetActive(false);
		}
		mRun->SetFlip(false);
	}
}

#endif

⌨️ 快捷键说明

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