/// <summary> /// 设置激光的发射源是否显示 /// </summary> /// <param name="luaState"></param> /// <para>isEnable 是否显示</para> /// <para>sourceIndex 发射源的图像索引</para> /// <returns></returns> public static int SetLinearLaserSourceEnable(ILuaState luaState) { EnemyLinearLaser laser = luaState.ToUserData(-2) as EnemyLinearLaser; bool isEnable = luaState.ToBoolean(-1); laser.SetSourceEnable(isEnable); return(0); }
/// <summary> /// 设置直线激光的长度 /// <para>laser</para> /// <para>int laserLen 激光的长度</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int SetLinearLaserLength(ILuaState luaState) { EnemyLinearLaser laser = luaState.ToUserData(-2) as EnemyLinearLaser; int laserLen = luaState.ToInteger(-1); laser.SetLength(laserLen); return(0); }
private BulletBase NewBullet(BulletType bulletID) { BulletBase bullet = null; Stack <BulletBase> _stack; // 判断对象池中是否有该类型的对象,如果有,则取出 if (_bulletsPool.TryGetValue(bulletID, out _stack)) { if (_stack.Count > 0) { bullet = _stack.Pop(); } } else { _stack = new Stack <BulletBase>(); _bulletsPool.Add(bulletID, _stack); } // 如果对象池内没有该对象,则创建 if (bullet == null) { switch (bulletID) { case BulletType.ReimuA_Sub1: bullet = new BulletReimuASub1(); break; case BulletType.Player_Laser: bullet = new PlayerLaser(); break; case BulletType.Player_Simple: bullet = new PlayerBulletSimple(); break; case BulletType.Enemy_Laser: bullet = new EnemyLaser(); break; case BulletType.Enemy_CurveLaser: bullet = new EnemyCurveLaser(); break; case BulletType.Enemy_Simple: bullet = new EnemySimpleBullet(); break; case BulletType.Enemy_LinearLaser: bullet = new EnemyLinearLaser(); break; default: Logger.Log("Create Bullet Fail! Invalid BulledId!"); break; } } return(bullet); }
/// <summary> /// 创建可发射的直线激光 /// <para>texture 暂时指向于etama9的激光贴图</para> /// <para>laserLen 激光长度</para> /// <para>posX</para> /// <para>posY</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int CreateLinearLaser(ILuaState luaState) { string id = luaState.ToString(-4); int laserLen = luaState.ToInteger(-3); float posX = (float)luaState.ToNumber(-2); float posY = (float)luaState.ToNumber(-1); luaState.Pop(4); EnemyLinearLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_LinearLaser) as EnemyLinearLaser; laser.SetStyleById(id); laser.SetLength(laserLen); laser.SetPosition(posX, posY); luaState.PushLightUserData(laser); return(1); }
public static int CreateCustomizedLinearLaser(ILuaState luaState) { int numArgs = luaState.GetTop() - 3; string customizedName = luaState.ToString(-3 - numArgs); float posX = (float)luaState.ToNumber(-2 - numArgs); float posY = (float)luaState.ToNumber(-1 - numArgs); int initFuncRef = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName); luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, initFuncRef); // 将本体插入执行栈中 EnemyLinearLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_LinearLaser) as EnemyLinearLaser; laser.AddOrGetComponent <BCCustomizedTask>(); laser.SetPosition(posX, posY); luaState.PushLightUserData(laser); for (int i = 0; i < numArgs; i++) { luaState.PushValue(-2 - numArgs); } luaState.Call(numArgs + 1, 0); // 将返回值压入栈中 luaState.PushLightUserData(laser); return(1); }
public static bool Get(object o, TValue key, out TValue res) { EnemyLinearLaser bullet = (EnemyLinearLaser)o; res = new TValue(); if (key.TtIsString()) { switch (key.SValue()) { #region 基础变量 case "x": { res.SetNValue(bullet.GetPosition().x); return(true); } case "y": { res.SetNValue(bullet.GetPosition().y); return(true); } case "rot": { res.SetNValue(bullet.GetRotation()); return(true); } case "dx": { res.SetNValue(bullet.dx); return(true); } case "dy": { res.SetNValue(bullet.dy); return(true); } #endregion #region 运动相关变量 case "v": { res.SetNValue(bullet.velocity); return(true); } case "vx": { res.SetNValue(bullet.vx); return(true); } case "vy": { res.SetNValue(bullet.vy); return(true); } case "vAngle": { res.SetNValue(bullet.vAngle); return(true); } case "maxV": { res.SetNValue(bullet.maxVelocity); return(true); } case "acce": { res.SetNValue(bullet.acce); return(true); } case "accAngle": { res.SetNValue(bullet.accAngle); return(true); } #endregion #region 子弹类专属变量 case "timer": { res.SetNValue(bullet.timeSinceCreated); return(true); } case "SetSelfRotation": { res.SetClCsValue(_funcSetSelfRotaion); return(true); } case "SetStyleById": { res.SetClCsValue(_funcSetStyleById); return(true); } #endregion #region 运动类专属方法 ISTGMovable case "SetV": { res.SetClCsValue(_funcSetV); return(true); } case "SetAcce": { res.SetClCsValue(_funcSetAcce); return(true); } case "SetStraightParas": { res.SetClCsValue(_funcSetStraightParas); return(true); } case "SetPolarParas": { res.SetClCsValue(_funcSetPolarParas); return(true); } case "MoveTo": { res.SetClCsValue(_funcMoveTo); return(true); } case "MoveTowards": { res.SetClCsValue(_funcMoveTowards); return(true); } case "SetPos": { res.SetClCsValue(_funcSetPos); return(true); } case "GetPos": { res.SetClCsValue(_funcGetPos); return(true); } #endregion #region IAttachable case "AttachTo": { res.SetClCsValue(_funcAttachTo); return(true); } case "SetRelativePos": { res.SetClCsValue(_funcSetRelativePos); return(true); } #endregion #region ITaskExecuter case "AddTask": { res.SetClCsValue(_funcAddTask); return(true); } #endregion #region 激光相关 case "SetSourceEnable": { res.SetClCsValue(_funcSetSourceEnable); return(true); } case "SetHeadEnable": { res.SetClCsValue(_funcSetHeadEnable); return(true); } case "SetLength": { res.SetClCsValue(_funcSetLength); return(true); } #endregion } } res.SetSValue(string.Format("GetField from userData fail!Invalid key {0} for type {1}", key, typeof(EnemySimpleBullet).Name)); return(false); }
public static bool Set(object o, TValue key, ref TValue value) { EnemyLinearLaser bullet = (EnemyLinearLaser)o; if (key.TtIsString()) { switch (key.SValue()) { #region 基础变量 case "x": { Vector2 pos = bullet.GetPosition(); pos.x = (float)value.NValue; bullet.SetPosition(pos); return(true); } case "y": { Vector2 pos = bullet.GetPosition(); pos.y = (float)value.NValue; bullet.SetPosition(pos); return(true); } case "rot": { bullet.SetRotation((float)value.NValue); return(true); } #endregion #region 运动相关变量 case "v": { bullet.velocity = (float)value.NValue; return(true); } case "vx": { bullet.vx = (float)value.NValue; return(true); } case "vy": { bullet.vy = (float)value.NValue; return(true); } case "vAngle": { bullet.vAngle = (float)value.NValue; return(true); } case "maxV": { bullet.maxVelocity = (float)value.NValue; return(true); } case "acce": { bullet.acce = (float)value.NValue; return(true); } case "accAngle": { bullet.accAngle = (float)value.NValue; return(true); } #endregion #region 子弹类专属变量 case "orderInLayer": { bullet.SetOrderInLayer((int)value.NValue); return(true); } case "checkCollision": { bullet.SetDetectCollision(value.BValue()); return(true); } case "checkBorder": { bullet.SetCheckOutOfBorder(value.BValue()); return(true); } #endregion } } value.SetSValue(string.Format("SetField of userData fail!Invalid key {0} for type {1}", key, typeof(EnemySimpleBullet).Name)); return(false); }