?? world.h
字號(hào):
/**
* File : World.h
* Author : Kevin Lynx
* Date : 2007/7/29
*/
#ifndef _WORLD_H_
#define _WORLD_H_
#include "Singleton.h"
#include <map>
using std::map;
/**
* World class
*
* Implements the world in PacShooter, mainly building the map
*/
class World : public Singleton<World>
{
public:
/**
* Stone type
*
*/
enum E_StoneType
{
STONE_NONE = -1,
/// these stones below cannot be destroyed
STONE_DESTROY_MIN,
STONE1_1 = 1,
STONE2_1,
STONE_DESTROY_MAX,
/// these stones below can be destroyed
STONE1_2,
STONE1_3,
STONE2_2,
STONE2_3,
STONE2_4,
STONE_COUNT
};
/**
* Monster type
*
*/
enum E_MonsterType
{
MONSTER_NONE = -1,
MONSTER_2,
MONSTER_3,
MONSTER_4
};
/**
* Bonus type
*
*/
enum E_BonusType
{
BONUS_NONE = -1,
B_BEAN, /// 豆子
B_4_SIDES, /// 朝四個(gè)方向發(fā)射子彈的獎(jiǎng)勵(lì)
B_ARMOUR, /// 保護(hù)主角不受傷害的盾牌獎(jiǎng)勵(lì)
B_MONEY, /// 增加分?jǐn)?shù)
B_TIME, /// 延長(zhǎng)游戲時(shí)間
B_GLUE, /// 使所有怪物移動(dòng)速度下降
B_SUPER_FIRE, /// 可以連續(xù)發(fā)射子彈,不用等到子彈消失
B_LIFE, /// 增加生命值
B_COUNT
};
/**
* resources set type
*
* key : the model's type
* value: the resources, i mean the model
*/
typedef map<int, IAnimatedMesh*> tModelSet;
/**
* monster texture set
*
* key : the monster's type
* value : the texture
*/
typedef map<int, ITexture*> tMonsterTexture;
public:
/**
* Constructor
*
*/
World( IrrlichtDevice *device );
/**
* Destructor
*
*/
~World();
/**
* load a level
*
*/
bool load( bool nextLevel = false);
/**
* createGround
*
*/
void createGround();
/**
* release
*
*/
void release();
/**
* collision
*
* You should know, in this game the collision between sprite(model) and
* world only depends on xz plane ( donot care y value in 3d world ).
* So just provide the rect around the model on xz plane, and the direction
* of the model that means the model is moving toward dir now.
*
* and this function will return the collision check result .
* 0 means it can move , otherwise, it got something like stone( cannot move),
* bonuses , especially for our hero.
*/
int collision( const rect<float> &box2d, const vector3df &dir );
/**
* adjustPos
*
* mainly adjust the player's position
*/
void adjustPos( const rect<float> &box2d, const vector3df &dir, vector3df &outPos );
/**
* an assist function.
*
*/
int collision( const vector3df &pos );
void worldToMap( float x, float z, int &ax, int &az );
void mapToWorld( int ax, int az, float &x,float &z );
void mapToWorldCenter( int ax, int az, float &cx, float &cz );
/**
* check whether got a bean
* It's impossible that our hero can eat two beans at the same time!
*
*/
bool isGotBean( const aabbox3df &box );
/**
* getMonsterRes
*
* return a monster's mesh texture
*/
bool getMonsterRes( int type, IAnimatedMesh *&mesh, ITexture *&texture );
/**
* getBonusRes
*
*/
bool getBonusRes( int type, IAnimatedMesh *&mesh );
/**
* getMapValue
*
*
*/
int getMapValue( int ax,int az );
/**
* check whether the grid you can get
*
*/
bool canReach( int ax, int az );
/**
* check whether a sprite is at the center position
*
* you know, a sprite is always at some array position (a grid) ,
* so this function check whether the sprite is at the center of the grid
*/
bool isCenterPos( const vector3df &worldPos );
/**
* getValidPos
*
* return a valid position in world space, there can put a monster
*/
void getValidPos( float &x, float &z );
void setLevelIndex( int index );
/**
* isLevelClear
*
* when all the beans were eaten, the level is clear,so return true
*/
bool isLevelClear();
/**
* isOutOfWorld
*
* return whether the given rect on xz plane is out of world
*/
bool isOutOfWorld( const rect<f32> &rect );
int getBeanCount() { return mBeanCount; }
private:
/**
* load resources which used to build the world
*
* @param file the level resources config file
*/
bool loadModels( const std::string &file );
/**
* load map
*
* this function will read map array data and put stones on the ground
* @param mapFile the map array config file, the file name is
* specified in the level resources config file
*/
bool loadMap( const std::string &mapFile );
/**
* create map item
*
*/
void createMapItem( int value, int x, int z );
/**
* caculate a scene node id
*
*/
int getNodeId( int ax, int az );
/**
* getNextLevelIndex
*
*/
int getNextLevelIndex( int curIndex );
private:
IrrlichtDevice *mDevice;
tModelSet mStoneSet;
tModelSet mMonsterSet;
tModelSet mBonusSet;
tMonsterTexture mMonsterTextSet;
ITexture *mBkTexture;
ISceneNode *mGroundNode;
int *mMapData;
int mBeanCount;
int mCurLevelIndex;
public:
dimension2d<int> mMapSize;
dimension2d<float> mStartPos;
dimension2d<int> mStoneSize;
position2d<float> mPlayerWorldPos;
};
/*
MapData : 1---STONE_COUNT : cannot move
STONE_COUNT - STONE_COUNT + B_COUNT : get bonus
*/
#endif // end _WORLD_H_
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -