object.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:9k
- #ifndef _ASIDER_TANK_ALPHA3_OBJECT_H_
- #define _ASIDER_TANK_ALPHA3_OBJECT_H_
- #define BULLET_MAXCHANG 4
- #define MAXSPEEDONICE 8
- #define MAXTANKSPEED 8
- #define DEFTANKSPEED 4
- #define DEFBULLETSPEED 12
- #define DEFBULLETWIDTH 16
- #define DEFBULLETHEIGHT 16
- #define OBJSTAT_UNUSED 0
- #define OBJSTAT_BORN 0x010000
- #define OBJSTAT_LIVE 0x020000
- #define OBJSTAT_DIE 0x040000
- #define OBJSTAT_CADAVER 0x080000
- #define EQUIP_SHIP 0x0001
- #define EQUIP_ICE 0x0002
- struct TANKCMD {
- unsigned int cmd;
- bool fire;
- };
- //-----------------------------------------------------------------------------
- // Type enumeration
- //-----------------------------------------------------------------------------
- enum ObjectType { OBJTYPE_NONE, OBJTYPE_TANK, OBJTYPE_BULLET,
- OBJTYPE_BLOCK, OBJTYPE_BASE, OBJTYPE_EFFECT,
- OBJTYPE_FOOD };
- enum PropertyType { PROTYPE_NONE };
- enum EffectType { EFFECT_NONE, EFFECT_TANKBOOM, EFFECT_BULLETBOOM };
- enum DirectionType { DIR_NONE, DIR_RIGHT, DIR_DOWN, DIR_UP, DIR_LEFT, DIR_MAX };
- enum TeamType { TEAM_HOME, TEAM_ENEMY, TEAM_NEUTRAL };
- enum LocateIndex { LOC_BLOCK_NONE, LOC_BLOCK_BRICK0, LOC_BLOCK_IRON0,
- LOC_BLOCK_RIVER0, LOC_BLOCK_RIVER1, LOC_BLOCK_RIVER2,
- LOC_BLOCK_GRASS0, LOC_BLOCK_ICE0,
- LOC_OBJECT_TANK0, LOC_OBJECT_TANK1, LOC_OBJECT_BULLET0
- };
- enum FoodType { FOOD_SHIP, FOOD_KEEPBASE, FOOD_POWERUP, FOOD_BLOODUP,
- FOOD_SPEEDUP, FOOD_MAX };
- //-----------------------------------------------------------------------------
- // Classes defined in this header file
- //-----------------------------------------------------------------------------
- class CObject;
- class CMobileObject;
- class CProperty;
- class CObjBase;
- class CObjBlock;
- class CObjFood;
- class CObjTank;
- class CObjBullet;
- class CObjEffect;
- //-----------------------------------------------------------------------------
- // Name: class CObject
- // Desc: Base Class of all the objects which can change its appearance
- // or position, or just its values of properties
- //-----------------------------------------------------------------------------
- class CObject
- {
- protected:
- DWORD m_dwObjType;
- DWORD m_dwObjStat;
- int m_nStatCounter;
- int m_nLeft;
- int m_nTop;
- int m_nWidth;
- int m_nHeight;
-
- DWORD m_dwFrameType;
- int m_nTotalFrame;
- int m_nCurrentFrame;
- DWORD m_dwLastTime;
- DWORD m_dwPersistTime;
- public:
- CObject();
- ~CObject();
- // Access functions
- DWORD GetType() { return m_dwObjType; }
- DWORD GetStat() { return m_dwObjStat; }
- void SetStat( DWORD s ) { m_dwObjStat = s; }
- int GetLeft() { return m_nLeft; }
- int GetTop() { return m_nTop; }
- void SetPos( int l, int t ) { m_nLeft = l; m_nTop = t; }
- void SetOffset( int h, int v ) { m_nLeft += h; m_nTop += v; }
- int GetWidth() { return m_nWidth; }
- int GetHeight() { return m_nHeight; }
- RECT GetRect();
-
- DWORD GetFrameType() { return m_dwFrameType; }
- int GetFrameCurrent() { return m_nCurrentFrame; }
- int GetFrameTotal() { return m_nTotalFrame; }
- void SetTotalFrame( int t ) { m_nTotalFrame = t; }
- // Status functions
-
- // Creation/destruction methods
- // Object methods
- void NextFrame( DWORD nowtime );
- // bool TestNextFrame() { return ++m_nCurrentFrame < m_nTotalFrame; }
- };
- //-----------------------------------------------------------------------------
- // Name: class CMobileObject
- // Desc: Base Class of all the objects which can move
- //-----------------------------------------------------------------------------
- class CMobileObject : public CObject
- {
- protected:
- int m_nMoveStep;
- public:
- UINT m_uiDirection;
- UINT m_uiTeamType;
- public:
- CMobileObject();
- ~CMobileObject();
- // Access functions
- int GetStep() { return m_nMoveStep; }
- void SetStep( int s ) { m_nMoveStep = s; }
- RECT GetNextRect();
- RECT GetNextRectStep( int step );
- POINT GetDirectionUnit();
- };
- //-----------------------------------------------------------------------------
- // Name: class CProperty
- // Desc: Base Class of all the properties whose value may be changed
- //-----------------------------------------------------------------------------
- class CProperty
- {
- protected:
- int m_nDefaultValue;
- int m_nCurrentValue;
- int m_nMaxValue;
- int m_nMinValue;
- public:
- CProperty();
- ~CProperty();
- // Access functions
- // Status functions
- bool IsZero() { return m_nCurrentValue == 0; }
- bool IsMin() { return m_nCurrentValue == m_nMinValue; }
-
- // Creation/destruction methods
- void CreateProperty( int def, int max, int min );
-
- // Object methods
- int GetPercent( int total ) { return total*m_nCurrentValue/m_nMaxValue; }
- void Add( int step );
- bool Minus( int step );
- };
- //-----------------------------------------------------------------------------
- // Name: class CObjTank
- // Desc: Class of Tank object
- //-----------------------------------------------------------------------------
- class CObjTank : public CMobileObject
- {
- bool m_bHome;
- bool m_bBoom;
- int m_nIndex;
- bool m_bHaveBullet;
-
- public:
- bool m_bMoving;
- bool m_bOnIce;
- int m_nIceStep;
- UINT m_uiIceDir;
- DWORD m_dwEquip;
- CProperty m_prtBlood;
- int m_nAttack;
- public:
- CObjTank();
- ~CObjTank();
- // Status functions
- bool IsHomeTeam() { return m_bHome; }
- bool HaveBullet() { return m_bHaveBullet; }
- // Access functions
- int GetBloodPercent(int total) { return m_prtBlood.GetPercent(total); }
- void NextStat();
- void SetBullet() { m_bHaveBullet = true; }
- void RemoveBullet() { m_bHaveBullet = false; }
- int GetIndex() { return m_nIndex; }
- void Hited( int attack );
-
- // Creation/destruction methods
- void CreateTank( int left, int top, bool bHome );
-
- // Methods
- RECT GetNextRectOnIce();
- POINT GetDirUnitOnIce();
- };
- //-----------------------------------------------------------------------------
- // Name: class CObjBullet
- // Desc: Base Class of all bullet objects which have expecial effects
- //-----------------------------------------------------------------------------
- class CObjBullet : public CMobileObject
- {
- bool m_bHome;
- int m_nAttack;
- CObjTank *m_obkTank;
- public:
- CObjBullet();
- ~CObjBullet();
- // Status functions
- bool IsHomeTeam() { return m_bHome; }
- // Access functions
- void NextStat();
- int GetAttack() { return m_nAttack; }
-
- // Creation/destruction methods
- void CreateBullet( CObjTank *ptk );
-
- // Methods
- void Hit( CObjTank *ptk );
- void Hit( CObjBullet *pblt );
- void Rebound() { m_uiDirection = 5 - m_uiDirection; }
- };
- //-----------------------------------------------------------------------------
- // Name: class CObjBullet
- // Desc: Base Class of all bullet objects which have expecial effects
- //-----------------------------------------------------------------------------
- class CObjEffect : public CMobileObject
- {
- DWORD m_dwEffect;
- int m_nAttack;
- public:
- CObjEffect();
- ~CObjEffect();
- // Access functions
- DWORD GetEffect() { return m_dwEffect; }
- // Creation/destruction methods
- void CreateEffect( CObject *pobj );
-
- // Methods
- };
- //-----------------------------------------------------------------------------
- // Name: class CObjBase
- // Desc: Class of a team's base
- //-----------------------------------------------------------------------------
- class CObjBase : public CMobileObject
- {
- bool m_bHome;
- public:
- CProperty m_ptyBlood;
- public:
- CObjBase();
- ~CObjBase();
- // Status functions
- bool IsHomeTeam() { return m_bHome; }
- // Access functions
- RECT GetSurroundRect();
- // Creation/destruction methods
- void CreateBase( int x, int y, bool bHome );
- // Methods
- };
- //-----------------------------------------------------------------------------
- // Name: class CObjBase
- // Desc: Class of a team's base
- //-----------------------------------------------------------------------------
- class CObjBlock : public CObject
- {
- int m_nbx;
- int m_nby;
- int m_nLand;
- public:
- CObjBlock();
- ~CObjBlock();
- // Access functions
- int GetBx() { return m_nbx; }
- int GetBy() { return m_nby; }
- int GetLand() { return m_nLand; }
- // Creation/destruction methods
- void CreateObjBlock( int x, int y, int land );
-
- // Methods
- };
- //-----------------------------------------------------------------------------
- // Name: class CObjBase
- // Desc: Class of a team's base
- //-----------------------------------------------------------------------------
- class CObjFood : public CObject
- {
- bool m_bExsit;
- bool m_bPresent;
- DWORD m_dwType;
- public:
- CObjFood();
- ~CObjFood();
- // Access functions
- void SetPresent( bool p ) { m_bPresent = p; }
- void SetExsit( bool e ) { m_bExsit = e; }
- bool IsPresent() { return m_bPresent; }
- bool IsExsit() { return m_bExsit; }
- DWORD GetFoodType() { return m_dwType; }
- // Creation/destruction methods
- void CreateFood( DWORD type, int left, int top );
-
- // Methods
- RECT GetPermitRect();
- void Benefit( CObjTank *ptk );
- };
- #endif // _ASIDER_TANK_ALPHA3_OBJECT_H_