本文整理汇总了Python中direct.showbase.RandomNumGen.RandomNumGen类的典型用法代码示例。如果您正苦于以下问题:Python RandomNumGen类的具体用法?Python RandomNumGen怎么用?Python RandomNumGen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RandomNumGen类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scheduleDrops
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
示例2: startSuitWalkTask
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.3,
2.1][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
示例3: generate
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
return
示例4: __init__
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
if not walkAnimName:
pass
self._walkAnimName = 'walk'
self.suit = Suit.Suit()
d = SuitDNA.SuitDNA()
d.newSuit(suitDnaName)
self.suit.setDNA(d)
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.59999999999999998 * self.cellWalkDuration
示例5: __init__
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
示例6: __init__
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)))
示例7: MazeSuit
class MazeSuit(DirectObject):
COLL_SPHERE_NAME = 'MazeSuitSphere'
COLLISION_EVENT_NAME = 'MazeSuitCollision'
MOVE_IVAL_NAME = 'moveMazeSuit'
DIR_UP = 0
DIR_DOWN = 1
DIR_LEFT = 2
DIR_RIGHT = 3
oppositeDirections = [
DIR_DOWN,
DIR_UP,
DIR_RIGHT,
DIR_LEFT]
directionHs = [
0,
180,
90,
270]
DEFAULT_SPEED = 4.0
SUIT_Z = 0.10000000000000001
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
if not walkAnimName:
pass
self._walkAnimName = 'walk'
self.suit = Suit.Suit()
d = SuitDNA.SuitDNA()
d.newSuit(suitDnaName)
self.suit.setDNA(d)
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.59999999999999998 * self.cellWalkDuration
def destroy(self):
self.suit.delete()
def uniqueName(self, str):
return str + `self.serialNum`
def gameStart(self, gameStartTime):
self.gameStartTime = gameStartTime
self.initCollisions()
self.startWalkAnim()
self.occupiedTiles = [
(self.nextTX, self.nextTY)]
n = 20
self.nextThinkTic = self.serialNum * self.ticFreq / n
self.fromPos = Point3(0, 0, 0)
self.toPos = Point3(0, 0, 0)
self.fromHpr = Point3(0, 0, 0)
self.toHpr = Point3(0, 0, 0)
self.moveIval = WaitInterval(1.0)
def gameEnd(self):
self.moveIval.pause()
del self.moveIval
self.shutdownCollisions()
self.suit.loop('neutral')
def initCollisions(self):
self.collSphere = CollisionSphere(0, 0, 0, 2.0)
self.collSphere.setTangible(0)
self.collNode = CollisionNode(self.uniqueName(self.COLL_SPHERE_NAME))
self.collNode.setIntoCollideMask(ToontownGlobals.WallBitmask)
self.collNode.addSolid(self.collSphere)
self.collNodePath = self.suit.attachNewNode(self.collNode)
self.collNodePath.hide()
self.accept(self.uniqueName('enter' + self.COLL_SPHERE_NAME), self.handleEnterSphere)
def shutdownCollisions(self):
self.ignore(self.uniqueName('enter' + self.COLL_SPHERE_NAME))
del self.collSphere
self.collNodePath.removeNode()
del self.collNodePath
del self.collNode
def handleEnterSphere(self, collEntry):
messenger.send(self.COLLISION_EVENT_NAME, [
#.........这里部分代码省略.........
示例8: ADBakery
class ADBakery(Bakery):
"""
A factory for tiles based on panda3d's perlin noise
"""
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)))
def hasTile(self, xStart, yStart, tileSize):
"""
If one is using a cashed tile source instead of a live bakery, this would be sometimes be false
"""
return True
def getTile(self, xStart, yStart, scale):
"""
returns a tile for the specified positions and size
"""
sizeY = tileMapSize
sizeX = tileMapSize
getHeight = self.getHeight
noiseTex=Texture("NoiseTex")
noiseTex.setup2dTexture(sizeX, sizeY, Texture.TUnsignedByte, Texture.FRgb)
p=noiseTex.modifyRamImage()
step=noiseTex.getNumComponents()*noiseTex.getComponentWidth()
scalar=.4
for y in range(sizeY):
yPos=scalar*(1.0*y*scale/(sizeY-1)+yStart)
for x in range(sizeX):
height = getHeight(scalar*(1.0*x*scale/(sizeX-1) + xStart), yPos)
r=min(255,max(0,height*256))
g=r*256
b=g*256
index = (sizeX * y + x)*step
p.setElement(index, b%256)#Blue
p.setElement(index+1, g%256)#Green
p.setElement(index+2, r)#Red
return Tile({"height":Map("height", noiseTex)},[], xStart, yStart, scale)
def asyncGetTile(self, xStart, yStart, scale, callback, callbackParams=[]):
"""
like getTile, but calls callback(tile,*callbackParams) when done
"""
callback(self.getTile(xStart, yStart, scale), *callbackParams)
def getHeight(self, x, y):
#.........这里部分代码省略.........
示例9: MazeAI
class MazeAI(DistributedObjectAI):
notify = directNotify.newCategory("MazeAI")
TurnChance = 75
ForkChance = 20
StopChance = 10
def __init__(self, air, gameId):
DistributedObjectAI.__init__(self, air)
self.gameId = gameId
self.xsize = 0
self.ysize = 0
self.numWalls = 0
self.map = None
self.root = None
self.prevPlayers = {}
def getSize(self):
return self.xsize, self.ysize
def getNumWalls(self):
return self.numWalls
def deleteMaze(self):
if self.map:
for row in self.map:
for cell in row:
self.air.zoneAllocator.free(cell.zoneId)
cell.requestDelete()
def generateMaze(self, xsize, ysize,
prevMaze = None, seed = None):
if seed is None:
seed = int(time.time())
self.random = RandomNumGen(seed)
# Delete the old maze, if any
self.deleteMaze()
self.xsize = xsize
self.ysize = ysize
self.map = []
for sy in range(self.ysize):
row = []
for sx in range(self.xsize):
zoneId = self.air.zoneAllocator.allocate()
cell = CellAI(self.air)
cell.setGeometry(Globals.AllDirs, sx, sy)
cell.generateWithRequired(zoneId)
row.append(cell)
self.map.append(row)
# Start by choosing a random square and a random direction.
self.numSquares = self.xsize * self.ysize - 1
self.paths = []
nextStep = self.__findEmptySquare()
self.paths.append(nextStep)
while self.numSquares > 0:
self.__generateMazeSteps()
# Count up the number of walls.
walls = []
for row in self.map:
for cell in row:
walls += cell.getWalls()
self.numWalls = len(walls)
random.shuffle(walls)
if prevMaze:
# Put our previous art paintings up on the walls,
# including any poster data.
for i in range(len(prevMaze.artPaintings)):
dir, name, color, posterData, imgData = prevMaze.artPaintings[i]
sx, sy, wallDir = walls[i]
cell = self.map[sy][sx]
while posterData[0] and cell.posterDir:
# We've already placed a poster in this cell. Go
# on to the next one.
del walls[i]
sx, sy, wallDir = walls[i]
cell = self.map[sy][sx]
if dir & Globals.AllDirs != 0:
# It's not a floor or ceiling, so use the wall we
# picked, instead of the wall it was on in the
# previous maze.
dir = wallDir
else:
# It is a floor or ceiling, so keep it there.
pass
cell.preloadPrevPainting(dir, posterData, imgData)
# Record the player's color so we can identify him
# when he comes back in and give him the points for
# this paint immediately.
#.........这里部分代码省略.........
示例10: generateMaze
def generateMaze(self, xsize, ysize,
prevMaze = None, seed = None):
if seed is None:
seed = int(time.time())
self.random = RandomNumGen(seed)
# Delete the old maze, if any
self.deleteMaze()
self.xsize = xsize
self.ysize = ysize
self.map = []
for sy in range(self.ysize):
row = []
for sx in range(self.xsize):
zoneId = self.air.zoneAllocator.allocate()
cell = CellAI(self.air)
cell.setGeometry(Globals.AllDirs, sx, sy)
cell.generateWithRequired(zoneId)
row.append(cell)
self.map.append(row)
# Start by choosing a random square and a random direction.
self.numSquares = self.xsize * self.ysize - 1
self.paths = []
nextStep = self.__findEmptySquare()
self.paths.append(nextStep)
while self.numSquares > 0:
self.__generateMazeSteps()
# Count up the number of walls.
walls = []
for row in self.map:
for cell in row:
walls += cell.getWalls()
self.numWalls = len(walls)
random.shuffle(walls)
if prevMaze:
# Put our previous art paintings up on the walls,
# including any poster data.
for i in range(len(prevMaze.artPaintings)):
dir, name, color, posterData, imgData = prevMaze.artPaintings[i]
sx, sy, wallDir = walls[i]
cell = self.map[sy][sx]
while posterData[0] and cell.posterDir:
# We've already placed a poster in this cell. Go
# on to the next one.
del walls[i]
sx, sy, wallDir = walls[i]
cell = self.map[sy][sx]
if dir & Globals.AllDirs != 0:
# It's not a floor or ceiling, so use the wall we
# picked, instead of the wall it was on in the
# previous maze.
dir = wallDir
else:
# It is a floor or ceiling, so keep it there.
pass
cell.preloadPrevPainting(dir, posterData, imgData)
# Record the player's color so we can identify him
# when he comes back in and give him the points for
# this paint immediately.
self.prevPlayers.setdefault(color, []).append((cell, dir))
## # Temp hack for debugging.
## painted = PNMImage()
## painted.read('paint.rgb')
## for sx, sy, dir in walls:
## cell = self.map[sy][sx]
## for dir in Globals.AllDirsList:
## if cell.bits & dir:
## cell.painted[dir] = PNMImage(painted)
self.drawMap()
self.determineVisibility()