📄 sprite.h
字号:
/**
* File : Sprite.h
* Author : Kevin Lynx
* Date : 2007/7/30
*/
#ifndef _SPRITE_H_
#define _SPRITE_H_
const float DEFAULT_MONSTER1_SPEED = 160;
const float DEFAULT_MONSTER2_SPEED = 220;
const float DEFAULT_MONSTER3_SPEED = 230;
const float DEFAULT_PLAYER_SPEED = 200;
const float DEFAULT_BULLET_SPEED = 500;
class AnimManager;
/**
* SpriteStatus
*
* describes the status for a sprite
*/
struct SpriteStatus
{
/// status type
enum Status
{
NORMAL,
DEAD,
BORN_SHOW,
BORN_HIDE
};
/// const value
enum
{
PLAYER_DEAD_TIME = 3000,
MONSTER_DEAD_TIME = 9000,
SPRITE_SHOW_TIME = 100,
SPRITE_HIDE_TIME = 50,
SPRITE_BORN_TIME = 3000
};
/// this status begin time
u32 mBeginTime;
/// this status keep time
u32 mKeepTime;
/// current status
int mStatus;
/// specially used for BORN
u32 mBornBeginTime;
u32 mBornKeepTime;
/// functions for more convenience
SpriteStatus();
/// it will change its status automatically by the current status
void changeStatus( int curStatus, int spriteType );
bool update( int spriteType );
};
/**
* Sprite base class
*
*/
class Sprite
{
public:
/**
* Sprit Type
*
*/
enum E_SpriteType
{
ST_MONSTER_2,
ST_MONSTER_3,
ST_MONSTER_4,
ST_BULLET,
ST_PLAYER,
ST_BONUS
};
/**
* Animatation state
*
*/
enum E_AnimState
{
AS_NORMAL,
AS_RUN,
AS_IDLE,
AS_FIRE
};
/**
* fire delay time in millseconds
*
* Especially for player and monsters
*/
enum E_FireDelay
{
FD_PLAYER = 200,
FD_MONSTER2 = 8000,
FD_MONSTER3 = 10000,
FD_MONSTER4 = 20000
};
public:
/**
* Constructor
*
*/
Sprite( int type, float speed, vector3df dir = vector3df( 0, 0, -1 ) );
/**
* Destructor
*
*/
virtual ~Sprite();
/**
* init
*
* mainly init the scene node
*/
virtual bool init( ISceneManager *smgr, IAnimatedMesh *mesh, ITexture *texture );
/**
* update
*
* it moves without collision check
*/
virtual void update( float dt );
/**
* render
*
*/
virtual void render();
/**
* rotate the model
*
* @param dir the new direction the model will face,
*/
virtual void rotate( const vector3df &dir );
/**
* move the sprite default : using mDir and mSpeed
* and make the basic collision check with the world
*
* You can obtain the collision check result by mCollResult after
* this funciton .
*/
virtual void move( float dt );
virtual void setPosition( const vector3df &pos );
virtual const vector3df getPosition();
virtual aabbox3df getWorldAABB();
virtual const vector3df getExpPosition();
/**
* get the sprite's array position in the world
*
*/
virtual void getArrayPos( int &ax, int &az );
virtual vector2di getArrayPos();
/**
* getXZRect
*
* return the rect on the xz plane
*/
virtual rect<f32> getXZRect();
/**
* setFireDelay
*
* it will set fire delay time by the type
*/
void setFireDelay( u32 delay = -1 );
void setVisible( bool visible );
/// especially used in Credits
AnimManager *accessAnimMgr();
ISceneNode *accessNode();
void setSpeed( float speed );
void setDir( vector3df dir );
protected:
vector3df mDir;
float mSpeed;
int mType;
ISceneNode *mNode;
float mMeshW;
float mMeshH;
int mCollResult; /// this frame collision check result with world
AnimManager *mAnimMgr; /// manage the animation of this sprite
u32 mLastFireTime; /// only used for player and monsters
u32 mFireDelay;
};
#endif // end _SPRITE_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -