Пример #1
0
    def startSuitWalkTask(self):
        ival = Parallel(name='catchGameMetaSuitWalk')
        rng = RandomNumGen(self.randomNumGen)
        delay = 0.0
        while delay < CatchGameGlobals.GameDuration:
            delay += lerp(self.SuitPeriodRange[0], self.SuitPeriodRange[0],
                          rng.random())
            walkIval = Sequence(name='catchGameSuitWalk')
            walkIval.append(Wait(delay))

            def pickY(self=self, rng=rng):
                return lerp(-(self.StageHalfHeight), self.StageHalfHeight,
                            rng.random())

            m = [2.5, 2.5, 2.2999999999999998,
                 2.1000000000000001][self.getNumPlayers() - 1]
            startPos = Point3(-(self.StageHalfWidth * m), pickY(), 0)
            stopPos = Point3(self.StageHalfWidth * m, pickY(), 0)
            if rng.choice([0, 1]):
                startPos = stopPos
                stopPos = startPos

            walkIval.append(self.getSuitWalkIval(startPos, stopPos, rng))
            ival.append(walkIval)
        ival.start()
        self.suitWalkIval = ival
Пример #2
0
    def scheduleDrops(self, genId = None):
        if genId is None:
            genId = self.getCurGeneration()
        gen = self._id2gen[genId]
        if gen.hasBeenScheduled:
            return
        fruitIndex = int((gen.startTime + 0.5 * self.DropPeriod) / PartyGlobals.CatchActivityDuration)
        fruitNames = ['apple',
         'orange',
         'pear',
         'coconut',
         'watermelon',
         'pineapple']
        fruitName = fruitNames[fruitIndex % len(fruitNames)]
        rng = RandomNumGen(genId + self._generationSeedBase)
        gen.droppedObjNames = [fruitName] * self.numFruits + ['anvil'] * self.numAnvils
        rng.shuffle(gen.droppedObjNames)
        dropPlacer = PartyRegionDropPlacer(self, gen.numPlayers, genId, gen.droppedObjNames, startTime=gen.startTime)
        gen.numItemsDropped = 0
        tIndex = gen.startTime % PartyGlobals.CatchActivityDuration
        tPercent = float(tIndex) / PartyGlobals.CatchActivityDuration
        gen.numItemsDropped += dropPlacer.skipPercent(tPercent)
        while not dropPlacer.doneDropping(continuous=True):
            nextDrop = dropPlacer.getNextDrop()
            gen.dropSchedule.append(nextDrop)

        gen.hasBeenScheduled = True
        return
Пример #3
0
 def __init__(self, serialNum, maze, randomNumGen, cellWalkPeriod, difficulty, suitDnaName = 'f', startTile = None, ticFreq = MazeGameGlobals.SUIT_TIC_FREQ, walkSameDirectionProb = MazeGameGlobals.WALK_SAME_DIRECTION_PROB, walkTurnAroundProb = MazeGameGlobals.WALK_TURN_AROUND_PROB, uniqueRandomNumGen = True, walkAnimName = None):
     self.serialNum = serialNum
     self.maze = maze
     if uniqueRandomNumGen:
         self.rng = RandomNumGen(randomNumGen)
     else:
         self.rng = randomNumGen
     self.difficulty = difficulty
     self._walkSameDirectionProb = walkSameDirectionProb
     self._walkTurnAroundProb = walkTurnAroundProb
     self._walkAnimName = walkAnimName or 'walk'
     self.suit = Suit.Suit()
     d = SuitDNA.SuitDNA()
     d.newSuit(suitDnaName)
     self.suit.setDNA(d)
     self.suit.nametag.setNametag2d(None)
     self.suit.nametag.setNametag3d(None)
     if startTile is None:
         defaultStartPos = MazeGameGlobals.SUIT_START_POSITIONS[self.serialNum]
         self.startTile = (defaultStartPos[0] * self.maze.width, defaultStartPos[1] * self.maze.height)
     else:
         self.startTile = startTile
     self.ticFreq = ticFreq
     self.ticPeriod = int(cellWalkPeriod)
     self.cellWalkDuration = float(self.ticPeriod) / float(self.ticFreq)
     self.turnDuration = 0.6 * self.cellWalkDuration
     return
