www.pudn.com > GameEngine_src.rar > CBaseSprite.h
#ifndef CBaseSprite_h
#define CBaseSprite_h
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "CEasyDraw.h"
#include "CEasyAudio.h"
#include "CPictureGroup.h"
#include "struct.h"
#include "CMyStack.h"
//精灵的各种状态,注意顺序不能变
enum SPRITE_STATE
{
SS_WAIT = 0, //静止
SS_IDLE = 1, //空闲
SS_WALK = 2, //行走
SS_HURT = 3, //被击中
SS_DEAD = 4, //死亡
SS_MELEE = 5, //攻击
SS_SPELL = 6, //施法
};
//精灵的各种种类
enum SPRITE_TYPE
{
ST_NONE = 0, //空
ST_MAGE_1 = 4, //地表魔法
ST_BODY = 8, //地表尸体
ST_ITEM = 12, //地表物品
ST_N_B = 16, //NPC与建筑
ST_MONSTER = 17, //地上的怪物
ST_MAGE_2 = 18, //地上的魔法
ST_HERO = 19, //英雄
ST_FLY = 20, //空中的怪物或精灵
ST_MAGE_3 = 21, //空中的魔法
};
//角色职业
enum HERO_CLASS
{
SC_ALL = 0, //所有职业
SC_FENCER = 1, //剑士
SC_ELEMENT = 2, //元素师
SC_CURSE = 3, //咒术师
};
///////////////////////////////////////////////////////////////
//精灵类的基类
//精灵类包括建筑,怪物,人物,魔法
///////////////////////////////////////////////////////////////
class CBaseSprite
{
public:
CBaseSprite();
virtual ~CBaseSprite();
virtual void DrawSprite() = 0;
virtual void DrawShadow();
virtual bool UpdateSprite() = 0;
bool IsSelected( int x, int y );
bool IsVisible( const RECT & rect );
void EnableSelected() { m_bSelected = true; }
SPRITE_TYPE GetSpriteType() { return m_SpriteType; }
void SetSpriteType( SPRITE_TYPE st ) { m_SpriteType = st; }
const POINT &GetBasePoint() { return m_BasePoint; }
void SetBasePoint( int x, int y ) { m_BasePoint.x = x; m_BasePoint.y = y; }
const RECT &GetRect() { return m_Rect; }
int GetPriority() { return m_Priority; }
void CalcPriority();
void GetNextPoint( int direction, POINT &next );
bool IsAlive() { return m_Life > 0; }
void SetLife( int i ) { m_Life = i; }
int GetLife() { return m_Life; }
static int CalcDistance( const POINT &base, const POINT &dest );
static int CalcDirection( const POINT &base, const POINT &dest );
static int CalcDirection( const CELL &from, const CELL &to );
protected:
SPRITE_TYPE m_SpriteType; //精灵的种类
RECT m_Rect; //Rect的四个坐标,都是地图坐标,单位像素
POINT m_BasePoint; //基点坐标,地图坐标,单位象素
POINT m_RenderPoint; //绘制的坐标,屏幕窗口坐标,单位像素
bool m_bSelected; //是否被选取
int m_Priority; //渲染优先权
int m_Life; //精灵的生命值
int m_Frame;
unsigned int m_LastTick;
CPictureGroup * m_cur_pg; //图像组合
CPictureGroup * m_cur_shadow_pg; //阴影图像组合
};
///////////////////////////////////////////////////////////////
//建筑物类
//建筑物不分方向,没有方向这一数据
///////////////////////////////////////////////////////////////
class CBuilding : public CBaseSprite
{
public:
CBuilding();
~CBuilding();
bool Init( CPictureGroup *pPG, CPictureGroup *pSPG, const POINT &base );
void Free(){}
void DrawSprite();
bool UpdateSprite();
CPictureGroup *GetPG() { return m_cur_pg; }
private:
};
//////////////////////////////////////////////////////////////////////
//魔法状态结构
//////////////////////////////////////////////////////////////////////
struct MAGIC_STATE
{
short effectIndex; //作用项
short effectValue; //作用值
unsigned int endTime; //状态结束时间
};
//////////////////////////////////////////////////////////////////////
//魔法状态动画
//////////////////////////////////////////////////////////////////////
struct MAGIC_STATE_EPG
{
CPictureGroup * pEPG; //动画指针
unsigned int endTime; //状态结束时间
short drawType; //绘制时参考(上,中,下)
short curFrame; //当前帧
};
#endif