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

📄 gamestateplay.hpp

📁 超级玛丽
💻 HPP
📖 第 1 页 / 共 3 页
字号:
//-------------------------------------------------------------------------------------
//
// 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. 
// 
//-------------------------------------------------------------------------------------

#include <stdio.h>

#include "GameState.h"

#define SAFE_DELETE(x)		if (x) delete x

float VIRTUAL_WIDTH	= 5120.0f;
float VIRTUAL_HEIGHT = 480.0f;

float BIGM_INITIAL_JUMP_VEL	=-0.57f;
float DEFAULT_GRAVITY = 0.001f;
float DEFAULT_WALK_SPEED =	0.15f;


#define MAX_TILES		10

#define TILE_HILL1		0
#define TILE_HILL2		1
#define TILE_HILL3		2
#define TILE_TUBE		3
#define TILE_BRICK		4
#define TILE_BLOCK1		5
#define TILE_BLOCK2		6
#define TILE_CASTLE		7

#define BLOCK_SOLID		1
#define BLOCK_BRICK		2
#define BLOCK_COIN		3
#define BLOCK_MUSHROOM	4
#define BLOCK_STAR		5
#define BLOCK_TUNNEL	6
#define BLOCK_TURTLE	7
#define BLOCK_FLOWER	8
#define BLOCK_COIN2		9
#define BLOCK_BADMUSH	10
#define BLOCK_TUNNEL_01	11
#define BLOCK_TUNNEL_02	12
#define BLOCK_TUNNEL_03	13
#define BLOCK_TUNNEL_04	14
#define BLOCK_SPRING    16
#define BLOCK_DISAPPEAR 17
#define BLOCK_RIGHT     18
#define BLOCK_LEFT      19


#define MAX_SFX			12

#define SFX_JUMP1		0
#define SFX_JUMP2		1
#define SFX_COIN		2
#define SFX_GROWING		3
#define SFX_SHRINK		4
#define SFX_HITWALL		5
#define SFX_BREAKER		6
#define SFX_MUSHROOM	7
#define SFX_CRUSHED		8
#define SFX_PAUSE		9
#define SFX_FIRE		10
#define SFX_SHOUT       11

#define MAX_STATIC_COIN	100
#define MAX_BAD_FLOWER	10
#define MAX_TUNNEL      200
#define MAX_TURTLE      100
#define MAX_MUSH        100
#define MAX_GANGPLANK   100
#define MAX_BADFISH     5

//long life;
//long coincount;
//long mark;

class TileMap;
class Scroller;
class GameObject;
class MoveableObject;

class JumpingBlock;
class JumpingCoin;
class Mario;
class Turtle;
class Mushroom;
class StaticCoin;
class BadFlower;
class BadMush;
class Tunnel;
class Gangplank;
class BadFish;

class GameApp;
class IMenu;
//class MarioSql;

class GameStatePlay:	public GameState
{

private:
	bool blood;
//	float mAngle;
//	float mScale;
//	float mDelta;

	//float mCloudX;

	Scroller* scrollerMount;
	Scroller* scrollerCloud;


	JMusic* mMusic;
	JSample* mSfx[MAX_SFX];

	TileMap* mTileMap;

	bool haveMushroom;

	JTexture* mTexture;
	JTexture* mTexture_2;
//	JQuad* mMario;
//	JQuad* mHello;

	JTexture* mBgTex;
	JQuad* mCloud;
	JQuad* mMountains;
	JQuad* mTiles[MAX_TILES];

	JTexture* mTileTex;

	JTexture* mRainbowTex;
	JQuad* mRainbow;

	JTexture* mStabTex;
	JQuad* mStab;

	JumpingBlock* mBlock;

	JumpingCoin* mCoin;

	Mario *mMario;
	BadFish *mBadFish[MAX_BADFISH];

	MoveableObject* mObject;

	Turtle* mTurtle[MAX_TURTLE];
	BadMush* mBadMush[MAX_MUSH];
	//MarioSql* mSql;

	int mTurtleCount;
	int mBadMushCount;

	StaticCoin* mStaticCoins[MAX_STATIC_COIN];
	int mStaticCoinsCount;

	Tunnel* mTunnel[MAX_TUNNEL];
	int mTunnelCount;

	Tunnel* mTunnel_1[MAX_TUNNEL];
	int mTunnel_1Count;

	Tunnel* mTunnel_2[MAX_TUNNEL];
	int mTunnel_2Count;

	Tunnel* mTunnel_3[MAX_TUNNEL];
	int mTunnel_3Count;

	Tunnel* mTunnel_4[MAX_TUNNEL];
	int mTunnel_4Count;

	Gangplank* mGangplank[MAX_GANGPLANK];
	int mGangplankCount;

	Gangplank* mGangplank_1[MAX_GANGPLANK];
	int mGangplankCount_1;

