📄 jumpingblock.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;
JTexture* mTileTex;
bool mGoingUp;
float mOldY;
TileMap* mMap;
u8 mTileInfo;
u8 mTileInfo_1;
short mTile;
public:
JumpingBlock(GameStatePlay* app);
virtual ~JumpingBlock();
virtual void Update(float dt);
virtual void Render();
virtual void Gangplank();
void SelectBlock(int n);
void Animate(int col, int row);
};
JumpingBlock::JumpingBlock(GameStatePlay* app): GameObject(app)
{
mMap = mApp->GetTileMap();
mTileTex = mEngine->LoadTexture("Res/tiles_5.png", true);
mBlock = new JQuad(mTileTex, 128.0f, 0.0f, 32.0f, 32.0f);
}
JumpingBlock::~JumpingBlock()
{
}
void JumpingBlock::Gangplank()
{
if (mTileInfo_1 == BLOCK_SPRING )
{
mMap->SetTileInfo(mCol, mRow, 0);
mMap->SetTile(mCol, mRow, 0);
}
}
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);
mTileInfo = 1;
}
if (mTileInfo == 2 )
{
mApp->PlaySfx(SFX_BREAKER);
mMap->SetTileInfo(mCol, mRow, 0);
mMap->SetTile(mCol, mRow, 0);
}
}
}
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);
mMap->SetTileInfo(mCol, mRow, 1);
mMap->SetTile(mCol, mRow, 4);
}
if(mTileInfo == 1)
{
mMap->SetTileInfo(mCol, mRow, 1);
mMap->SetTile(mCol, mRow, 4);
}
}
}
}
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);
u8 info_1 = mMap->GetTileInfo(col, row + 1);
//if (tile != 0)
{
if (info >= BLOCK_BRICK && info <= BLOCK_STAR || info_1 == BLOCK_SPRING)
{
if (info == BLOCK_BRICK)
SelectBlock(6);
else
SelectBlock(7);
mTile = tile;
mTileInfo = info;
mTileInfo_1 = info_1;
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 + -