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

📄 jumpingblock1.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 _JUMPINGBLOCK_HPP
#define _JUMPINGBLOCK_HPP

//-----------------------------------------------------------------------------------------------------
class JumpingBlock: public GameObject
{
private:
	int mCol;
	int mRow;

	JQuad* mBlock;

	bool mGoingUp;
	float mOldY;

	TileMap* mMap;

	u8 mTileInfo;
	short mTile;
	
public:
	JumpingBlock(GameStatePlay* app);
	virtual ~JumpingBlock();

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

	void SelectBlock(int n);

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


JumpingBlock::JumpingBlock(GameStatePlay* app): GameObject(app)
{
	mMap = mApp->GetTileMap();
	mBlock = new JQuad(mTexture, 0.0f, 96.0f, 32.0f, 32.0f);
}


JumpingBlock::~JumpingBlock()
{

}


void JumpingBlock::Update(float dt)
{
	if (mGoingUp)
	{
		mY -= BLOCK_SPEED*dt;
		if (mY < mOldY-16.0f)
		{
			mGoingUp = false;

			if (mTileInfo == BLOCK_COIN)
			{
				JumpingCoin* coin = mApp->GetJumpingCoin();
				coin->Action(mX+16.0f, mY-16.0f);
				mApp->PlaySfx(SFX_COIN);
				mApp->PlaySfx(SFX_WANG);
			}
			
		}
	}
	else
	{
		mY += BLOCK_SPEED*dt;
		if (mY > mOldY)
		{
			mY = mOldY;
			mActive = false;

			mMap->SetTile(mCol, mRow, mTile);
			mMap->SetTileInfo(mCol, mRow, mTileInfo);

			if (mTileInfo == BLOCK_MUSHROOM)
			{
				mApp->SpawnMushroom(mCol, mRow);
				mApp->PlaySfx(SFX_MUSHROOM);
			}
		}
	}
}


void JumpingBlock::Render()
{
	float x, y;
	mMap->GetPosition(&x, &y);
	mEngine->RenderQuad(mBlock, mX-x, mY-y);
}


void JumpingBlock::SelectBlock(int n)
{
	float x, y, w, h;

	mBlock->GetTextureRect(&x, &y, &w, &h);
	mBlock->SetTextureRect((float)(n*32), y, w, h);

}


void JumpingBlock::Animate(int col, int row)
{

	short tile = mMap->GetTile(col, row);
	u8 info = mMap->GetTileInfo(col, row);

	//if (tile != 0)
	{
		
		if (info >= BLOCK_BRICK && info <= BLOCK_STAR)
		{
			if (info == BLOCK_BRICK)
				SelectBlock(0);
			else
				SelectBlock(1);
			
			mTile = tile;
			mTileInfo = info;
			
			mCol = col;
			mRow = row;
			mGoingUp = true;
			mActive = true;
			mX = (float) (col << TILE_SHIFT);
			mY = (float) (row << TILE_SHIFT);
			
			mOldY = mY;

			mMap->SetTile(col, row, 0);
			mMap->SetTileInfo(col, row, BLOCK_SOLID);
		}
		else if (info == BLOCK_SOLID)
		{
			//mApp->PlaySfx(SFX_HITWALL);
		}
	}
}

#endif

⌨️ 快捷键说明

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