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

📄 m_entity.h

📁 C++课程大学作业的一次任务
💻 H
字号:
//////////////////////////////////
//     M_ENTITY.H
//
// VIRTUAL BASE CLASS - M_ENTITY
//
// ALL THE MAP OBJECTS INCLUDING
// SPRITE, MONSTERS, DOTS COMES
// FROM THIS CLASS
//
// PROJECT: ULTRA PAC MAN
// PROGRAMER: Mal
// LAST UPDATE: NOV. 28th 2001
/////////////////////////////////

#include "m_common.h"
#include "m_map.h"
#include "m_event.h"
#include "m_time.h"
#include "m_render.h"


#ifndef m_entity
 #define m_entity

struct BaseProperty
{
	int 	nPosX;
	int 	nPosY;
	int 	nDirection;
	float 	fSpeed;
	int 	nTexture;
	bool 	isLiving;
};

class M_Entity
{
 public:
	M_Entity();
	virtual ~M_Entity();
	virtual bool Think() = 0;
	virtual bool Respawn() = 0;
	virtual bool Kill() = 0;
	const BaseProperty* Report();
 protected:
	BaseProperty* thisEnt;
};

////////////////////////////////
// DERIVATIVE CLASSES         //
////////////////////////////////


////////////////////////////////
//    M_MOVER CLASS
//
// BASE CLASS FOR EVERY MOVING
// THINGS IN THE MAP, WITH A
// SIZE LIMIT OF ONE BLOCK
////////////////////////////////
class M_Mover: public M_Entity
{
 public:
	bool Move(int direction);
	int MoverSpeed(int desiredSpeed=-1);
	bool HaveOffset();//reports if offsets
	int MoverState(int state = -1);

 protected:
	int		nState;//States: NORMAL, SPEED, POWER etc.
	int  	nNextMovDir;
	float  	fOffsetX, fOffsetY;//Offsets
	int  	nLastMovDir;//the direction last time the move() is called

};

////////////////////////////////////
//    M_SPRITE CLASS
//		(DERIVED FROM M_MOVER)
//
// A SPRITE CAN'T ACTUALLY 'THINK',
// WHEN 'THINK' IS CALLED, IT
// RESPONDS TO THE PLAYER'S INPUT.
////////////////////////////////////
class M_Sprite: public M_Mover
{
 public:
	M_Sprite();
	bool Respawn();
	bool Think();
	bool Kill();
	void DispatchEvent();
	int  AddLives(int deltaLives=0);
	long AddScore(int score=0);
	bool isInit;//this variable only affects the respawn point

 protected:
	long	lZombieTime;//time before force to respawn
	bool 	bReadyToRespawn;
	int 	nLives;
	int  	nTotalSRP;
	long	lTotalScore;
};

extern M_Sprite* thisSprite;//global pointer;

////////////////////////////////////////
//   M_MONSTER CLASS
//        (DERIVED FROM M_MOVER)
//
// A MONSTER REALLY DOES 'THINK',
// ESPECIALLY WHEN A SPRITE IS IN ITS
// 'SIGHT' AND WITHIN ITS PERCEIVABLE
// 'DISTANCE'. IT TAKES RANDOM MOVES
// WHEN IT CAN'T SEE THE SPRITE.
// BEWARE! A MONSTER CAN SEE ALL THE
// FOUR DIRECTION AT A TIME! :)
////////////////////////////////////////


class M_Monster: public M_Mover
{
 public:
	M_Monster();
	bool Respawn();
	bool Think();
	bool Kill();
	int  RandomDir();
	void AIChangeNextMove(int nextMove);

	int  nAwareDistance;//no need to protect la~
 protected:
	int curNextDir;
	static int presentMRP;
};

struct MonsterNode //Monster node for monster link table
{
	M_Monster* thisMonster;
	MonsterNode* nextMonster;
};


//////////////////////////////////////
//          M_ITEM CLASS
//
// HOW COULD A ITEM 'THINK'?? IT CAN'T
// 'THINK', IT CAN ONLY BE EATEN OR
// 'KILL' BY A SPRITE. IT IS STILL
// A VIRTUAL CLASS.
//
// FOR MEMORY MANAGE REASON, NORMAL
// DOTS ARE NOT INCLUDED INTO M_ITEM
// CLASSES.
//////////////////////////////////////

class M_Item: public M_Entity
{
 public:
	M_Item();
	bool Think() {return M_NORMAL;}
	virtual bool Think(M_Sprite*, MonsterNode*) {return M_NORMAL;}
 protected:
	int nScore;
	bool isActivated;
	long nextThinkTime;
	static bool bDisable;
};

///////////////////////////////////
// M_POWERDOT CLASS
//    (DERIVED FROM M_ITEM)
//
// FEED YOUR SPRITE WITH THIS,
// IT WILL BECOME MONSTER BUSTER
// FOR SOME WHILE. HOW COME,
// I WOULD LIKE TO CALL IT:
//  !!!Q U A D  D A M A G E!!!
///////////////////////////////////
class M_PowerDot: public M_Item
{
 public:
	M_PowerDot(int x, int y);
	//~M_PowerDot();
	bool Respawn();
	bool Think(M_Sprite* sprite, MonsterNode* monster);
	bool Kill();
};

///////////////////////////////////
// M_SPEEDDOT CLASS
//     (DERIVED FROM M_ITEM)
//
// MAKE YOUR SPRITE FEEL LIKE
// LIGHTNING...<ALSO POWERFUL!!!>
///////////////////////////////////

class M_SpeedDot: public M_Item
{
 public:
	M_SpeedDot(int x, int y);
	//~M_SpeedDot();
	bool Respawn();
	bool Think(M_Sprite* sprite, MonsterNode* monster);
	bool Kill();
 protected:
	long respawnTime;
};

#endif

⌨️ 快捷键说明

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