示例#1
0
        //-------------------------------------------------------------------------
        public void create(int turret_id, ref _tScenePlayer scene_player, int player_gold,
                           bool buffer_power, bool buffer_freeze, bool buffer_longpress, bool buffer_rapid, int turret_rate, float turret_angle, int locked_fish_objid
                           , TbDataTurret.TurretType turret_type)
        {
            mTurretId    = turret_id;
            mPlayer      = scene_player;
            mTurretAngle = turret_angle;

            mTurretType      = turret_type;
            mTurretDataTable = new TurretDataTable();

            _setTurretRate(turret_rate);

            CTurretHelper turret_helper = mScene.getTurretHelper();

            mTurretPos = turret_helper.getPositionByOffset(turret_id,
                                                           mScene.getRenderConfigure().TurretOffset);
            mBaseAngle   = turret_helper.getBaseAngleByTurretId(turret_id);
            mTurretColor = turret_helper.getBaseColorByTurretId(turret_id).convert();

            float scene_length = mScene.getSceneLength();
            float scene_width  = mScene.getSceneWidth();

            mCSpriteTurretShow = new CSpriteTurretShow();
            mCSpriteTurretShow.create(mScene, this);

            _displayTurretRate();

            mRenderBufferMgr = new CRenderBufferMgr(mScene, this,
                                                    turret_helper.getPositionByOffset(turret_id, mScene.getRenderConfigure().TurretBufferOffset), mBaseAngle);
            setLockFishByFishObjId(locked_fish_objid);

            if (buffer_power)
            {
                List <object> param_list = new List <object>();
                mRenderBufferMgr.addBuffer("BufPower", param_list);
            }

            if (buffer_freeze)
            {
                List <object> param_list = new List <object>();
                mRenderBufferMgr.addBuffer("BufFreeze", param_list);
            }

            if (buffer_longpress)
            {
                List <object> param_list = new List <object>();
                mRenderBufferMgr.addBuffer("BufLongpress", param_list);
            }

            if (buffer_rapid)
            {
                List <object> param_list = new List <object>();
                mRenderBufferMgr.addBuffer("BufRapid", param_list);
            }

            mScene.getListener().onSceneTurretCreated(mTurretId);
        }
        //-------------------------------------------------------------------------
        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);
                }
            }
        }