/// <summary>
    /// 根据tag移除引力场
    /// <para>string tag</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int RemoveGravitationFieldByTag(ILuaState luaState)
    {
        string tag = luaState.ToString(-1);

        ColliderManager.GetInstance().RemoveGravitationFieldByTag(tag);
        return(0);
    }
 public void UpdateState2()
 {
     _time++;
     _curScale     = MathUtil.GetEaseOutQuadInterpolation(State1EndScale, State2EndScale, _time, _duration);
     _detectRadius = _curScale * DefaultRadius;
     //CheckCollisionWithEnemyBullets();
     //CheckCollisionWithEnemy();
     for (int i = 0; i < BombCount; i++)
     {
         _bombsTf[i].localScale = new Vector3(_curScale, _curScale, 1);
         _colliderList[i].SetSize(_detectRadius, _detectRadius);
     }
     if (_time >= _duration)
     {
         // 全屏伤害
         ColliderCircle collider = ColliderManager.GetInstance().CreateColliderByType(eColliderType.Circle) as ColliderCircle;
         collider.SetSize(500, 500);
         collider.SetColliderGroup(eColliderGroup.EnemyBullet | eColliderGroup.Enemy);
         collider.SetPosition(Global.PlayerPos.x, Global.PlayerPos.y);
         collider.SetEliminateType(eEliminateDef.PlayerSpellCard);
         collider.SetHitEnemyDamage(150);
         collider.SetExistDuration(1);
         _curState = 3;
     }
 }
    /// <summary>
    /// 根据tag移除碰撞器
    /// <para>string tag</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int RemoveObjectColliderByTag(ILuaState luaState)
    {
        string tag = luaState.ToString(-1);

        ColliderManager.GetInstance().RemoveColliderByTag(tag);
        return(0);
    }
Beispiel #4
0
    public void Init()
    {
        // 游戏本体边界
        Global.GameLBBorderPos = new Vector2(-Consts.GameWidth / 2, -Consts.GameHeight / 2);
        Global.GameRTBorderPos = new Vector2(Consts.GameWidth / 2, Consts.GameHeight / 2);
        // 弹幕边界
        Global.BulletLBBorderPos = new Vector2(Global.GameLBBorderPos.x - 100, Global.GameLBBorderPos.y - 100);
        Global.BulletRTBorderPos = new Vector2(Global.GameRTBorderPos.x + 100, Global.GameRTBorderPos.y + 100);
        // 玩家坐标边界
        Global.PlayerLBBorderPos = new Vector2(Global.GameLBBorderPos.x + 10, Global.GameLBBorderPos.y + 10);
        Global.PlayerRTBorderPos = new Vector2(Global.GameRTBorderPos.x - 10, Global.GameRTBorderPos.y - 10);

        InterpreterManager.GetInstance().Init();
        STGStageManager.GetInstance().Init();
        AnimationManager.GetInstance().Init();
        BulletsManager.GetInstance().Init();
        EnemyManager.GetInstance().Init();
        ItemManager.GetInstance().Init();
        ColliderManager.GetInstance().Init();

        ExtraTaskManager.GetInstance().Init();

        EffectsManager.GetInstance().Init();
        STGEliminateEffectManager.GetInstance().Init();
        BackgroundManager.GetInstance().Init();
#if ShowCollisionViewer
        CollisionViewer.Instance.Init();
#endif
    }
    /// <summary>
    /// 根据类型创建一个引力场
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateGravitationFieldByType(ILuaState luaState)
    {
        eColliderType      type     = (eColliderType)luaState.ToInteger(-1);
        ObjectColliderBase collider = ColliderManager.GetInstance().CreateGravitationFieldByType(type);

        luaState.PushLightUserData(collider);
        return(1);
    }
    /// <summary>
    /// 创建一个销毁敌机子弹以及敌机的ObjectCollider
    /// </summary>
    private void CreateEliminateEnemyCollider(Vector2 pos)
    {
        // 清除子弹用的collider
        ColliderCircle collider = ColliderManager.GetInstance().CreateColliderByType(eColliderType.Circle) as ColliderCircle;

        collider.SetPosition(pos);
        collider.SetSize(0, 0);
        collider.SetEliminateType(eEliminateDef.SpellCardFinish);
        collider.SetColliderGroup(eColliderGroup.EnemyBullet | eColliderGroup.Enemy);
        collider.ScaleToSize(400, 400, 30);
        collider.SetExistDuration(30);
    }
Beispiel #7
0
    private void RenderCollider()
    {
        Color col = new Color(255f / 255, 50f / 255, 255f / 255);
        int   count;
        List <ObjectColliderBase> list = ColliderManager.GetInstance().GetColliderList(out count);

        //int count = list.Count;
        foreach (var collider in list)
        {
            if (collider != null)
            {
                RenderCollisionGraphic(collider.GetCollisionDetectParas(), col);
            }
        }
    }
    public void OnFinish()
    {
        // 移除符卡事件监听
        CommandManager.GetInstance().Remove(CommandConsts.PlayerDying, this);
        CommandManager.GetInstance().Remove(CommandConsts.PlayerMiss, this);
        CommandManager.GetInstance().Remove(CommandConsts.PlayerCastSC, this);

        // 通过符卡经过的时间
        int framePassed = _frameTotal - _frameLeft;
        int timePassed  = framePassed * 1000 / Consts.TargetFrameRate;
        // 是否获得符卡奖励
        bool getBonus = true;

        if (!_isFinishSpellCard)
        {
            getBonus = false;
        }
        else if (_dyingCount != 0 || _castSCCount != 0)
        {
            getBonus = false;
        }
        // 计算通过符卡实际经过的时间
        long scFinishTimeTick = TimeUtil.GetTimestamp();
        int  realTimePassed   = (int)((scFinishTimeTick - _scStartTimeTick) / 10000);

        object[] datas = { _isSpellCard, _isFinishSpellCard, getBonus, timePassed, realTimePassed };
        CommandManager.GetInstance().RunCommand(CommandConsts.SpellCardFinish, datas);

        if (_finishFuncRef != 0)
        {
            InterpreterManager.GetInstance().AddPara(_bossList[0], LuaParaType.LightUserData);
            InterpreterManager.GetInstance().AddPara(_isFinishSpellCard, LuaParaType.Bool);
            InterpreterManager.GetInstance().AddPara(getBonus, LuaParaType.Bool);
            InterpreterManager.GetInstance().CallLuaFunction(_finishFuncRef, 3);
        }
        // 清除BossTask
        for (int i = 0; i < _bossCount; i++)
        {
            _bossList[i].OnSpellCardFinish();
        }
        ColliderManager.GetInstance().ClearAllObjectCollider(new List <eEliminateDef> {
            eEliminateDef.PlayerSpellCard
        });
        CreateEliminateEnemyCollider(_bossList[0].GetPosition());
    }
Beispiel #9
0
 public void Init(float angle, int index)
 {
     _dmg       = 35;
     _size      = 32;
     _curRot    = angle;
     _index     = index;
     _state     = 1;
     _totalTime = 190 - index * 10;
     CommandManager.GetInstance().Register(CommandConsts.PauseGame, this);
     CommandManager.GetInstance().Register(CommandConsts.ContinueGame, this);
     _collider = ColliderManager.GetInstance().CreateColliderByType(eColliderType.Circle);
     _collider.SetPosition(2000, 0);
     _collider.SetSize(_size, _size);
     _collider.RegisterCallback(eColliderGroup.Enemy, CollidedByEnemyCallback);
     _collider.SetEliminateType(eEliminateDef.PlayerSpellCard);
     _collider.SetColliderGroup(eColliderGroup.Enemy | eColliderGroup.EnemyBullet);
     _collider.SetHitEnemyDamage(_dmg);
     _isFinish = false;
 }
Beispiel #10
0
 /// <summary>
 /// 魔炮张开的阶段
 /// </summary>
 public void UpdateState1()
 {
     _curScaleX = MathUtil.GetEaseInQuadInterpolation(0, 1, _time, _duration);
     _sparkContainerTf.localScale = new Vector3(_curScaleX, 1, 1);
     if (_time >= _duration)
     {
         _curState          = 2;
         _nextMovementIndex = 0;
         _time = 0;
         // 设置碰撞
         _colliderRect = ColliderManager.GetInstance().CreateColliderByType(eColliderType.Rect) as ColliderRect;
         _colliderRect.SetSize(MasterSparkHitBoxWidth, MasterSpartHitBoxHeight);
         _colliderRect.SetColliderGroup(eColliderGroup.EnemyBullet | eColliderGroup.Enemy | eColliderGroup.Boss);
         _colliderRect.SetEliminateType(eEliminateDef.PlayerSpellCard);
         _colliderRect.SetHitEnemyDamage(1.5f);
         _colliderRect.SetPosition(Global.PlayerPos.x + _posOffset.x, Global.PlayerPos.y + _posOffset.y);
         _duration = 240;
     }
     _time++;
 }
 protected virtual void StateWaitRebornUpdate()
 {
     RotateCollisionPoint();
     _waitRebornTime++;
     // 创建消弹特效
     if (_waitRebornTime == EliminateEffectTime)
     {
         ColliderCircle collider = ColliderManager.GetInstance().CreateColliderByType(eColliderType.Circle) as ColliderCircle;
         collider.SetSize(0, 0);
         collider.ScaleToSize(ElimiateEffectSize, ElimiateEffectSize, EliminateEffectDuration);
         collider.SetExistDuration(EliminateEffectDuration);
         collider.SetHitEnemyDamage(1);
         collider.SetEliminateType(eEliminateDef.PlayerDead);
         collider.SetColliderGroup(eColliderGroup.EnemyBullet | eColliderGroup.Enemy | eColliderGroup.Boss);
     }
     if (_waitRebornTime >= _waitRebornDuration)
     {
         _nextState = eCharacterState.Appear;
     }
 }
Beispiel #12
0
    public void Clear()
    {
        PlayerInterface.GetInstance().Clear();
        _char = null;
        OperationController.GetInstance().Clear();
        ColliderManager.GetInstance().Clear();
        BulletsManager.GetInstance().Clear();
        EnemyManager.GetInstance().Clear();
        ItemManager.GetInstance().Clear();
        EffectsManager.GetInstance().Clear();
        ExtraTaskManager.GetInstance().Clear();
        BackgroundManager.GetInstance().Clear();
        STGStageManager.GetInstance().Clear();
        InterpreterManager.GetInstance().Clear();
        SoundManager.GetInstance().Clear(true);
#if ShowCollisionViewer
        CollisionViewer.Instance.Clear();
#endif
        STGEliminateEffectManager.GetInstance().Clear();
    }