	Gangplank* mGangplank_2[MAX_GANGPLANK];
	int mGangplankCount_2;

	BadFlower* mBadFlowers[MAX_BAD_FLOWER];
	int mBadFlowersCount;

	Mushroom* mMushroom;

	IMenu* mMenu;
	
	bool bmap_3;

	int r[MAX_GANGPLANK];
	int l[MAX_GANGPLANK];
	int sumr;
	int suml;
	bool inRangeR;
	bool inRangeL;

	bool mmm;
	float time;
	int coin;
	int life;

	int maxLifeCount;
public:
	GameStatePlay(GameApp* app);
	virtual ~GameStatePlay();
	virtual void Create();
	virtual void Destroy();
	virtual void Update();
	virtual void Render();
	virtual void Start();
	virtual void End();

	JTexture* GetTexture(int id);
	TileMap* GetTileMap() { return mTileMap; }
	
	JumpingBlock* GetJumpingBlock() { return mBlock; }
	JumpingCoin* GetJumpingCoin() { return mCoin; }
	Turtle* GetTurtle(int i){ return mTurtle[i];}

	bool GetHaveMushroom();
	Mushroom* getMushroom() { return mMushroom; };

	void SpawnTurtle(int col, int row);
	void SpawnMushroom(int col, int row);
	void SpawnStaticCoin(int col, int row);
	void SpawnBadFlower(int col, int row);
	void SpawnBadMush(int col, int row);
	void SpawnTunnel(int col, int row);
	void SpawnTunnel_1(int col, int row);
	void SpawnTunnel_2(int col, int row);
	void SpawnTunnel_3(int col, int row);
	void SpawnTunnel_4(int col, int row);
	void SpawnGangplank(int col, int row);
	void SpawnGangplank_1(int col, int row);
	void SpawnGangplank_2(int col, int row);

	void PlaySfx(int idx);

};




#include "TileMap.hpp"
#include "Scroller.hpp"
#include "GameObject.hpp"
#include "JumpingCoin.hpp"
#include "StaticCoin.hpp"
#include "JumpingBlock.hpp"
#include "Mario.hpp"
#include "Turtle.hpp"
#include "Mushroom.hpp"
#include "BadFlower.hpp"
#include "BadMush.hpp"
#include "Tunnel.hpp"
#include "Gangplank.hpp"
#include "IMenu.hpp"
#include "BadFish.hpp"
//#include "MarioSql.hpp"

GameStatePlay::GameStatePlay(GameApp* app): GameState(app)
{
	maxLifeCount  = 50;
	time = 0;
	blood = false;
	bmap_3 = false;
	for(int i=0; i<  MAX_GANGPLANK  ;i++)
	{
		r[i] = 1;
		l[i] = 1;
	}
	sumr=1;
	suml=1;
	inRangeR=inRangeL=false;

	mmm=false;

	mTexture = NULL;
	mTexture_2 = NULL;

	mMario = NULL;
	//mTurtle = NULL;
	haveMushroom = false;

	for (int i=0;i<MAX_BADFISH;i++)
		mBadFish[i]=NULL;

	mBgTex = NULL;
	mMountains = NULL;
	mCloud = NULL;

	mMusic = NULL;

	
	for (int i=0;i<MAX_TILES;i++)
		mTiles[i] = NULL;

	mBlock = NULL;
	

	mMushroom = NULL;
	scrollerCloud = NULL;
	scrollerMount = NULL;
	mTileTex = NULL;
	mTileMap = NULL;
	mRainbowTex = NULL;
	mRainbow = NULL;
	mStabTex = NULL;
	mStab = NULL;
	mBlock = NULL;
	mCoin = NULL;
	mMenu = new IMenu();
	//mSql = new MarioSql();
	//mSql->LoadLastTime("1",mark,life,coincount);

	//mMario->SetCoinCount(coincount);
	//mMario->SetCurLife(life);
	int i;
	
	for (i=0;i<MAX_TURTLE;i++)
		mTurtle[i] = NULL;

	for (i=0;i<MAX_MUSH;i++)
		mBadMush[i] = NULL;

	for (i=0;i<MAX_STATIC_COIN;i++)
		mStaticCoins[i] = NULL;


	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel[i] = NULL;

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_1[i] = NULL;

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_2[i] = NULL;

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_3[i] = NULL;

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_4[i] = NULL;

	for (i=0;i<MAX_GANGPLANK;i++)
		mGangplank[i] = NULL;

	for (i=0;i<MAX_GANGPLANK;i++)
		mGangplank_1[i] = NULL;

	for (i=0;i<MAX_GANGPLANK;i++)
		mGangplank_2[i] = NULL;

	for (i=0;i<MAX_BAD_FLOWER;i++)
		mBadFlowers[i] = NULL;

	mMushroom = NULL;

	for (i=0;i<MAX_SFX;i++)
		mSfx[i] =NULL;

}


