DNF_DEV_SQR
This commit is contained in:
52
Game/CharacterScript/Common/Move.nut
Normal file
52
Game/CharacterScript/Common/Move.nut
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
文件名:Move.nut
|
||||
路径:Game/CharacterScript/Common/Move.nut
|
||||
创建日期:2025-10-03 02:02
|
||||
文件用途:角色移动脚本
|
||||
*/
|
||||
|
||||
function checkCanChangeState_Character_Move(obj) {
|
||||
//获取当前状态
|
||||
local CurState = obj.GetState();
|
||||
//得到摇杆的数据 X 和 Y的范围 -1.0 ~ 1.0
|
||||
local arr = obj.GetVars("_move_data_", "float");
|
||||
if (fabs(arr[0]) > 0.35 || fabs(arr[1]) > 0.35) {
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function SetState_Character_Move(obj) {
|
||||
//获取移动数据
|
||||
local arr = obj.GetVars("_move_data_", "float");
|
||||
|
||||
//设置人物朝向 摇杆X轴大于0则朝右,小于0则朝左
|
||||
local SetValue = arr[0] > 0 ? 0 : 1;
|
||||
if (SetValue != obj.GetDirection()) {
|
||||
if (fabs(arr[0]) > 0.35) obj.SetDirection(SetValue);
|
||||
//设置动作
|
||||
obj.SetAction("move");
|
||||
} else {
|
||||
if (obj.GetState() != 1) obj.SetAction("move");
|
||||
}
|
||||
|
||||
local Speed = 250;
|
||||
local Dir = obj.GetDirection();
|
||||
local Pos = obj.GetPosition();
|
||||
local XOffset = null;
|
||||
if (fabs(arr[0]) > 0.35) XOffset = ((arr[0] > 0 ? Speed : -Speed));
|
||||
else XOffset = 0;
|
||||
local YOffset = null;
|
||||
//当摇杆Y轴大于0.35或小于-0.35时,设置Y轴偏移量
|
||||
if (fabs(arr[1]) > 0.35) YOffset = (arr[1] > 0 ? Speed : -Speed);
|
||||
else YOffset = 0;
|
||||
|
||||
obj.SetSpeed(XOffset, YOffset, null);
|
||||
}
|
||||
|
||||
function ProcState_Character_Move(obj, DeltaTime) {
|
||||
//获取移动数据
|
||||
local arr = obj.GetVars("_move_data_", "float");
|
||||
if (arr[0] == 0 && arr[1] == 0) {
|
||||
obj.SetState(0);
|
||||
}
|
||||
}
|
||||
22
Game/CharacterScript/Common/Rest.nut
Normal file
22
Game/CharacterScript/Common/Rest.nut
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
文件名:Rest.nut
|
||||
路径:Game/CharacterScript/Common/Rest.nut
|
||||
创建日期:2025-10-03 02:02
|
||||
文件用途:角色站立状态
|
||||
*/
|
||||
|
||||
function checkCanChangeState_Character_Rest(obj) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function SetState_Character_Rest(obj) {
|
||||
//设置动作
|
||||
obj.SetAction("rest");
|
||||
//设置速度
|
||||
obj.SetSpeed(0, 0, null);
|
||||
}
|
||||
|
||||
function ProcState_Character_Rest(obj, DeltaTime) {
|
||||
|
||||
}
|
||||
25
Game/ObjectClass/ActiveObject.nut
Normal file
25
Game/ObjectClass/ActiveObject.nut
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
文件名:ActiveObject.nut
|
||||
路径:Game/ObjectClass/ActiveObject.nut
|
||||
创建日期:2025-10-03 02:50
|
||||
文件用途:
|
||||
*/
|
||||
|
||||
class ActiveObject extends BaseObject {
|
||||
|
||||
constructor(Object) {
|
||||
base.constructor(Object);
|
||||
}
|
||||
|
||||
function SetSpeed(x, y, z) {
|
||||
local CurSpeed = sq_GetSpeed(C_Object);
|
||||
if (x == null) x = CurSpeed.x;
|
||||
if (y == null) y = CurSpeed.y;
|
||||
if (z == null) z = CurSpeed.z;
|
||||
sq_SetSpeed(C_Object, x, y, z);
|
||||
}
|
||||
|
||||
function GetSpeed() {
|
||||
return sq_GetSpeed(C_Object);
|
||||
}
|
||||
}
|
||||
32
Game/ObjectClass/BaseObject.nut
Normal file
32
Game/ObjectClass/BaseObject.nut
Normal file
@@ -0,0 +1,32 @@
|
||||
class BaseObject {
|
||||
//c++对象指针
|
||||
C_Object = null;
|
||||
|
||||
constructor(Object) {
|
||||
C_Object = Object;
|
||||
}
|
||||
|
||||
function GetPosition() {
|
||||
return sq_GetPosition(C_Object);
|
||||
}
|
||||
|
||||
function SetPosition(x, y, z) {
|
||||
sq_SetPosition(C_Object, x, y, z);
|
||||
}
|
||||
|
||||
function GetVars(Name, Type) {
|
||||
return sq_GetVars(C_Object, Name, Type);
|
||||
}
|
||||
|
||||
function SetVars(Name, Type, Value) {
|
||||
sq_SetVars(C_Object, Name, Type, Value);
|
||||
}
|
||||
|
||||
function GetDirection() {
|
||||
return sq_GetDirection(C_Object);
|
||||
}
|
||||
|
||||
function SetDirection(Dir) {
|
||||
sq_SetDirection(C_Object, Dir);
|
||||
}
|
||||
}
|
||||
23
Game/ObjectClass/CharacterObject.nut
Normal file
23
Game/ObjectClass/CharacterObject.nut
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
文件名:CharacterObject.nut
|
||||
路径:Game/ObjectClass/CharacterObject.nut
|
||||
创建日期:2025-10-03 02:50
|
||||
文件用途:
|
||||
*/
|
||||
class CharacterObject extends ActiveObject {
|
||||
constructor(Object) {
|
||||
base.constructor(Object);
|
||||
}
|
||||
|
||||
function GetState() {
|
||||
return sq_GetState(C_Object);
|
||||
}
|
||||
|
||||
function SetState(State) {
|
||||
sq_SetState(C_Object, State);
|
||||
}
|
||||
|
||||
function SetAction(key) {
|
||||
sq_SetAction(C_Object, key);
|
||||
}
|
||||
}
|
||||
85
Game/StateMachine/StateMachine.nut
Normal file
85
Game/StateMachine/StateMachine.nut
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
文件名:StateMachine.nut
|
||||
路径:Game/StateMachine/StateMachine.nut
|
||||
创建日期:2025-10-03 02:11
|
||||
文件用途:
|
||||
*/
|
||||
|
||||
class StateMachine {
|
||||
//状态注册表
|
||||
StatusRegistry = null;
|
||||
|
||||
constructor() {
|
||||
if (getroottable().rawin("__StateMachine__")) {
|
||||
// 防止重复实例化
|
||||
throw "StateMachine 不能重复实例化!";
|
||||
}
|
||||
//初始化状态注册表
|
||||
StatusRegistry = {};
|
||||
foreach(JobIndex in getconsttable().CHARACTERJOB) {
|
||||
StatusRegistry[JobIndex] <- {};
|
||||
}
|
||||
}
|
||||
|
||||
// 静态方法:获取唯一实例
|
||||
function GetInstance() {
|
||||
if (!getroottable().rawin("__StateMachine__")) {
|
||||
// 首次调用时创建实例
|
||||
getroottable()["__StateMachine__"] <- StateMachine();
|
||||
}
|
||||
return getroottable()["__StateMachine__"];
|
||||
}
|
||||
|
||||
//注册状态
|
||||
function RegisterState(Job, StateName, StateIndex) {
|
||||
StatusRegistry[Job][StateIndex] <- {
|
||||
StateName = StateName,
|
||||
StateIndex = StateIndex
|
||||
}
|
||||
print("注册了状态" + StateName + ",状态索引为" + StateIndex);
|
||||
}
|
||||
|
||||
//获取状态信息
|
||||
function GetStateInfo(Job, State) {
|
||||
return StatusRegistry[Job][State];
|
||||
}
|
||||
}
|
||||
|
||||
function StateMachine_checkCanChangeState(C_Object, Job, State) {
|
||||
//获取状态信息
|
||||
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
|
||||
//判断是否有 检查能否切换状态函数
|
||||
local FuncName = "checkCanChangeState_" + StateInfo.StateName;
|
||||
if (getroottable().rawin(FuncName)) {
|
||||
return getroottable()[FuncName](CharacterObject(C_Object));
|
||||
} else {
|
||||
error("没有找到" + FuncName + "函数");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function StateMachine_SetState(C_Object, Job, State) {
|
||||
//获取状态信息
|
||||
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
|
||||
//判断是否有 设置状态函数
|
||||
local FuncName = "SetState_" + StateInfo.StateName;
|
||||
if (getroottable().rawin(FuncName)) {
|
||||
getroottable()[FuncName](CharacterObject(C_Object));
|
||||
} else {
|
||||
error("没有找到" + FuncName + "函数");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function StateMachine_ProcState(C_Object, Job, State, DeltaTime) {
|
||||
//获取状态信息
|
||||
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
|
||||
//判断是否有 设置状态函数
|
||||
local FuncName = "ProcState_" + StateInfo.StateName;
|
||||
if (getroottable().rawin(FuncName)) {
|
||||
getroottable()[FuncName](CharacterObject(C_Object), DeltaTime);
|
||||
} else {
|
||||
error("没有找到" + FuncName + "函数");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
16
SquirrelFileConfig.cfg
Normal file
16
SquirrelFileConfig.cfg
Normal file
@@ -0,0 +1,16 @@
|
||||
enum.nut
|
||||
|
||||
|
||||
Game/StateMachine/StateMachine.nut
|
||||
|
||||
Game/ObjectClass/BaseObject.nut
|
||||
Game/ObjectClass/ActiveObject.nut
|
||||
Game/ObjectClass/CharacterObject.nut
|
||||
|
||||
|
||||
Game/CharacterScript/Common/Rest.nut
|
||||
Game/CharacterScript/Common/Move.nut
|
||||
|
||||
|
||||
UI/asd.nut
|
||||
main.nut
|
||||
0
UI/asd.nut
Normal file
0
UI/asd.nut
Normal file
27
enum.nut
Normal file
27
enum.nut
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
文件名:enum.nut
|
||||
路径:enum.nut
|
||||
创建日期:2025-10-03 02:41
|
||||
文件用途:
|
||||
*/
|
||||
|
||||
enum CHARACTERJOB {
|
||||
SWORDMAN // 男鬼剑士
|
||||
FIGHTER // 女格斗家
|
||||
GUNNER // 男神枪手
|
||||
MAGE // 女魔法师
|
||||
PRIEST // 男圣职者
|
||||
AT_GUNNER // 女神枪手
|
||||
THIEF // 暗夜使者
|
||||
AT_FIGHTER // 男格斗家
|
||||
AT_MAGE // 男魔法师
|
||||
DEMONIC_SWORDMAN // 黑暗武士
|
||||
CREATOR_MAGE // 缔造者
|
||||
AT_SWORDMAN // 女鬼剑士
|
||||
KNIGHT // 守护者
|
||||
DEMONIC_LANCER // 魔枪士
|
||||
AT_PRIEST // 女圣职者
|
||||
GUN_BLADER // 枪剑士
|
||||
ARCHER // 弓箭手
|
||||
MAX // 无
|
||||
};
|
||||
32
folder-alias.json
Normal file
32
folder-alias.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"Game": {
|
||||
"description": "游戏"
|
||||
},
|
||||
"UI": {
|
||||
"description": "界面"
|
||||
},
|
||||
"Game/ObjectClass": {
|
||||
"description": "对象类"
|
||||
},
|
||||
"Game/CharacterScript": {
|
||||
"description": "角色类脚本"
|
||||
},
|
||||
"Game/CharacterScript/Common": {
|
||||
"description": "通用"
|
||||
},
|
||||
"Game/StateMachine": {
|
||||
"description": "状态机"
|
||||
},
|
||||
"enum.nut": {
|
||||
"description": "枚举表"
|
||||
},
|
||||
"Game/ObjectClass/BaseObject.nut": {
|
||||
"description": "基础对象"
|
||||
},
|
||||
"Game/ObjectClass/ActiveObject.nut": {
|
||||
"description": "动态对象"
|
||||
},
|
||||
"Game/ObjectClass/CharacterObject.nut": {
|
||||
"description": "角色对象"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user