Beispiel #13
0
 public override void Update()
 {
     for (int i = 0; i < _triggerDataCount; i++)
     {
         TriggerData data = _triggerDatas[i];
         if (data.triggerGroup == 0)
         {
             continue;
         }
         int listCount;
         List <ObjectColliderBase> colliderList = ColliderManager.GetInstance().GetColliderList(out listCount);
         ObjectColliderBase        collider;
         for (int j = 0; j < listCount; j++)
         {
             collider = colliderList[j];
             // 非空,且满足触发条件
             if (collider != null && ((int)collider.GetColliderGroup() & data.triggerGroup) != 0)
             {
                 int nextColliderIndex = 0;
                 int curColliderIndex;
                 do
                 {
                     CollisionDetectParas collParas = _bullet.GetCollisionDetectParas(nextColliderIndex);
                     curColliderIndex  = nextColliderIndex;
                     nextColliderIndex = collParas.nextIndex;
                     if (collider.DetectCollisionWithCollisionParas(collParas))
                     {
                         //InterpreterManager.GetInstance().AddPara(_bullet, LuaParaType.LightUserData);
                         InterpreterManager.GetInstance().AddPara(collider, LuaParaType.LightUserData);
                         InterpreterManager.GetInstance().AddPara(curColliderIndex, LuaParaType.Int);
                         InterpreterManager.GetInstance().CallLuaFunction(data.triggerFuncRef, 2, 0);
                     }
                 } while (nextColliderIndex != -1);
             }
         }
     }
 }
    public override void Start()
    {
        int            i;
        GameObject     go;
        Transform      tf;
        Vector2        playerPos = Global.PlayerPos;
        ColliderCircle collider;
        Vector2        bombPos;

        for (i = 0; i < BombCount; i++)
        {
            go = ResourceManager.GetInstance().GetPrefab("Prefab/Character", "ReimuABomb");
            tf = go.transform;
            UIManager.GetInstance().AddGoToLayer(go, LayerId.STGNormalEffect);
            _bombs.Add(go);
            _bombsTf.Add(tf);
            bombPos          = new Vector2(playerPos.x + _posOffsets[i].x, playerPos.y + _posOffsets[i].y);
            tf.localPosition = bombPos;
            tf.localScale    = Vector3.zero;
            SpriteRenderer sp = tf.Find("Bomb").GetComponent <SpriteRenderer>();
            sp.color = _colors[i];
            //sp.material.SetColor("_Color", _colors[i]);
            // 创建ObjectCollider
            collider = ColliderManager.GetInstance().CreateColliderByType(eColliderType.Circle) as ColliderCircle;
            collider.SetSize(0, 0);
            collider.SetColliderGroup(eColliderGroup.EnemyBullet | eColliderGroup.Enemy | eColliderGroup.Boss);
            collider.SetPosition(bombPos.x, bombPos.y);
            collider.SetEliminateType(eEliminateDef.PlayerSpellCard);
            collider.SetHitEnemyDamage(0.1f);
            _colliderList.Add(collider);
        }
        _curState = 1;
        _time     = 0;
        _duration = 180;
        _isFinish = false;
    }
    /// <summary>
    /// 创建自定义的collider
    /// <para>customizedName 自定义的类型名称</para>
    /// <para>eColliderType collider的形状类别</para>
    /// <para>参数...</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedCollider(ILuaState luaState)
    {
        int           top            = luaState.GetTop();
        int           numArgs        = top - 2;
        string        customizedName = luaState.ToString(-top);
        eColliderType type           = (eColliderType)luaState.ToInteger(-top + 1);
        int           funcRef        = InterpreterManager.GetInstance().GetCustomizedFuncRef(customizedName, eCustomizedType.Collider, eCustomizedFuncRefType.Init);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef);
        ObjectColliderBase collider = ColliderManager.GetInstance().CreateColliderByType(type);

        luaState.PushLightUserData(collider);
        // 复制参数
        int copyIndex = -numArgs - 2;

        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(copyIndex);
        }
        luaState.Call(numArgs + 1, 0);
        // 返回结果
        luaState.PushLightUserData(collider);
        return(1);
    }
