コード例 #1
0
    def genFishs(self):
        self.genFishDatas = []
        centerNLevelNRadius = []
        for area in self.init_areas:
            centerP, direct, endP = area.initArea.getPointNDirect()
            count = len(area.fishLevels)
            levelNedges = []
            for i in xrange(count):
                space = self.space
                level = random.choice(area.fishLevels[i])
                levelData = FISH_LEVELS_DATA[level]
                if i == count - 1:
                    centerP = centerP + (-direct) * (levelData.width/2.0)
                    levelNedges.append((level, centerP))
                else:
                    width = levelData.width
                    if i == count - 2:
                        width = width/4.0
                        space = self.space * 2
                    elif i == 0:
                        space = self.space
                    else:
                        space = self.space / 2
                    centerP = centerP + (-direct) * (width/2.0)
                    levelNedges.append((level, centerP))
                    centerP = centerP + (-direct) * (width/2.0 + space)
            levelNRadius = []
            for level, edgeP in levelNedges:
                levelNRadius.append((level, centerP.getDist(edgeP)))
            centerNLevelNRadius.append((centerP, levelNRadius))

        longestDuration = 0
        for idx, area in enumerate(self.init_areas):
            centerP, levelNRadius = centerNLevelNRadius[idx]
            initP, direct, endP = area.initArea.getPointNDirect()
            #获取初始角度
            rad = direct.toRadian()
            initRot = math.degrees(rad)
            for i in xrange(len(levelNRadius)):
                level, radius = levelNRadius[i]
                deltaAngle = (math.pi*2)/area.counts[i]
                levelData = FISH_LEVELS_DATA[level]
                for i in xrange(area.counts[i]):
                    offsetDir = direct.rotateSelfByRadian(deltaAngle*i).normalize()
                    startP = centerP + (offsetDir*radius)
                    curEndP = Point(endP.x, startP.y) + direct * (levelData.width/2.0)
                    duration = curEndP.getDist(startP)/area.speed
                    #优化,把初始化位置都设到屏幕外半个身位
                    realStartP = Point(initP.x, startP.y) + (-direct) * (levelData.width/2.0)
                    realDuration = curEndP.getDist(realStartP)/area.speed
                    if duration > longestDuration:
                        longestDuration = duration
                    self.genFishDatas.append(fish_array.FishInitData(0, level, levelData.order, initRot, \
                        realStartP.x, realStartP.y, realDuration, levelData.getMulti(), levelData.getPickedRate(), 0, \
                        pbAppendRoute([], 0, area.speed, realDuration + TOLERATE_LAG_SECS), \
                        fish_array.FISH_ARRAY_APPEAR_TICK + (duration - realDuration)*1000))

        self.duration = longestDuration + TOLERATE_LAG_SECS
        super(FishArray, self).genFishs()
コード例 #2
0
    def genFishs(self):
        self.genFishDatas = []
        centerLevelNPoints = [None] * len(self.initDatas)
        initP, direct, endP = self.initArea.getPointNDirect()
        centerP = initP * 1.0
        initData = self.initDatas[0]
        #获取初始角度
        rad = direct.toRadian()
        initRot = math.degrees(rad)
        level = random.choice(initData.fishLevels)
        levelData = FISH_LEVELS_DATA[level]
        centerP = centerP + (-direct) * (levelData.width / 2.0 +
                                         initData.radius)
        centerLevelNPoints[0] = (level, centerP)
        centerP = centerP + (-direct) * (levelData.width / 2.0 +
                                         initData.radius)
        initData = self.initDatas[1]
        level = random.choice(initData.fishLevels)
        centerLevelNPoints[1] = (level, centerP)
        initData = self.initDatas[3]
        level = random.choice(initData.fishLevels)
        centerLevelNPoints[3] = (level, centerP)
        initData = self.initDatas[2]
        level = random.choice(initData.fishLevels)
        levelData = FISH_LEVELS_DATA[level]
        centerP = centerP + (-direct) * (levelData.width / 2.0 +
                                         initData.radius)
        centerLevelNPoints[2] = (level, centerP)

        #外环大鱼
        fishLevelAmbient = random.choice([20, 21])
        levelDataAmbient = FISH_LEVELS_DATA[fishLevelAmbient]

        longestDuration = 0
        endIdx = len(self.initDatas) - 1
        for idx, initData in enumerate(self.initDatas):
            level, centerP = centerLevelNPoints[idx]
            deltaAngle = (math.pi * 2) / initData.count
            levelData = FISH_LEVELS_DATA[level]
            offsetRad = math.radians(initData.offsetAngle)
            for i in xrange(initData.count):
                offsetDir = direct.rotateSelfByRadian(offsetRad + deltaAngle *
                                                      i).normalize()
                startP = centerP + (offsetDir * initData.radius)
                curEndP = Point(endP.x,
                                startP.y) + direct * (levelData.width / 2.0)
                duration = curEndP.getDist(startP) / initData.speed
                #优化,把初始化位置都设到屏幕外半个身位
                realStartP = Point(
                    initP.x, startP.y) + (-direct) * (levelData.width / 2.0)
                realDuration = curEndP.getDist(realStartP) / initData.speed
                if duration > longestDuration:
                    longestDuration = duration
                self.genFishDatas.append(fish_array.FishInitData(0, level, levelData.order, initRot, \
                    realStartP.x, realStartP.y, realDuration, levelData.getMulti(), levelData.getPickedRate(), 0, \
                    pbAppendRoute([], 0, initData.speed, realDuration + TOLERATE_LAG_SECS), \
                    fish_array.FISH_ARRAY_APPEAR_TICK + (duration - realDuration)*1000))
                if idx == endIdx:
                    if i in (1, 2):
                        offsetDir = -direct
                    else:
                        offsetDir = direct
                    startP = startP + (offsetDir * self.offsetInOut)
                    curEndP = Point(
                        endP.x,
                        startP.y) + direct * (levelDataAmbient.width / 2.0)
                    duration = curEndP.getDist(startP) / initData.speed
                    #优化,把初始化位置都设到屏幕外半个身位
                    realStartP = Point(
                        initP.x,
                        startP.y) + (-direct) * (levelData.width / 2.0)
                    realDuration = curEndP.getDist(realStartP) / initData.speed
                    if duration > longestDuration:
                        longestDuration = duration
                    self.genFishDatas.append(fish_array.FishInitData(0, fishLevelAmbient, levelDataAmbient.order, initRot, \
                        realStartP.x, realStartP.y, realDuration, levelDataAmbient.getMulti(), levelDataAmbient.getPickedRate(), 0, \
                        pbAppendRoute([], 0, initData.speed, realDuration + TOLERATE_LAG_SECS), \
                        fish_array.FISH_ARRAY_APPEAR_TICK + (duration - realDuration)*1000))

        self.duration = longestDuration + TOLERATE_LAG_SECS
        super(FishArray, self).genFishs()