GameStatePlay::~GameStatePlay()
{
}


void GameStatePlay::Create()
{
	int i;

	mBgTex = mEngine->LoadTexture("Res/bg1.png", true);

	mMountains = new JQuad(mBgTex, 0.0f, 0.0f, 512.0f, 142.0f);
	mCloud = new JQuad(mBgTex, 0.0f, 352.0f, 512.0f, 159.0f);
	//mCloud->SetColor(ARGB(196,255,255,255));

	mTiles[TILE_HILL1] = new JQuad(mBgTex, 0.0f, 143.0f, 200.0f, 133.0f);
	mTiles[TILE_HILL2] = new JQuad(mBgTex, 202.0f, 143.0f, 200.0f, 85.0f);
	mTiles[TILE_HILL3] = new JQuad(mBgTex, 410.0f, 143.0f, 98.0f, 161.0f);
	mTiles[TILE_BRICK] = new JQuad(mBgTex, 48.0f, 278.0f, 64.0f, 64.0f);
	mTiles[TILE_BLOCK1] = new JQuad(mBgTex, 118.0f, 278.0f, 32.0f, 32.0f);
	mTiles[TILE_BLOCK2] = new JQuad(mBgTex, 160.0f, 278.0f, 32.0f, 32.0f);
	mTiles[TILE_CASTLE] = new JQuad(mBgTex, 202.0f, 232.0f, 160.0f, 116.0f);
	mTiles[TILE_TUBE] = new JQuad(mBgTex, 366.0f, 232.0f, 43.0f, 84.0f);

	mTileTex = mEngine->LoadTexture("Res/tiles_5.png", true);	
	mTileMap = new TileMap(this, mTileTex);

	mTexture = mEngine->LoadTexture("Res/mario-old.png", true);	// load texture and put onto VRAM if possible
	
	mTexture_2 = mEngine->LoadTexture("Res/mario_1.png", true);	

	mRainbowTex = mEngine->LoadTexture("Res/bg4.png", true);	
	mRainbow = new JQuad(mRainbowTex, 0.0f, 0.0f, 768.0f, 480.0f);

	mStabTex = mEngine->LoadTexture("Res/1.5.bmp", true);	
	mStab = new JQuad(mStabTex, 0.0f, 0.0f, 32.0f, 20.0f);
	//mRainbow->SetColor(ARGB(196,255,255,255));

	mMenu->Create(mEngine);

	mMario = new Mario(this);

	
//	mMario = new JQuad(mTexture, 0.0f, 0.0f, 62.0f, 72.0f);		// create quad for rendering
//	mMario->SetHotSpot(31.0f, 36.0f);							// change center of quad
//
//	mHello = new JQuad(mTexture, 0.0f, 100.0f, 128.0f, 28.0f);
//	mHello->SetHotSpot(64.0f, 14.0f);

	
	scrollerCloud = new Scroller(mCloud);
	scrollerMount = new Scroller(mMountains);
	
	mMusic = mEngine->LoadMusic("Res/smarioa.mod");
	

	char *sfx[] = 
	{
		"Res/Sfx/jump1.wav",
		"Res/Sfx/jump2.wav",
		"Res/Sfx/coin.wav",
		"Res/Sfx/growing.wav",
		"Res/Sfx/shrink.wav",
		"Res/Sfx/hitwall.wav",
		"Res/Sfx/breaker.wav",
		"Res/Sfx/mushroom.wav",
		"Res/Sfx/crushed.wav",
		"Res/Sfx/pause.wav",
		"Res/Sfx/fire.wav",
		"Res/Sfx/sound5.wav"
	};
	
	for (i=0;i<MAX_SFX;i++)
		mSfx[i] = mEngine->LoadSample(sfx[i]);



//	mScale = 1.0f;
//	mAngle = 0.0f;
//	mDelta = 0.001f;


	//mCloudX = 0.0f;

	mTileMap->Load("Res/map.dat", "Res/mario.ent");

	mBlock = new JumpingBlock(this);
	
	mCoin = new JumpingCoin(this);

	for (i=0;i<MAX_TURTLE;i++)
		mTurtle[i] = new Turtle(this);

	for (i=0;i<MAX_MUSH;i++)
		mBadMush[i] = new BadMush(this);

	mMushroom = new Mushroom(this);

	for (int i=0;i<MAX_BADFISH;i++)
		mBadFish[i] = new BadFish(this);

	for (i=0;i<MAX_STATIC_COIN;i++)
		mStaticCoins[i] = new StaticCoin(this);

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel[i] = new Tunnel(this);

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_1[i] = new Tunnel(this);

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_2[i] = new Tunnel(this);

	for (i=0;i<MAX_TUNNEL;i++)
		mTunnel_3[i] = new Tunnel(this);

	for (i=0;i<MAX_TUNNEL;i++)

⌨️ 快捷键说明

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