📄 gamelogic.h
字号:
#pragma once
#include <list>
#include "GameObj.h"
#include "ActorManager.h"
#include "EventManager.h"
class CGameLogic
{
public:
/*
* 构造函数:创建ActorManager和EventManager得对象
*/
CGameLogic(void) ;
/*
* 析构
*/
~CGameLogic(void) ;
/*
* 游戏各种状态的枚举
*/
enum state { STOP = 0, /* 用户控制的人物处于静止状态 */
WALKING = 1, /* 用户控制的人物处于奔跑状态 */
FIGHTING = 2, /* 游戏处于战斗场景状态 */
TALKING, /* 说话状态 */
MENUING, /* 菜单状态 */
NORMAL /* 一般状态 */
};
/*
* 枚举屏幕对象:对外接口
* 参数:
* object - 指向对象结构体CBaseStruct的指针,依次copy对象内容到指针,枚举结束copy空对象
*/
void enumObj( void* object ) ;
/*
* 逻辑状态更新,接受外界的调用
*/
void AutoUpdate() ;
/*
* 处理用户输入
* 参数:
* keymap - 若干个按键的按位map,某一位置1,表示键被按下
*/
void UserInput( int keymap ) ;
/*
* 查询对话,通过此机制来判断何时需要显示人物之间的对话
* 返回值:
* 返回对话板的指针,见STalking_Board
*/
const STalking_Board* QueryTalking() ;
/*
* 查询发现物品对话框,机制同CGameLogic::QueryTalking
*/
const SDiscovery_Board* QueryDiscovery() ;
/*
* 根据环境已经游戏状态移动当前的目标物体
* 参数:
* dx - x方向的目标偏移
* dy - y方向的目标偏移
*/
void ActiveMove( int dx, int dy ) ;
/*
* 从文件读入逻辑地图
* 参数:
* name - 文件名
*/
void LoadLogicalMap( const std::string& name) ;
/*
* 选择使用逻辑地图
* 参数:
* map_id - 逻辑地图的编号
*/
void UseLogicalMap(int map_id) ;
/*
* 获取图片资源信息,包括colorkey等
* 参数:
* res_name - 资源名
*/
GameRes* GetRes(const std::string& res_name) ;
/*
* 查询当前菜单标题,没有菜单返回NULL
*/
int QueryCurrentMenu( char** title ) ;
/*
* 查询战斗场景的位置以及大小
* 参数
* x - 指向圆心x坐标的指针
* y - 指向圆心y坐标的指针
* radius - 指向半径的int型指针
*/
void QueryBattleState( int* x, int* y, int* radius ) ;
/*
* 当前人物调查地图
*/
void Research() ;
/*
* 对选择菜单项的处理
*/
void SelectItem() ;
/*
* 枚举菜单项
* 参数:
* pItem - 指向菜单项的指针
*/
void enumMenuItem( void* pItem ) ;
/*
* 设置人物移动速度
* 参数:
* speed - 一次移动的象素
*/
void SetWalkingSpeed( int speed ) ;
/*
* 得到人物移动速度
* 返回值:
* 一次移动的象素
*/
int GetWalkingSpeed() ;
/*
* 得到npc的敏感距离
* 返回值:
* 象素为单位
*/
int GetSensitiveLength() ;
/*
* 开始战斗模式
* 参数:
* name - 玩家控制人物的名字
* npc_name - npc人物的名字
*/
void StartFight(const std::string& name, const std::string& npc_name) ;
/*
* 结束战斗模式
*/
void EndFight(const std::string& name);
/*
* 设置屏幕光圈焦点
* 参数:
* x - 圆心x坐标
* y - 圆心y坐标
* radius - 圆心半径
*/
void SetLightSpot( int x, int y, int radius ) ;
/*
* 得到当前逻辑地图某个位置的信息
* 参数:
* x - x坐标
* y - y坐标
* 返回值:
* 如实返回逻辑地图某个位置的值
*/
int GetLogicalMapInfo(int x, int y) ;
/*
* 是否在战斗模式
* 返回值:
* true - 在战斗模式,false - 不在战斗模式
*/
bool is_fighting() ;
/*
* 主角是否死掉
* 返回值:
* true - 死掉, false - 没死
*/
bool is_dead() ;
/*
* 本幕是否打通关,既完成既定任务
*/
bool is_success() ;
/*
* 设置上下方向的移动角度
* 参数:
* angel - 角度
*/
void set_up_walking_angel(double angel) ;
/*
* 设置左右方向的移动角度
* 参数:
* angel - 角度
*/
void set_left_walking_angel(double angel) ;
/*
* 得到战斗中电脑对手的名字
*/
std::string& get_npc_fighter();
/* 事件管理器 */
CEventManager* m_EventManager ;
/* 人物管理器 */
CActorManager* m_ActorManager ;
friend class CEventManager ;
friend class CPlayer ;
protected:
/*
* 从文件读取图片资源信息
*/
void LoadResInfo() ;
/*
* 判断菜单项是否枚举到结尾
*/
bool is_enum_item_end(const std::vector<SPropertyItem>::iterator& pos) ;
/*
* 判断菜单项是否在枚举的开始位置
*/
bool is_enum_item_begin(const std::vector<SPropertyItem>::iterator& pos) ;
/*
* 重置枚举指针到开始位置
*/
void reset_enum_pointer(std::vector<SPropertyItem>::iterator& pos) ;
/*
* 判断是否能够在预期方向卷动菜单
* 参数:
* way - 卷动方向,见CGameLogic::SCROLLINFO
* 返回值:
* bool型,代表能否卷动
*/
bool Scrolled(int way) ;
/*
* 打开指定的菜单
* 参数:
* id - 需要打开的菜单号,见CGameLogic::MENUNAME
*/
void BringUpMenu( int id ) ;
/*
* 拷贝ActiveActor的属性列表到通用菜单
*/
void dump_property_menu() ;
private:
enum { granularity = 10,
maxmap = 11, /* 最大逻辑地图数目 */
FASTMODE = 10, SLOWMODE = 5 /* 人物走路速度 */
};
enum SCROLLINFO { UPWARD = 0, DOWNWARD = 1, MAXSCROLLITEM = 4 };
enum MENUNAME { NOMENU = -1, MENU1 = 1, MENU2 = 2, MENU3 = 3, MENU4 = 4 }; /* 菜单状态 */
private:
/* 记录对话信息的结构体 */
STalking_Board m_talking_board ;
/* 记录消息框信息的结构体 */
SDiscovery_Board m_discovery_board ;
/* 游戏状态,参见CGameLogic::state */
state m_GameState ;
/* 是否接受用户输入 */
bool m_bAccept_user_inputs ;
/* 逻辑地图 */
int m_LogicMap[maxmap][800/granularity][600/granularity] ;
/* 当前场景的地图编号 */
int m_current_map ;
/* 当前菜单编号 */
int m_current_menu ;
/* 走路速度,一次update所行走的距离 */
int m_walking_speed ;
/* npc 的敏感距离 */
int m_sensitive_length ;
// 屏幕亮点坐标
int m_lightspot_x ;
/* 屏幕亮点坐标 */
int m_lightspot_y ;
/* 屏幕亮点半径 */
int m_lightspot_radius ;
/* 战斗中npc的名字 */
std::string m_npcFighter ;
/* 是否在战斗模式 */
bool m_is_fighting ;
/* 主角是否死掉 */
bool m_is_dead ;
/* 是否通关 */
bool m_is_success ;
/* 向上下方向移动的角度 */
double m_walking_angel_up ;
/* 向左右方向移动的角度 */
double m_walking_angel_left ;
private:
/* 把游戏中使用到的资源与外部文件联系起来 */
std::map< std::string, GameRes > m_game_res ;
/* 枚举菜单项用的指针 */
std::vector<SPropertyItem>::iterator m_enumPointer ;
/* 菜单焦点迭代器 */
std::vector<SPropertyItem>::iterator m_focused_menu_item;
/* 菜单卷动开始点 */
std::vector<SPropertyItem>::iterator m_scroll_point ;
/* 通用菜单 */
std::vector<SPropertyItem> m_gerneral_menu ;
};
inline void CGameLogic::UseLogicalMap(int map_id)
{
if ( map_id < maxmap )
{
m_current_map = map_id ;
}
}
inline int CGameLogic::QueryCurrentMenu( char** title )
{
switch (m_current_menu)
{
case MENU1 :
*title = "属性" ;
break;
case MENU2 :
*title = "装备菜单" ;
break;
case MENU3:
case MENU4:
*title = "空菜单" ;
break;
default:
//throw exception("invalid menu id when query menu caption!") ;
break;
}
return m_current_menu ;
}
inline void CGameLogic::SetWalkingSpeed(int speed )
{
m_walking_speed = speed ;
// 敏感距离也跟随改变
if ( speed <= SLOWMODE )
{
m_sensitive_length = 25 ;
}
else
{
m_sensitive_length = 55 ;
}
}
inline void CGameLogic::SetLightSpot(int x, int y, int radius )
{
m_lightspot_x = x ;
m_lightspot_y = y ;
m_lightspot_radius = radius ;
}
inline int CGameLogic::GetWalkingSpeed()
{
return m_walking_speed ;
}
inline int CGameLogic::GetLogicalMapInfo(int x, int y)
{
return m_LogicMap[ m_current_map ][x / granularity][y / granularity] ;
}
inline int CGameLogic::GetSensitiveLength()
{
return m_sensitive_length ;
}
inline bool CGameLogic::is_fighting()
{
return m_is_fighting ;
}
inline bool CGameLogic::is_dead()
{
return m_is_dead ;
}
inline bool CGameLogic::is_success()
{
return m_is_success ;
}
inline void CGameLogic::set_up_walking_angel(double angel)
{
m_walking_angel_up = angel ;
}
inline void CGameLogic::set_left_walking_angel(double angel)
{
m_walking_angel_left = angel ;
}
inline std::string& CGameLogic::get_npc_fighter()
{
return m_npcFighter ;
}
extern CGameLogic* LogicEngine ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -