本文整理汇总了Python中hud.Hud.update方法的典型用法代码示例。如果您正苦于以下问题:Python Hud.update方法的具体用法?Python Hud.update怎么用?Python Hud.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hud.Hud
的用法示例。
在下文中一共展示了Hud.update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
def main():
hud = Hud()
# ser = serial.Serial(port = '/dev/ttyUSB0',
# baudrate = 9600,
# parity = serial.PARITY_NONE,
# stopbits = serial.STOPBITS_ONE,
# bytesize = serial.EIGHTBITS,
# timeout = 1)
logger = 0
kv = {}
stringKV = {}
firstPass = True
while True:
# wrapping this all in a try-catch should handle file-opening/-closing timeline nicely
# i.e. catch TclError(possibly tclError): close file
#
# var parsing and file writing will need to be wrapped in classes
sleep(0.5)
#kv = RT.randomKV()
#print kv
try:
#inLine = ser.readline()
inLine = RT.randomKVLine()
if inLine[0] == '@':
newKV = parseLineToKV(inLine)
newStringKV = parseLineToStringKV(inLine)
if firstPass:
keys = sorted(newStringKV.keys())
logger = Logger(keys)
firstPass = False
if newKV != kv:
kv = newKV
stringKV = newStringKV
hud.updateHud(kv)
hud.update_idletasks()
hud.update()
logger.logKV(stringKV)
print strfkv(stringKV)
except TclError: #possibly tclError
print "HUD was closed"
logger.close()
break
except err:
print err
break
示例2: run
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
#.........这里部分代码省略.........
dir = params["dir"]
g_coll = groupmanager.get(params["collision_group"])
object = object_cls(pos, dir, g_coll)
elif spawn["object_base_cls_name"] == "Bonus":
pass
else:
raise ValueError, "Invalid value '%s' for attrubite \
'object_base_cls_name' in stage %s" % (
spawn["object_base_cls_name"],
stage_name,
)
else:
object = object_cls(pos)
if spawn["bonus_cls_name"]:
if isinstance(object, BonusHolder):
object.set_bonus(spawn["bonus_cls_name"], spawn["bonus_params"])
else:
raise ValueError, "Instances of %s can not hold bonuses." % object.__class__.__name__
if spawn["mover_cls_name"]:
mover_cls = eval("mover.%s" % spawn["mover_cls_name"])
m = mover_cls(pos, object.max_speed, spawn["mover_params"])
object.set_mover(m)
for g in spawn["groups"]:
if g == "enemies":
g_enemies.add(object)
elif g == "explosions":
g_explosions.add(object)
elif g == "enemy_projectiles":
g_enemy_projectiles.add(object)
elif g == "player_projectiles":
g_player_projectiles.add(object)
# time management
clock.tick(40)
# clock.tick( float(sys.argv[1]) )
stage_clock += clock.get_time()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
sys.exit()
elif event.key == pygame.K_s:
if ship():
ship().next_weapon()
elif event.key == pygame.K_a:
if ship():
ship().previous_weapon()
elif event.key == pygame.K_x:
if ship():
ship().activate_shield(True)
elif event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
if ship():
ship().fly_up(False)
elif event.key == pygame.K_x:
if ship():
ship().activate_shield(False)
pressed_keys = pygame.key.get_pressed()
if pressed_keys[pygame.K_UP]:
if ship():
ship().fly_up(True)
if pressed_keys[pygame.K_DOWN]:
if ship():
ship().fly_down(viewport_size[1])
if pressed_keys[pygame.K_LEFT]:
if ship():
ship().fly_left()
if pressed_keys[pygame.K_RIGHT]:
if ship():
ship().fly_right(viewport_size[0])
if pressed_keys[pygame.K_z]:
if ship():
ship().shoot()
back.clear(screen, clear_bg)
back.update()
back.draw(screen)
# temp
# if ship():
# ship().damage(1)
#
g_draw.clear(screen, clear_bg)
hud.clear(screen, clear_bg)
g_draw.update()
hud.update()
g_draw.draw(screen)
hud.draw(screen)
pygame.display.flip()
示例3: GameScreen
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
class GameScreen(Events):
"""docstring for GameScreen"""
def __init__(self, window):
super(GameScreen, self).__init__()
self.window = window
self.camera = Camera(window)
self.player = player.Player()
self.proj_viewer = ProjectileViewer(self.send_center)
self.controls = {}
self.controls_old = {}
self.map = Map('blank')
#self.player.spawn(100, 100)
self.time = 0
self.moves = moves(1024)
self.index = [0]
self.head = [0]
#other players
self.players = {}
self.specs = {}
#crosshair
self.cross = CrossHair()
self.isSpec = True
self.hud = Hud()
self.gs_view = GameStateViewer(self.players, self.hud.update_prop,
self.hud.set_score)
def update(self, dt):
dt = int(dt * 1000000) / 1000000.
if self.controls['esc'] and not self.controls_old['esc']:
self.send_message('menu_transition_+', (GameMenu, self.isSpec))
if self.controls['rdy'] and not self.controls_old['rdy']:
if not self.isSpec:
self.ready_up()
if self.controls['chat'] and not self.controls_old['chat']:
self.send_message('menu_transition_+',
(ChatScreen, self.window))
self.update_keys()
self.on_update(dt)
def update_physics(self, dt, state=False, input=False):
playergen = (player.rect for player in self.players.itervalues())
mapgen = (rect for rect in self.map.quad_tree.retrieve([],
self.player.rect))
rectgen = chain(playergen, mapgen)
self.player.update(dt, rectgen, state, input)
return self.player.state
def update_state_only(self, state):
self.player.state.update(0, state)
def update_keys(self):
for key_, value in self.controls.items():
self.controls_old[key_] = value
def from_server(self, data):
typ, data = data
if typ == proto.playerUpdate:
ind, time, s_state, inpt, weaponinfo = data
smove = move(time, inpt, s_state)
if ind == self.player.id:
correct_client(self.update_physics, smove, self.moves,
self.head, self.index[0],
self.update_state_only)
self.player.weapons.from_server(weaponinfo)
else:
#try:
self.players[ind].client_update(s_state)
self.players[ind].input = inpt
#except KeyError:
# pass
elif typ == proto.projectile:
self.proj_viewer.process_proj(data)
elif typ == proto.newPlayer:
gs, data = data
if gs == proto.goesSpec:
ind, name, colstring = data
new = player.Player()
new.name = name
new.id = ind
new.set_color(colstring)
self.specs[ind] = new
#if there are existing players on the server
elif gs == proto.wantsJoin:
ind, name, state, time, colstring = data
new = player.Player()
new.name = name
new.state = state
new.time = time
new.id = ind
new.set_color(colstring)
new.rect.update_color(new.color)
self.players[ind] = new
print 'new player: %s' % name
self.gs_view.to_team(ind)
elif typ == proto.disconnect:
ind = data
if ind in self.players:
#.........这里部分代码省略.........
示例4: playGame
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
def playGame(character1, character2):
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load("Sound/07 - The Raising Fighting Spirit.ogg") #Background music "The Rising Fighting Spirit":http://downloads.khinsider.com/game-soundtracks/album/naruto-original-soundtrack-1
pygame.mixer.music.play(-1)
displaysurf = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
player1=Character(PLAYER1_CONTROLS, IMAGES[character1], SOUNDS[character1], PLAYER1_POSITION)
player2=Character(PLAYER2_CONTROLS, IMAGES[character2], SOUNDS[character2], PLAYER2_POSITION)
HUD1_IMAGES=HUD_IMAGES.copy()
HUD1_IMAGES["icon"]=IMAGES[character1]["icon"]
HUD2_IMAGES=HUD_IMAGES.copy()
HUD2_IMAGES["icon"]=IMAGES[character2]["icon"]
player1_hud=Hud(HUD1_IMAGES, LEFT_HUD_POSITION)
player2_hud=Hud(HUD2_IMAGES, RIGHT_HUD_POSITION)
player2_hud.flip()
background=load_image("Background/training_background.png") #http://spritedatabase.net/game/1889
background=pygame.transform.scale(background, (WIDTH, HEIGHT))
player1_wins=load_image("Background/player1wins.png") #Used the folowing website to generate the win signs: http://www.dafont.com/ninja-naruto.font
player2_wins=load_image("Background/player2wins.png")
pygame.display.set_caption('Pybrawl')
game_over=False
while True: # main game loop
displaysurf.blit(background, (0,0))
clock.tick(FPS)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN and event.key == K_RETURN and game_over:
return
if player1.health==0:
game_over=True
pygame.mixer.music.stop()
displaysurf.blit(player2_wins, (172, 200))
if player2.health==0:
game_over=True
pygame.mixer.music.stop()
displaysurf.blit(player1_wins, (172, 200))
keys_status=pygame.key.get_pressed()
if game_over:
keys_status=[False for i in keys_status]
player1.update(keys_status)
player2.update(keys_status)
collide(player1, player2)
keep_inside(player1)
keep_inside(player2)
if player1.rect.centerx < player2.rect.centerx:
player1.direction="right"
player2.direction="left"
else:
player1.direction="left"
player2.direction="right"
player1_hud.update(player1.health/player1.max_health,
player1.mana/player1.max_mana)
player2_hud.update(player2.health/player2.max_health,
player2.mana/player2.max_mana)
player1.draw(displaysurf)
player2.draw(displaysurf)
player1_hud.draw(displaysurf)
player2_hud.draw(displaysurf)
pygame.display.update()
示例5: GameScreen
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
class GameScreen(Events):
"""docstring for GameScreen"""
def __init__(self, window, input_handler):
super(GameScreen, self).__init__()
self.window = window
self.input_handler = input_handler
self.camera = Camera(window)
self.render = Render(self.camera, self.window)
sc_batch = self.render.scene_batch
st_batch = self.render.static_batch
self.player = player.Player(renderhook=self.render.playerhook)
self.proj_viewer = ProjectileViewer(
self.send_center, batch=sc_batch, scale=self.render.scale,
rndhook=self.render.attack)
self.controls = {}
self.controls_old = {}
self.map = Map('blank')
#self.player.spawn(100, 100)
self.time = 0
self.moves = moves(1024)
self.index = [0]
self.head = [0]
#other players
self.players = {}
self.specs = {}
#crosshair
self.cross = CrossHair(batch=st_batch)
self.isSpec = 0.5
self.hud = Hud(batch=st_batch, window=self.window)
self.gs_view = GameStateViewer(self.players, self.hud.update_prop,
self.hud.set_score)
self.frozen = False
self.rest_time = 0
def update(self, dt):
dt = int(dt * 1000000.) / 1000000.
if self.controls['esc'] and not self.controls_old['esc']:
self.send_message('menu_transition_+', (GameMenu, self.isSpec))
if self.controls['rdy'] and not self.controls_old['rdy']:
if not self.isSpec:
self.ready_up()
self.render.move_ahead()
if self.controls['chat'] and not self.controls_old['chat']:
self.send_message('menu_transition_+',
(ChatScreen, None))
self.update_keys()
for plr in self.players.itervalues():
mapgen = [rect for rect in self.map.quad_tree.retrieve([],
plr.rect)]
plr.predict(dt, mapgen)
self.on_update(dt)
def update_physics(self, dt, state=False, input=False):
self.player.update(dt, self.get_rect(), state, input)
return self.player.state.copy()
def update_state_only(self, state):
self.player.state.update_hp(state)
def update_keys(self):
for key_, value in self.controls.items():
self.controls_old[key_] = value
def from_server(self, data):
typ, data = data
if typ == proto.playerUpdate:
ind, time, s_state, inpt, weaponinfo = data
smove = move(time, inpt, s_state)
if ind == self.player.id:
correct_client(self.update_physics, smove, self.moves,
self.head, self.index[0],
self.update_state_only)
self.player.weapons.from_server(weaponinfo)
else:
self.players[ind].client_update(s_state)
self.players[ind].input = inpt
if ind == self.isSpec:
self.camera.mpos_from_aim(vec2(inpt.mx, inpt.my))
self.players[ind].weapons.from_server(weaponinfo)
self.render.weapon_check(ind, weaponinfo)
elif typ == proto.projectile:
self.proj_viewer.process_proj(data)
elif typ == proto.newPlayer:
gs, data = data
if gs == proto.goesSpec:
ind, name, colstring = data
new = player.Player(renderhook=self.render.playerhook, id=ind)
new.name = name
new.id = ind
new.set_color(colstring)
new.rect.update_color(new.color)
self.specs[ind] = new
#if there are existing players on the server
elif gs == proto.wantsJoin:
ind, name, state, time, colstring = data
new = player.Player(renderhook=self.render.playerhook, id=ind)
new.name = name
#.........这里部分代码省略.........
示例6: World
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
#.........这里部分代码省略.........
sound = pygame.mixer.Sound("data/sounds/minedeploy.wav")
sound.set_volume(.25)
sound.play()
def enemy_popcorn(self):
if len(self.enemy_list)==1:
self.call_popcorn=0
else:
self.enemy_list[1].takeHit(self.enemy_list[1].health)
self.enemy_list.remove(self.enemy_list[1])
def destroy_all_enemies(self):
self.enemy_list=[0]
if self.player.destroyAllEnemies:
self.player.after_destroy_all()
sound = pygame.mixer.Sound("data/sounds/destroyall.wav")
sound.play()
for enemy in self.enemies:
if enemy.typeofenemy == 'boss' or enemy.typeofenemy == 'link':
enemy.takeHit(1)
else:
if enemy.typeofenemy is 'virus':
self.numViruses += 1
if enemy.typeofenemy is 'worm':
self.numWorms += 1
if enemy.typeofenemy is 'pop up window':
self.numPopUps += 1
self.numEnemiesDestroyed += 1
self.enemy_list.insert(1,enemy)
#enemy.takeHit(enemy.health)
self.call_popcorn=self.frames
def update(self):
if self.holdingLeftMouseButton:
if self.frames % 5 == 0:
self.player.shoot(self.bullets)
for group in self.spriteGroups:
group.update()
self.hud.update(self)
# Test player-enemy collisions
for enemy in pygame.sprite.spritecollide(self.player, self.enemies, False):
if not enemy.dead and not enemy.animName == 'spawn':
if not enemy.typeofenemy == 'boss':
enemy.takeHit(enemy.health)
if not self.player.invincible:
self.player.decrease_life()
self.score -= 100
if enemy.dead:
if enemy.typeofenemy is 'virus':
self.numViruses += 1
self.numEnemiesDestroyed += 1
if enemy.typeofenemy is 'worm':
self.numWorms += 1
self.numEnemiesDestroyed += 1
if enemy.typeofenemy is 'pop up window':
self.numPopUps += 1
self.numEnemiesDestroyed += 1
# Test player-pickup collisions
示例7: Character
# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import update [as 别名]
class Character(Sprite):
"""Representing a character(toon) with its movements, skills,
sound effects and hud.
attributes -- dictionary that holds the attribute of each character
skill_names -- dictionary that holds the skills of each cahracter
"""
attributes = {"itachi": ATTRIBUTES[0], "sasuke": ATTRIBUTES[1],
"suigetsu": ATTRIBUTES[1], "naruto": ATTRIBUTES[0],
"jiraiya": ATTRIBUTES[0]}
skill_names = {"itachi": {"throw": "throw_shuriken",
"special_1": "amaterasu",
"special_2": "katon_goukakyuu"},
"sasuke": {"throw": "throw_lightning",
"special_1": "katon_gouryuuka",
"special_2": "chidori"},
"suigetsu": {"throw": "throw_explosive_note",
"special_1": "suirou",
"special_2": "kubikiri_shuriken"},
"naruto": {"throw": "rasengan",
"special_1": "rasen_shuriken",
"special_2": "kyuubi"},
"jiraiya": {"throw": "throw_kunai",
"special_1": "rasengan_original",
"special_2": "katon_endan"}}
def __init__(self, player, character_name, position=Vec2D(0, 0)):
"""Initialize all member variables of character.
damage -- numeric value, the amount of harm dealt through normal_attack
lock -- bool varible, says if the character is currently casting an
ability or motion
action -- string, the action currently being excecuted by the character
"""
pygame.sprite.Sprite.__init__(self)
self.name = character_name
self.damage = 100
self.attribute = self.attributes[self.name]
self.lock = True
self.action = "introduction"
self.enemy_position = pygame.Rect(0, 0, 0, 0)
if not isinstance(position, Vec2D):
self.position = Vec2D(position)
else:
self.position = position
if player == 1:
self.controls = P1_CONTROLS
self.direction = "Right"
elif player == 2:
self.controls = P2_CONTROLS
self.direction = "Left"
else:
raise SystemExit("player argument should be either 1 or 2")
self.movements = {}
for action in get_all_movements(self.name):
self.movements[action] = Movement(self.name, action)
self.skills = SkillManager()
self.hud = Hud(player, self.name)
self.sound_effects = SoundManager(self.name)
self.update({})
def update(self, input_list):
"""Update the current character action, movement, position,
sound effect and hud.
Character.update(): return None
"""
self.update_action(input_list)
self.movements[self.action].update(pygame.time.get_ticks())
self.image, self.rect = self.movements[self.action].get_image()
self._adjust_direction()
self._adjust_position()
if (self.direction == "Left" and self.action in
["take_damage", "normal_attack"]):
self.position -= self.movements[self.action].force
else:
self.position += self.movements[self.action].force
self.rect.topleft = self.position
if self.lock:
if self.movements[self.action].done:
#.........这里部分代码省略.........