本文整理汇总了Python中Interface.Interface.update方法的典型用法代码示例。如果您正苦于以下问题:Python Interface.update方法的具体用法?Python Interface.update怎么用?Python Interface.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interface.Interface
的用法示例。
在下文中一共展示了Interface.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Interface import Interface [as 别名]
# 或者: from Interface.Interface import update [as 别名]
class Program:
"""
General program template
- init function for program component initialization
- main loop
* check events -> handle (event)
* update
"""
def __init__(self):
"""
init function
"""
self.interface = Interface()
self.engine = Engine()
self.run()
def run(self):
"""
main loop
"""
while True:
self.check_events()
self.update()
def check_events(self):
"""
pygame event handling (edit this for more events)
"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mousex, mousey = event.pos
response = self.interface.click(mousex,mousey)
self.handle(response)
def handle(self,response):
"""
handle responses to events
"""
self.engine.send(response)
def update(self):
"""
update state of program components
"""
self.engine.update()
self.interface.update(self.engine.get_updates())
示例2: main
# 需要导入模块: from Interface import Interface [as 别名]
# 或者: from Interface.Interface import update [as 别名]
def main(root):
#close tkinter
root.quit()
# 1 - Initialize the game
pygame.init()
#timer
timer = 0
#screen
screen = pygame.display.set_mode((640,480))
screenx = screen.get_width()
screeny = screen.get_height()
screeny = 480
running = True
#sprites lists
player_sprites = pygame.sprite.Group()
all_sprites = pygame.sprite.Group()
enemy_sprites = pygame.sprite.Group()
projectile_sprites = pygame.sprite.Group()
item_sprites = pygame.sprite.Group()
#enemy data
bossPos = [screenx/2, screeny/2]
#player
playerPos = [250, 250]
global player
player = Player(playerPos)
interface = Interface(screen)
all_sprites.add(player)
player_sprites.add(player)
# 2 - Load resources
hit = pygame.mixer.Sound("resources/audio/explode.wav")
enemy = pygame.mixer.Sound("resources/audio/enemy.wav")
hit.set_volume(0.05)
enemy.set_volume(0.05)
pygame.mixer.music.load('resources/audio/moonlight.wav')
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.set_volume(0.25)
smallFireball = pygame.image.load("resources/images/flame_verysmall.png")
dragon = pygame.image.load("resources/images/DragonAttack_small.png")
background = pygame.image.load("resources/images/rock_ground.jpg")
gold_pile = pygame.image.load("resources/images/gold_pile.png")
chest = pygame.image.load("resources/images/treasure.png")
clock = pygame.time.Clock()
LEFT = 1
spawnWave = 0
#kingKnight = None
wave = 1
spawnRate = 5
while running:
screen.fill(0)
# Draw background
for x in range(int(screen.get_width()/background.get_width())+1):
for y in range(int(screen.get_height()/background.get_height())+1):
screen.blit(background,(x*100,y*100))
#draw gold pile
for x in range(1,8):
#if x == 1 or x == 6:
if x % 2 == 0:
screen.blit(chest, (-5, screen.get_height()/8*x-30 ))
else:
screen.blit(gold_pile, (-10, screen.get_height()/8*x-30 ))
#spawn waves
if not enemy_sprites:
makeWave(timer, enemy_sprites, spawnWave, spawnRate, wave, screen)
wave += 1
player.rightclick_cd = 0
# 5 - Draw screen and update sprites
enemy_sprites.draw(screen)
projectile_sprites.draw(screen)
player_sprites.draw(screen)
item_sprites.draw(screen)
player.update(player, dragon, enemy_sprites, projectile_sprites, item_sprites, screen, interface)
projectile_sprites.update(projectile_sprites, timer, enemy_sprites, all_sprites, screen)
enemy_sprites.update(screen, timer, player, enemy_sprites, item_sprites, interface)
interface.update(player, screen)
# Draw timer display
seconds = clock.tick()/1000.0
timer += seconds
player.flycd -= seconds
player.rightclick_cd -= seconds
player.flyDuration -= seconds
displayTimer = round(timer,1)
gamefont = pygame.font.Font(None, 24)
timertext = gamefont.render(str(displayTimer), 1, [0,0,0])
screen.blit(timertext, [screen.get_width()-50, 5])
# Draw player health
pygame.draw.rect(screen, (0,0,0), (5, 5, 206, 18))
pygame.draw.rect(screen, (255,0,0), (8,8,200, 12))
if player.hitPoints:
#.........这里部分代码省略.........