本文整理汇总了Python中Gui.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.draw方法的具体用法?Python Gui.draw怎么用?Python Gui.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gui
的用法示例。
在下文中一共展示了Gui.draw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Gui [as 别名]
# 或者: from Gui import draw [as 别名]
class Game:
def __init__(self, mx=10, my=10):
self.board = Board(mx, my)
self.gui = Gui(mx, my)
self.last = sdl2.SDLK_UP
self.dir = {
sdl2.SDLK_UP: [-1, 0],
sdl2.SDLK_DOWN: [1, 0],
sdl2.SDLK_LEFT: [0, -1],
sdl2.SDLK_RIGHT: [0, 1],
}
def start(self):
run = True
self.board.init_board()
while run:
for e in sdl2.ext.get_events():
if e.type == sdl2.SDL_QUIT:
exit()
if e.type == sdl2.SDL_KEYDOWN:
k = e.key.keysym.sym
if k in self.dir.keys() and self.last != k:
self.last = self.check_key(k)
if k == sdl2.SDLK_ESCAPE:
self.quit()
run = self.move(self.dir[self.last])
self.gui.aff(self.board.get_map())
sdl2.SDL_Delay(200)
sdl2.ext.quit()
return 0
def check_key(self, k):
l = self.dir[self.last]
n = self.dir[k]
return self.last if n[0] == l[0] or n[1] == l[1] else k
def move(self, d):
h = self.board.get_head()
n = (h[0] + d[0], h[1] + d[1])
self.board.set_head(n[0], n[1])
if self.board.body.is_body(n):
return False
if self.board.apple.is_apple(n):
self.board.body.rise(d)
self.board.apple.set_apple(self.board.get_map())
elif self.board.cherry.is_cherry(self.board.get_map(), n):
self.board.body.rise(d)
self.board.cherry.set_cherry(self.board.get_map())
else:
self.board.body.move(d)
self.board.update_board()
ret = self.board.is_wall(n)
return ret
def aff(self):
self.gui.draw(self.board)
def quit(self):
exit()
示例2: Game
# 需要导入模块: import Gui [as 别名]
# 或者: from Gui import draw [as 别名]
#.........这里部分代码省略.........
self.active_sprites.add(room.walls)
self.active_sprites.add(room.floor)
self.active_sprites.set_clip(self.player.screen_rect)
# Mobs
self.mobgroup.update(self.rooms, self.dt)
# Menues
if self.player.level != self.player.old_level:
text = str(self.player.level)
old_text = str(self.player.old_level)
self.player_menu.update(0, [text])
if len(text) > len(old_text):
self.player_menu.dyn_text[1].x -= 10
self.player.old_level = self.player.level
if self.p_menu[0] != 0.0:
if self.p_menu[1] == True:
count = self.dt - self.time
else:
count = self.time - self.dt
if count < 1:
self.p_menu[0] = count
def oc_menu(self, menu):
if menu[1] == False:
self.time = self.dt + 0.1
return [0.1, True]
else:
self.time = self.dt + 1
return [0.9, False]
def draw(self):
# Background
self.active_sprites.draw(self.surf.surface)
"""
#This section is to test the Collisions visually
pygame.draw.rect(self.surf.surface, (255, 255, 255), self.player.collide_rect, 2)
for tile in self.player.collision.current_quad:
pygame.draw.rect(self.surf.surface, (255, 255, 255), tile)
"""
# Dynamic Objects
self.mobgroup.draw(self.surf.surface)
# Screen
self.screen.blit(self.surf.surface, self.surf.rect)
# Gui Menues
self.powers_gui.draw(self.screen)
if self.p_menu[0] != 0.0:
self.player_menu.draw(self.screen, self.p_menu[0])
# Mouse pointer
self.mouseover.draw(self.screen)
def user_event(self, event):
pass
def key_down(self, key):
if key in (K_w, K_UP):
self.player.arrows[0] = 1