Пример #4
0
 def __init__(self, randomNumGen, width, height, frameWallThickness=Globals.FrameWallThickness, cogdoMazeData=CogdoMazeData):
     self._rng = RandomNumGen(randomNumGen)
     self.width = width
     self.height = height
     self.frameWallThickness = frameWallThickness
     self._cogdoMazeData = cogdoMazeData
     self.quadrantSize = self._cogdoMazeData.QuadrantSize
     self.cellWidth = self._cogdoMazeData.QuadrantCellWidth
Пример #5
0
 def __init__(self, parent, quadLengthUnits, quadVisibilityAhead, quadVisibiltyBehind, rng = None):
     self.parent = parent
     self.quadLengthUnits = quadLengthUnits
     self.quadVisibiltyAhead = quadVisibilityAhead
     self.quadVisibiltyBehind = quadVisibiltyBehind
     self._rng = rng or RandomNumGen(1)
     self._level = None
     return
Пример #6
0
 def __init__(self, maze, exit, rng):
     CogdoGameMovie.__init__(self)
     self._maze = maze
     self._exit = exit
     self._rng = RandomNumGen(rng)
     self._camTarget = None
     self._state = 0
     self._suits = []
    def createRandomSpotsList(self, numSpots, randomNumGen):
        randomNumGen = RandomNumGen(randomNumGen)
        width = self.width
        height = self.height
        halfWidth = int(width / 2)
        halfHeight = int(height / 2)
        quadrants = [(0,
          0,
          halfWidth - 1,
          halfHeight - 1),
         (halfWidth,
          0,
          width - 1,
          halfHeight - 1),
         (0,
          halfHeight,
          halfWidth - 1,
          height - 1),
         (halfWidth,
          halfHeight,
          width - 1,
          height - 1)]
        spotsTaken = []

        def getEmptySpotInQuadrant(quadrant):
            tX = -1
            tY = -1
            while tX < 0 or not self.isWalkable(tX, tY, spotsTaken):
                tX = randomNumGen.randint(quadrant[0], quadrant[2])
                tY = randomNumGen.randint(quadrant[1], quadrant[3])

            spot = (tX, tY)
            spotsTaken.append(spot)
            return spot

        def getSpotList(length):
            randomNumGen.shuffle(quadrants)
            l = []
            remaining = length
            for quadrant in quadrants:
                for u in xrange(int(length / 4)):
                    l.append(getEmptySpotInQuadrant(quadrant))

                remaining -= int(length / 4)

            for u in xrange(remaining):
                quadrant = quadrants[randomNumGen.randint(0, len(quadrants) - 1)]
                l.append(getEmptySpotInQuadrant(quadrant))

            return l

        if type(numSpots) == tuple or type(numSpots) == list:
            spots = []
            for i in numSpots:
                spots.append(getSpotList(i))

            return spots
        return getSpotList(numSpots)
Пример #8
0
 def generate(self):
     DistributedPartyActivity.generate(self)
     self.notify.info('localAvatar doId: %s' % base.localAvatar.doId)
     self.notify.info('generate()')
     self._generateFrame = globalClock.getFrameCount()
     self._id2gen = {}
     self._orderedGenerations = []
     self._orderedGenerationIndex = None
     rng = RandomNumGen(self.doId)
     self._generationSeedBase = rng.randrange(1000)
     self._lastDropTime = 0.0
