Example #1
0
        //-------------------------------------------------------------------------
        public override void update(float elapsed_tm)
        {
            if (canDestroy())
            {
                return;
            }

            CRenderLevel level = mScene.getLevel();

            if (level == null)
            {
                signDestroy();
                return;
            }

            bool level_isrun = level.isNormal();

            if (!level_isrun)
            {
                signDestroy();
                return;
            }

            mfTotalSecond += elapsed_tm;

            bool is_me = _isMe();

            if (is_me)
            {
                // 本人发炮,子弹生产者
                if (mfTotalSecond - mfLastFireSecond > mfFireTimeSpan)
                {
                    mfLastFireSecond = mfTotalSecond;

                    if (!InputController.Instance.MouseDown)
                    {
                        signDestroy();
                        return;
                    }

                    if (mTurret.getPlayerGold() < mTurret.getTurretRate())
                    {
                        mTurret.goldNotEnough();
                        return;
                    }

                    if (mTurret.checkWhetherFire())
                    {
                        Vector2 mouse_pos    = InputController.Instance.CurrentMousePosition;
                        int     bullet_objid = mTurret.genBulletObjId(1);
                        mTurret.doLocalFire(mouse_pos, bullet_objid, CBulletConstant.AutoRapidSpeed);

                        _tBullet bullet;
                        bullet.bullet_objid      = bullet_objid;
                        bullet.turret_angle      = mTurret.getTurretAngle();
                        bullet.turret_rate       = mTurret.getTurretRate();
                        bullet.locked_fish_objid = mTurret.getLockFishObjId();
                        mQueBullet.Enqueue(bullet);
                    }

                    if (miLeftBulletObjIdNum > 0)
                    {
                        miLeftBulletObjIdNum--;
                    }
                    else
                    {
                        //signDestroy();

                        // 极速转长按
                        CRenderBufferMgr buf_mgr = mTurret.getBufferMgr();
                        buf_mgr.removeBuffer("BufRapid");
                        if (!buf_mgr.hasBuffer("BufLongpress"))
                        {
                            List <object> param_list = new List <object>();
                            buf_mgr.addBuffer("BufLongpress", param_list);
                        }
                    }
                }
            }
            else
            {
                // 他人发炮,子弹消费者
                if (mfTotalSecond - mfLastFireSecond > mfFireTimeSpan)
                {
                    mfLastFireSecond = mfTotalSecond;

                    if (mQueBullet.Count > 0)
                    {
                        _tBullet bullet = mQueBullet.Dequeue();
                        mTurret.setLockFishByFishObjId(bullet.locked_fish_objid);
                        mTurret.setTurretAngle(bullet.turret_angle);
                        mTurret.setTurretRate(bullet.turret_rate);
                        mTurret.doOtherFire(bullet.bullet_objid, CBulletConstant.AutoRapidSpeed);
                    }
                }
            }

            // 如果是本人,则按5Hz的频率进行自动发炮的网络同步
            if (is_me)
            {
                if (mfTotalSecond - mfLastSyncSecond > mfSyncTimeSpan)
                {
                    mfLastSyncSecond = mfTotalSecond;

                    mScene.getProtocol().c2sAutoFire(mTurret.getScenePlayerInfo().et_player_rpcid, mQueBullet);
                }
            }
        }
Example #2
0
        //-------------------------------------------------------------------------
        public void update(float elapsed_tm)
        {
            CRenderLevel level = mScene.getLevel();

            if (level == null)
            {
                return;
            }

            mfTotalSecond += elapsed_tm;

            if (mScene.getMyPlayerId() == mPlayer.et_player_rpcid && !mScene.isSingleMode())
            {
                mfIdleSecond += elapsed_tm;
                if (mfIdleSecond > 60.0f)
                {
                    mfObCountdown -= elapsed_tm;
                    if (mfObCountdown <= 0.0f)
                    {
                        mfIdleSecond  = 0.0f;
                        mfObCountdown = 60.0f;
                        mScene.getListener().onScenePlayerChange2Ob();
                    }
                    else
                    {
                        string str = "由于您一分钟没有发射炮弹 系统将在[ff0000]" + ((int)mfObCountdown).ToString() + "秒[-]后进入[00ffff]观战模式[-]";
                        //mScene.getListener().onSceneShowMessageBox(str, false, "", 1, (int)_eMessageBoxLayer.Ob, false, false);
                    }
                }
                else
                {
                    mfObCountdown = 60.0f;
                }

                if (mRenderBufferMgr.hasBuffer("BufLongpress") || mRenderBufferMgr.hasBuffer("BufRapid"))
                {
                    mfIdleSecond  = 0.0f;
                    mfObCountdown = 60.0f;
                }
            }

            mCSpriteTurretShow.update(elapsed_tm);
            mRenderBufferMgr.update(elapsed_tm);
        }