本文整理汇总了Python中direct.gui.DirectGui.DirectWaitBar.reparentTo方法的典型用法代码示例。如果您正苦于以下问题:Python DirectWaitBar.reparentTo方法的具体用法?Python DirectWaitBar.reparentTo怎么用?Python DirectWaitBar.reparentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类direct.gui.DirectGui.DirectWaitBar
的用法示例。
在下文中一共展示了DirectWaitBar.reparentTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoadingScreen
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
class LoadingScreen():
def __init__(self):
# a fill panel so the player doesn't see how everything
# gets loaded in the background
self.frameMain = DirectFrame(
# size of the frame
frameSize = (base.a2dLeft, base.a2dRight,
base.a2dTop, base.a2dBottom),
image = "Logo.png",
image_scale = (0.612/2.0, 1, 0.495/2.0),
image_pos = (0, 0, 0.7),
# tramsparent bg color
frameColor = (0, 0, 0, 1))
self.frameMain.setTransparency(1)
# the text Loading... on top
self.lblLoading = DirectLabel(
scale = 0.25,
pos = (0, 0, 0),
frameColor = (0, 0, 0, 0),
text = _("Loading..."),
text_align = TextNode.ACenter,
text_fg = (1,1,1,1))
self.lblLoading.reparentTo(self.frameMain)
# the waitbar on the bottom
self.wbLoading = DirectWaitBar(
text = "0%",
text_fg = (1,1,1,1),
value = 0,
pos = (0, 0, -0.5),
barColor = (0.5, 0.4, 0.1, 1),
frameColor = (0.1, 0.1, 0.1, 1))
self.wbLoading.reparentTo(self.frameMain)
def show(self):
self.frameMain.show()
# and render two frames so the loading screen
# is realy shown on screen
base.graphicsEngine.renderFrame()
base.graphicsEngine.renderFrame()
def hide(self):
self.frameMain.hide()
def setLoadingValue(self, value):
"""Set the waitbar value to the given value, where
value has to be a integer from 0 to 100"""
if value > 100: value = 100
if value < 0: value = 0
self.wbLoading["value"] = value
self.wbLoading["text"] = "{0}%".format(value)
base.graphicsEngine.renderFrame()
base.graphicsEngine.renderFrame()
示例2: GyroApp
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
class GyroApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.graphics = Graphics()
self.environment = Environment()
self.physics = Physics()
#self.level = testlevels.SimpleBridge()
#self.level = testlevels.ObstacleWall()
self.level = testlevels.Staircase()
self.level.enable_physics(self.physics)
self.player = Player(self.level)
self.player.model.setPos(-10, 0, 1)
self.player.enable_physics(self.physics)
self.graphics.camera_target = self.player
self.environment.spotlight_target = self.player.model
self.health_bar = DirectWaitBar(pos = (0, 0, -0.9), scale = 0.5,
frameColor = Vec4(0.3, 0.3, 0.3, 0.8),
relief = 5, borderWidth = (0.05,0.05))
self.health_bar.reparentTo(aspect2d)
self.max_health = self.player.health
taskMgr.add(self.update_health, "UpdateHealthTask")
self.accept("escape", self.reset)
def update_health(self, task):
value = self.player.health / self.max_health
self.health_bar['value'] = 100 * value
self.health_bar['barColor'] = Vec4(1 - value, value, 0, 0.8)
return task.cont
def reset(self):
self.player.reset()
self.level.reset()
示例3: __init__
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
def __init__(self):
#create Queue to hold the incoming chat
#request the heartbeat so that the caht interface is being refreshed in order to get the message from other player
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0, "charge":0}
base.win.setClearColor(Vec4(0,0,0,1))
self.cManager = ConnectionManager()
self.cManager.startConnection()
#------------------------------
#Chat
Chat(self.cManager)
#send dummy login info of the particular client
#send first chat info
#---------------------------------------
self.userName = username
dummy_login ={'user_id' : self.userName, 'factionId': faction, 'password': '1234'}
self.cManager.sendRequest(Constants.RAND_STRING, dummy_login)
chat = { 'userName' : self.userName, #username
'message' : '-------Login------' }
self.cManager.sendRequest(Constants.CMSG_CHAT, chat)
#--------------------------------------
#self.minimap = OnscreenImage(image="images/minimap.png", scale=(0.2,1,0.2), pos=(-1.1,0,0.8))
#frame = DirectFrame(text="Resource Bar", scale=0.001)
resource_bar = DirectWaitBar(text="",
value=35, range=100, pos=(0,0,0.9), barColor=(255,255,0,1),
frameSize=(-0.3,0.3,0,0.03))
cp_bar = DirectWaitBar(text="",
value=70, range=100, pos=(1.0,0,0.9), barColor=(0,0,255,1),
frameSize=(-0.3,0.3,0,0.03), frameColor=(255,0,0,1))
# Set up the environment
#
# This environment model contains collision meshes. If you look
# in the egg file, you will see the following:
#
# <Collide> { Polyset keep descend }
#
# This tag causes the following mesh to be converted to a collision
# mesh -- a mesh which is optimized for collision, not rendering.
# It also keeps the original mesh, so there are now two copies ---
# one optimized for rendering, one for collisions.
self.environ = loader.loadModel("models/world")
self.environ.reparentTo(render)
self.environ.setPos(0,0,0)
# Create the main character, Ralph
ralphStartPos = self.environ.find("**/start_point").getPos()
self.ralph = Actor("models/ralph",
{"run":"models/ralph-run",
"walk":"models/ralph-walk"})
self.ralph.reparentTo(render)
self.ralph.setScale(.2)
self.ralph.setPos(ralphStartPos)
nameplate = TextNode('textNode username_' + str(self.userName))
nameplate.setText(self.userName)
npNodePath = self.ralph.attachNewNode(nameplate)
npNodePath.setScale(0.8)
npNodePath.setBillboardPointEye()
#npNodePath.setPos(1.0,0,6.0)
npNodePath.setZ(6.5)
bar = DirectWaitBar(value=100, scale=1.0)
bar.setColor(255,0,0)
#bar.setBarRelief()
bar.setZ(6.0)
bar.setBillboardPointEye()
bar.reparentTo(self.ralph)
# Create a floater object. We use the "floater" as a temporary
# variable in a variety of calculations.
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Accept the control keys for movement and rotation
self.accept("escape", sys.exit)
self.accept("arrow_left", self.setKey, ["left",1])
self.accept("arrow_right", self.setKey, ["right",1])
self.accept("arrow_up", self.setKey, ["forward",1])
self.accept("a", self.setKey, ["cam-left",1])
self.accept("s", self.setKey, ["cam-right",1])
self.accept("arrow_left-up", self.setKey, ["left",0])
self.accept("arrow_right-up", self.setKey, ["right",0])
self.accept("arrow_up-up", self.setKey, ["forward",0])
self.accept("a-up", self.setKey, ["cam-left",0])
self.accept("s-up", self.setKey, ["cam-right",0])
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
class CIProgressScreen:
def __init__(self):
self.bgm = loader.loadModel('phase_3/models/gui/progress-background.bam')
self.bgm.find('**/logo').stash()
self.bg = self.bgm.find('**/bg')
self.logo = loader.loadTexture('phase_3/maps/CogInvasion_Logo.png')
self.logoImg = OnscreenImage(image=self.logo, scale=(0.5, 0, 0.3), pos=(0, 0, 0), parent=hidden)
self.logoImg.setTransparency(True)
self.bg_img = OnscreenImage(image=self.bg, parent=hidden)
self.bg_img.setSx(1.35)
self.bg_img.hide()
self.progress_bar = DirectWaitBar(value=0, pos=(0, 0, -0.85), parent=hidden, text_pos=(0, 0, 0.2))
self.progress_bar.setSx(1.064)
self.progress_bar.setSz(0.38)
self.loading_lbl = DirectLabel(text='', relief=None, scale=0.08, pos=(-1.0725, 0, -0.79), text_align=TextNode.ALeft, sortOrder=100, text_fg=(0.343, 0.343, 0.343, 1.0), text_font=CIGlobals.getMinnieFont(), parent=hidden, text_shadow=(0, 0, 0, 1))
return
def begin(self, hood, range, wantGui):
render.hide()
self.renderFrames()
base.setBackgroundColor(0, 0, 0)
if hood == 'localAvatarEnterGame':
self.loading_lbl['text'] = 'Entering...'
elif hood == 'init':
self.loading_lbl['text'] = 'Loading...'
else:
self.loading_lbl['text'] = 'Heading to %s...' % hood
self.progress_bar['barColor'] = (0.343, 0.343, 0.343, 1.0)
self.progress_bar['range'] = range
self.bgm.reparentTo(aspect2d)
self.bg.reparentTo(render2d)
self.bg_img.reparentTo(hidden)
self.loading_lbl.reparentTo(aspect2d)
self.logoImg.reparentTo(aspect2d)
self.progress_bar.reparentTo(aspect2d)
self.__count = 0
self.__expectedCount = range
self.progress_bar.update(self.__count)
def renderFramesTask(self, task):
self.renderFrames()
return task.cont
def end(self):
base.setBackgroundColor(CIGlobals.DefaultBackgroundColor)
taskMgr.remove('renderFrames')
render.show()
self.progress_bar.finish()
self.bg_img.reparentTo(hidden)
self.logoImg.reparentTo(hidden)
self.bg.reparentTo(hidden)
self.bgm.reparentTo(hidden)
self.loading_lbl.reparentTo(hidden)
self.progress_bar.reparentTo(hidden)
self.renderFrames()
def destroy(self):
self.bg.removeNode()
del self.bg
self.bgm.removeNode()
del self.bgm
self.bg_img.destroy()
self.loading_lbl.destroy()
self.progress_bar.destroy()
self.bgm.destroy()
del self.bg_img
del self.loading_lbl
del self.progress_bar
del self.bgm
def renderFrames(self):
base.graphicsEngine.renderFrame()
base.graphicsEngine.renderFrame()
def tick(self):
self.__count += 1
self.progress_bar.update(self.__count)
示例5: Enemy
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
class Enemy(DirectObject):
def __init__(self, _main):
self.main = _main
self.strenght = self.main.enemyStrength
self.id = id(self)
self.model = loader.loadModel("Enemy")
self.model.setP(-90)
self.model.setH(180)
self.model.hide()
cs = CollisionSphere(0, 0, 0, 0.5)
cnode = CollisionNode('colEnemy' + str(self.id))
cnode.addSolid(cs)
self.colNP = self.model.attachNewNode(cnode)
#self.colNP.show()
# Game state
self.health = 100 + (100 * self.strenght)
self.damageDone = 0.1 + (0.1 * self.strenght)
self.lastShot = 0.0
self.attackRate = 10.0
self.statusHealth = DirectWaitBar(
text = "",
value = self.health,
range = self.health,
frameSize = (0.12, 0.8, -0.12, 0.0),
pos = (-0.5, 0, -0.5),
barColor = (1, 0, 0, 1))
self.statusHealth.reparentTo(self.model)
self.statusHealth.setDepthWrite(False)
self.statusHealth.setBin('fixed', 0)
self.statusHealth.setBillboardAxis()
def start(self, startPos, enemyParent):
self.model.show()
self.model.reparentTo(enemyParent)
self.model.setPos(startPos.x,
startPos.y,
0)
self.accept("into-" + "colEnemy" + str(self.id), self.hit)
self.accept("inRange-" + "colEnemy" + str(self.id), self.startAttack)
self.statusHealth.update(self.health)
def stop(self):
self.model.remove_node()
self.ignore("into-" + "colEnemy" + str(self.id))
self.ignore("inRange-" + "colEnemy" + str(self.id))
def hit(self, _dmg):
if self.health == 0:
base.messenger.send("killEnemy", [self.id])
else:
self.health -= _dmg
self.statusHealth.update(self.health)
def makeAi(self):
# Make some ai character for each
self.aiChar = AICharacter("Enemy" + str(self.id), self.model, -100, 0.05 + (0.05 * self.strenght), 6 + (1 * self.strenght))
self.main.AiWorld.addAiChar(self.aiChar)
self.AIbehaviors = self.aiChar.getAiBehaviors()
self.AIbehaviors.pursue(self.main.player.model)
return self.aiChar
def startAttack(self, _inRange=False):
if _inRange:
self.isAttacking = True
self.simpleAttack()
#taskMgr.remove("StartAttack")
#elif _inRange:
# pass
# taskMgr.add(self.attack, "StartAttack")
def attack(self, task):
dt = globalClock.getDt()
self.lastShot += dt
if self.lastShot >= self.attackRate:
self.lastShot -= self.attackRate
base.messenger.send("doDamageToPlayer", [self.damageDone])
return task.again
def simpleAttack(self):
base.messenger.send("doDamageToPlayer", [self.damageDone])
示例6: Enemy
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
class Enemy(DirectObject):
def __init__(self, parent, startingBlock, map, model):
self.map = map # The map itself - needed for finding the path
self.startingBlock = startingBlock # The block the enemy is traveling to
self.direction = 0 # The direction the enemy is traveling (Right = 0, Down = 1, Left = 2, Up = 3)
self.maxHealth = self.health # The starting health of the enemy
self.maxMoveSpeed = 1 # How many seconds it takes the enemy to move from one block to another
self.moveSpeed = self.maxMoveSpeed # The current movespeed
self.isActive = 1 # Whether the enemy is alive and moving
self.index = -1 # The index of the enemy
self.distanceTravelled = 0
# Load and place the model
self.eNode = parent.attachNewNode('enemyBaseNode')
self.eNode.setPos( startingBlock.getPos() )
self.model = loader.loadModel( 'models/' + model )
self.model.reparentTo( self.eNode )
# Setup the rest of what the enemy needs
self.setupCollision()
self.setupHealthBar()
def move(self, task):
dist = self.moveSpeed * globalClock.getDt()
deltaPos = DIRECTION_TO_VECTOR[self.direction] * dist
self.eNode.setPos( self.eNode.getPos() + deltaPos )
self.distanceTravelled += dist
if( self.distanceTravelled >= 1.0 ):
self.moveToNextBlock( self.currentBlock )
self.distanceTravelled = 0
return task.done
return task.cont
# Tells the enemy to start moving along the path
def moveToEnd(self):
self.moveToNextBlock( self.startingBlock )
def moveToNextBlock(self, currentBlock):
# If we've reached the last block, don't move anymore;
# otherwise, find the next block in the path and start moving
if( currentBlock.isType(EndBlock) ):
taskMgr.doMethodLater( self.moveSpeed, self.remove, 'remove' )
else:
self.currentBlock = self.findNextBlock( currentBlock )
# Start moving
taskMgr.add( self.move, 'move' + str(self.index) )
# Locates the next block on the path based upon the enemy's current location
def findNextBlock(self, currentBlock):
(row, ignore, col) = currentBlock.index.partition(' ')
row = int(row)
col = int(col)
dir = self.direction
nextBlock = 0
if( dir > -1 ):
dir = (dir - 1) % 4
for i in range(4):
if( dir == 0 ):
nextBlock = self.map[row][col + 1]
elif( dir == 1 ):
nextBlock = self.map[row - 1][col]
elif( dir == 2 ):
nextBlock = self.map[row][col - 1]
else:
nextBlock = self.map[row + 1][col]
if( nextBlock.isType(PathBlock) or nextBlock.isType(EndBlock) ):
self.direction = dir
break
dir = (dir + 1) % 4
nextBlock = 0
return nextBlock
# Finds the first path block after the start block
def findFirstPathBlock(self, currentBlock):
(row, ignore, col) = currentBlock.index.partition(' ')
row = int(row)
col = int(col)
dir = 0
for dir in range(4):
if( dir == 0 ):
nextBlock = self.map[row][col + 1]
elif( dir == 1 ):
nextBlock = self.map[row - 1][col]
elif( dir == 2 ):
nextBlock = self.map[row][col - 1]
else:
nextBlock = self.map[row + 1][col]
if( nextBlock.isType(PathBlock) ):
self.direction = dir
#.........这里部分代码省略.........
示例7: LoadingScreen
# 需要导入模块: from direct.gui.DirectGui import DirectWaitBar [as 别名]
# 或者: from direct.gui.DirectGui.DirectWaitBar import reparentTo [as 别名]
class LoadingScreen():
def __init__(self):
self.defaultFont = loader.loadFont("gui/fonts/UbuntuBold.bam")
# a fill panel so the player doesn't see how everything
# gets loaded in the background
self.frameMain = DirectFrame(
# size of the frame
frameSize = (base.a2dLeft, base.a2dRight,
base.a2dTop, base.a2dBottom),
# position of the frame
#pos = (0, 0, 0),
# tramsparent bg color
frameColor = (0.05, 0.1, 0.25, 1))
# the text Loading... on top
self.lblLoading = DirectLabel(
scale = 0.25,
pos = (0, 0, 0.5),
frameColor = (0, 0, 0, 0),
text = "Loading...",
text_align = TextNode.ACenter,
text_fg = (1,1,1,1),
text_font = self.defaultFont)
self.lblLoading.reparentTo(self.frameMain)
# the waitbar on the bottom
self.wbLoading = DirectWaitBar(
text = "0%",
text_fg = (1,1,1,1),
text_font = self.defaultFont,
value = 100,
pos = (0, 0, -0.5),
barColor = (0, 0, 1, 1))
self.wbLoading.reparentTo(self.frameMain)
self.setText()
self.hide()
def show(self):
# make sure, the frame fill in the whole screen
self.frameMain["frameSize"] = (
base.a2dLeft, base.a2dRight,
base.a2dTop, base.a2dBottom)
# ensure the texts are translated
self.setText()
# now show the main frame
self.frameMain.show()
# and render two frames so the loading screen
# is realy shown on screen
base.graphicsEngine.renderFrame()
base.graphicsEngine.renderFrame()
def hide(self):
self.frameMain.hide()
def setLoadingValue(self, value):
"""Set the waitbar value to the given value, where
value has to be a integer from 0 to 100"""
if value > 100: value = 100
if value < 0: value = 0
self.wbLoading["value"] = value
self.wbLoading["text"] = "{0}%".format(value)
base.graphicsEngine.renderFrame()
base.graphicsEngine.renderFrame()
def setText(self):
self.lblLoading["text"] = _("Loading...")