Пример #9
0
    def __init__(self, editorFile, bakeryFolder):
        #id is a seed for the map and unique name for any cached heightmap images

        self.dice = RandomNumGen(TimeVal().getUsec())
        self.id = self.dice.randint(2, 1000000)

        # the overall smoothness/roughness of the terrain
        smoothness = 80
        # how quickly altitude and roughness shift
        self.consistency = smoothness * 8
        # waterHeight is expressed as a multiplier to the max height
        self.waterHeight = 0.3
        # for realism the flatHeight should be at or very close to waterHeight
        self.flatHeight = self.waterHeight + 0.04

        #creates noise objects that will be used by the getHeight function
        """Create perlin noise."""

        # See getHeight() for more details....

        # where perlin 1 is low terrain will be mostly low and flat
        # where it is high terrain will be higher and slopes will be exagerrated
        # increase perlin1 to create larger areas of geographic consistency
        self.perlin1 = StackedPerlinNoise2()
        perlin1a = PerlinNoise2(0, 0, 256, seed=self.id)
        perlin1a.setScale(self.consistency)
        self.perlin1.addLevel(perlin1a)
        perlin1b = PerlinNoise2(0, 0, 256, seed=self.id * 2 + 123)
        perlin1b.setScale(self.consistency / 2)
        self.perlin1.addLevel(perlin1b, 1 / 2)


        # perlin2 creates the noticeable noise in the terrain
        # without perlin2 everything would look unnaturally smooth and regular
        # increase perlin2 to make the terrain smoother
        self.perlin2 = StackedPerlinNoise2()
        frequencySpread = 3.0
        amplitudeSpread = 3.4
        perlin2a = PerlinNoise2(0, 0, 256, seed=self.id * 2)
        perlin2a.setScale(smoothness)
        self.perlin2.addLevel(perlin2a)
        perlin2b = PerlinNoise2(0, 0, 256, seed=self.id * 3 + 3)
        perlin2b.setScale(smoothness / frequencySpread)
        self.perlin2.addLevel(perlin2b, 1 / amplitudeSpread)
        perlin2c = PerlinNoise2(0, 0, 256, seed=self.id * 4 + 4)
        perlin2c.setScale(smoothness / (frequencySpread * frequencySpread))
        self.perlin2.addLevel(perlin2c, 1 / (amplitudeSpread * amplitudeSpread))
        perlin2d = PerlinNoise2(0, 0, 256, seed=self.id * 5 + 5)
        perlin2d.setScale(smoothness / (math.pow(frequencySpread, 3)))
        self.perlin2.addLevel(perlin2d, 1 / (math.pow(amplitudeSpread, 3)))
        perlin2e = PerlinNoise2(0, 0, 256, seed=self.id * 6 + 6)
        perlin2e.setScale(smoothness / (math.pow(frequencySpread, 4)))
        self.perlin2.addLevel(perlin2e, 1 / (math.pow(amplitudeSpread, 4)))
Пример #10
0
 def create_pid(self):
     """
     Create a new PID
     @return: a new, unique PID
     @rtype: int
     """
     pid = None
     while not pid:
         temp_pid = RandomNumGen(int(round(time.time() * 1000))).randint(
             0, 65535)
         if temp_pid not in self.active_connections:
             pid = temp_pid
     return pid
Пример #11
0
 def load(self):
     self.accept(self.distGame.getRemoteActionEventName(),
                 self.handleRemoteAction)
     self.audioMgr = CogdoGameAudioManager(Globals.Audio.MusicFiles,
                                           Globals.Audio.SfxFiles,
                                           base.localAvatar,
                                           cutoff=Globals.Audio.Cutoff)
     factory = CogdoFlyingLevelFactory(render,
                                       Globals.Level.QuadLengthUnits,
                                       Globals.Level.QuadVisibilityAhead,
                                       Globals.Level.QuadVisibilityBehind,
                                       rng=RandomNumGen(self.distGame.doId))
     self.level = factory.createLevel(self.distGame.getSafezoneId())
     self.level.setCamera(camera)
     self.guiMgr = CogdoFlyingGuiManager(self.level)
     self.levelFog = factory.createLevelFog()
     self._initLegalEagles()
Пример #12
0
    def create_game(self, pid):
        """
        Creates a game for the PID given
        @param pid: PID of player wanting to join a game
        @type pid: int
        @return: if successful
        @rtype: bool
        """
        gid = RandomNumGen(int(round(time.time() * 1000))).randint(0, 65535)

        self.notify.debug(f"[create_game] Create game {gid} for player {pid}")

        # create game
        game = Game(gid, self)
        self.games[gid] = game

        self.add_player_to_game(pid, game.gid)

        return True