Beispiel #16
0
    public void Update()
    {
        CommandManager.GetInstance().RunCommand(CommandConsts.STGFrameStart);

#if CheckSTGFrameTime
        int    index          = 0;
        long[] timeArr        = new long[20];
        long   frameBeginTime = Stopwatch.GetTimestamp();
        _opController.Update();
        STGStageManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        ColliderManager.GetInstance().UpdateFields();
        timeArr[index++] = Stopwatch.GetTimestamp();
        ExtraTaskManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        _char.Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        EnemyManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        BulletsManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        ItemManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        ColliderManager.GetInstance().UpdateColliders();
        timeArr[index++] = Stopwatch.GetTimestamp();
        EffectsManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        BulletsManager.GetInstance().Render();
        timeArr[index++] = Stopwatch.GetTimestamp();
        AnimationManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        BackgroundManager.GetInstance().Update();
        timeArr[index++] = Stopwatch.GetTimestamp();
        frameNode++;
        long frameEndTime = Stopwatch.GetTimestamp();
        if (frameEndTime - frameBeginTime >= 50000)
        {
            string logStr = "Frame " + STGStageManager.GetInstance().GetFrameSinceStageStart() + " cost time " + (frameEndTime - frameBeginTime) * 0.0001d + "ms\n";
            index   = 0;
            logStr += "STGStageManager Update Cost Time = " + (timeArr[index] - frameBeginTime) * 0.0001d + "ms\n";
            logStr += "GravitationFields Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "ExtraTaskManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "Character Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "EnemyManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "BulletsManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "ItemManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "Colliders Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "EffectsManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "BulletsManager Render Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "AnimationManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            logStr += "BackgroundManager Update Cost Time = " + (timeArr[++index] - timeArr[index - 1]) * 0.0001d + "ms\n";
            Logger.LogWarn(logStr);
            CommandManager.GetInstance().RunCommand(CommandConsts.LogFrameStatistics);
            Logger.Log("------------------------------------------------");
        }
#else
        //if (frameNode == 200)
        //{
        //    _lastFrameTicks = System.DateTime.Now.Ticks;
        //}
        //else if (frameNode > 200 && frameNode <= 300)
        //{
        //    long currentTicks = System.DateTime.Now.Ticks;
        //    Logger.Log("Frame Interval = " + (currentTicks - _lastFrameTicks) * 0.0001f);
        //    _lastFrameTicks = currentTicks;
        //}
        // 每帧开始
        BulletsManager.GetInstance().OnSTGFrameStart();
        // 逻辑部分
        _opController.Update();
        STGStageManager.GetInstance().Update();
        ExtraTaskManager.GetInstance().Update();
        ColliderManager.GetInstance().UpdateFields();
        _char.Update();
        EnemyManager.GetInstance().Update();
        BulletsManager.GetInstance().Update();
        ItemManager.GetInstance().Update();
        ColliderManager.GetInstance().UpdateColliders();
        EffectsManager.GetInstance().Update();
        // 渲染部分
        BulletsManager.GetInstance().Render();
        EnemyManager.GetInstance().Render();
        STGEliminateEffectManager.GetInstance().Render();
        ItemManager.GetInstance().Render();
        AnimationManager.GetInstance().Update();
        BackgroundManager.GetInstance().Update();
#if ShowCollisionViewer
        CollisionViewer.Instance.Render();
#endif
        //if (frameNode == 0)
        //    FPSController.GetInstance().Restart(true);
        frameNode++;
        //if (frameNode % 60 == 0)
        //{
        //   STGBulletEliminateEffect1 effect =  EffectsManager.GetInstance().CreateEffectByType(EffectType.BulletEliminate) as STGBulletEliminateEffect1;
        //    effect.SetColor(1, 0, 0, 1);
        //}
#endif
        //if ( frameNode == 200 )
        //{
        //    List<object> datas = new List<object>();
        //    float centerX = -130;
        //    float centerY = 180;
        //    float radius = 70;
        //    float distortFactor = 0.1f;
        //    Color effectColor = new Color(0.62f, 0.22f, 0.61f, 1f);
        //    datas.Add(centerX);
        //    datas.Add(centerY);
        //    datas.Add(radius);
        //    datas.Add(distortFactor);
        //    datas.Add(effectColor);
        //    CommandManager.GetInstance().RunCommand(CommandConsts.UpdateBgDistortEffectProps, datas.ToArray());
        //}
        //if ( frameNode == 200 )
        //{
        //    STGBurstEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.BurstEffect) as STGBurstEffect;
        //    effect.SetSize(128);
        //    effect.SetToPos(0, 150);
        //}
        //if (frameNode == 200)
        //{
        //    TimeUtil.BeginSample();
        //    STGChargeEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.ChargeEffect) as STGChargeEffect;
        //    effect.SetToPos(0, 100);
        //    TimeUtil.EndSample();
        //}
        //if (frameNode >= 200 && frameNode % 2 == 0 )
        //{
        //    STGBulletEliminateEffect effect = EffectsManager.GetInstance().CreateEffectByType(EffectType.BulletEliminate) as STGBulletEliminateEffect;
        //    effect.SetToPos(Random.Range(-8, 8), Random.Range(-8, 8));
        //    effect.SetColor(Random.value, Random.value, Random.value, 1);
        //}
    }