Пример #13
0
 def _createRng(self):
     self.rng = RandomNumGen(self.generationId + self.game.doId)
    def load(self, cogdoMazeFactory, numSuits, bossCode):
        self._initAudio()
        self.maze = cogdoMazeFactory.createCogdoMaze()
        suitSpawnSpot = self.maze.createRandomSpotsList(numSuits, self.distGame.randomNumGen)
        self.guiMgr = CogdoMazeGuiManager(self.maze, bossCode)
        self.suits = []
        self.suitsById = {}
        self.shakers = []
        self.toonsThatRevealedDoor = []
        self.quake = 0
        self.dropCounter = 0
        self.drops = {}
        self.gagCounter = 0
        self.gags = []
        self.hackTemp = False
        self.dropGen = RandomNumGen(self.distGame.doId)
        self.gagTimeoutTasks = []
        self.finished = False
        self.lastBalloonTimestamp = None
        difficulty = self.distGame.getDifficulty()
        serialNum = 0
        for i in range(numSuits[0]):
            suitRng = RandomNumGen(self.distGame.doId + serialNum * 10)
            suit = CogdoMazeBossSuit(serialNum, self.maze, suitRng, difficulty, startTile=suitSpawnSpot[0][i])
            self.addSuit(suit)
            self.guiMgr.mazeMapGui.addSuit(suit.suit)
            serialNum += 1

        for i in range(numSuits[1]):
            suitRng = RandomNumGen(self.distGame.doId + serialNum * 10)
            suit = CogdoMazeFastMinionSuit(serialNum, self.maze, suitRng, difficulty, startTile=suitSpawnSpot[1][i])
            self.addSuit(suit)
            serialNum += 1

        for i in range(numSuits[2]):
            suitRng = RandomNumGen(self.distGame.doId + serialNum * 10)
            suit = CogdoMazeSlowMinionSuit(serialNum, self.maze, suitRng, difficulty, startTile=suitSpawnSpot[2][i])
            self.addSuit(suit)
            serialNum += 1

        self.toonId2Door = {}
        self.keyIdToKey = {}
        self.players = []
        self.toonId2Player = {}
        cellPos = (int(self.maze.width / 2), self.maze.height - 1)
        pos = self.maze.tile2world(*cellPos)
        self._exit = CogdoMazeExit()
        self._exit.reparentTo(render)
        self._exit.setPos(self.maze.exitPos)
        self._exit.stash()
        self.guiMgr.mazeMapGui.placeExit(*cellPos)
        self._collNode2waterCooler = {}
        for waterCooler in self.maze.getWaterCoolers():
            pos = waterCooler.getPos(render)
            tpos = self.maze.world2tile(pos[0], pos[1])
            self.guiMgr.mazeMapGui.addWaterCooler(*tpos)
            self._collNode2waterCooler[waterCooler.collNode] = waterCooler

        self.pickups = []
        self.gagModel = CogdoUtil.loadMazeModel('waterBalloon')
        self._movie = CogdoMazeGameIntro(self.maze, self._exit, self.distGame.randomNumGen)
        self._movie.load()
        return
Пример #15
0
 def __init__(self, level, rng):
     CogdoGameMovie.__init__(self)
     self._level = level
     self._rng = RandomNumGen(rng)
     self._exit = self._level.getExit()
Пример #16
0
 def startIntro(self):
     self._movie = CogdoFlyingGameIntro(self.level, RandomNumGen(self.distGame.doId))
     self._movie.load()
     self._movie.play()
     self.audioMgr.playMusic('normal')
 def createRandomNumGen(self):
     return RandomNumGen(self.doId)
Пример #18
0
 def randomColor(self):
     rand = RandomNumGen(globalClock.getFrameTime())
     self.panda.setColorScale(rand.random(), rand.random(), rand.random(),
                              1)
Пример #19
0
 def announceGenerate(self):
     DistributedNPCToonBase.announceGenerate(self)
     self.rng = RandomNumGen(self.doId)
     self.setHat(59, 0, 0)
     if self.style.gender == 'm':
         self.setGlasses(22, 0, 0)