本文整理汇总了Python中scene.Scene.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.draw方法的具体用法?Python Scene.draw怎么用?Python Scene.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scene.Scene
的用法示例。
在下文中一共展示了Scene.draw方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import draw [as 别名]
class Game(engine.State):
def init(self):
self.image = load_image('bg_800x600.png')
self.screen.blit(self.image[0], (0,0))
self.speed = Speed()
self.player = objects.PigOnTractor((250, 300), self.speed)
self.police = objects.Police((-300, 300), self.speed)
self.scene = Scene(self.player)
for i in range(200):
self.do_scene()
def do_scene(self):
self.scene.generate()
self.scene.bias()
self.scene.clean()
def event(self, events):
for event in events:
if event.type == pygame.QUIT:
return engine.Quit(self.game, self.debug)
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return MainMenu(self.game, self.debug)
elif event.key == pygame.K_LEFT:
self.speed.down()
elif event.key == pygame.K_RIGHT:
self.speed.up()
elif event.type == UPDATESCENE:
self.do_scene()
self.player.consume_gas()
self.player.event(events)
def update(self, passed_time):
self.player.update()
self.scene.update()
self.police.update()
if self.police.status == 'arrest':
return GameOver(self.game, self.debug, 'game_over_arrested.png', self.player.get_score())
if self.player.status() == 'arrested':
return GameOver(self.game, self.debug, 'game_over_arrested.png', self.player.get_score())
elif self.player.status() == 'died':
return GameOver(self.game, self.debug, 'game_over_die.png', self.player.get_score())
def paint(self):
self.screen.blit(self.image[0], (0,0))
self.scene.draw(self.screen)
self.player.draw(self.screen)
self.police.draw(self.screen)
示例2: Game
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import draw [as 别名]
class Game(object):
"""The main game object."""
def __init__(self):
self.framecount = 0
self.create_game()
self.play()
def create_game(self):
"""Initializes the game."""
os.environ['SDL_VIDEO_CENTERED'] = '1'
self.screen = display.set_mode(RESOLUTION, False, 32)
self.scene = Scene(self.screen)
self.events = EventManager(self.scene)
self.clock = time.Clock()
display.set_caption("%s %s" % (NAME, VERSION))
mouse.set_visible(False)
if FULLSCREEN:
toggle_fullscreen()
def play(self):
"""The main game loop."""
while self.scene.running:
self.clock.tick(FPS)
self.events.check()
self.scene.draw()
self.show_debug()
def show_debug(self):
"""Print debug info to console output."""
if DEBUG:
if self.framecount == FPS:
# Show dirty screen areas in console output.
rects = self.scene.dirty_rects
dirty = "dirty: 0, "
for rect in rects:
dirty = "dirty: %d, " % len(rects)
# Print number of projectiles on the screen
projs = "projs: %s, " % len(self.scene.projs)
# Show current framerate on screen.
fps = "fps: %d/%d" % (self.clock.get_fps(), FPS)
self.framecount = 0
os.system("clear")
print "Game: " + dirty, projs, fps
else:
self.framecount += 1
示例3: draw
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import draw [as 别名]
def draw(self, screen):
Scene.draw(self, screen)
surf = self.font.render(str(g.game.score[0]) + " - " + str(g.game.score[1]), False, (255, 255, 255))
w, h = surf.get_size()
screen.blit(surf, (160 - w / 2, 9))
if self.victoryMessage != "":
surf = self.font.render(self.victoryMessage, False, (39, 65, 62))
w, h = surf.get_size()
w += 10
pygame.draw.rect(screen, (39, 65, 62), (160 - w / 2 - 1, 100 - h / 2 - 1, w + 2, h + 2), 1)
pygame.draw.rect(screen, (255, 255, 255), (160 - w / 2, 100 - h / 2, w, h), 0)
w -= 10
screen.blit(surf, (160 - w / 2, 100 - h / 2))
示例4: draw
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import draw [as 别名]
def draw(self, screen):
Scene.draw(self, screen)
surf = self.font.render(str(self.playersInGame) + " players waiting.", False, (39, 65, 62))
w, h = surf.get_size()
w += 10
pygame.draw.rect(screen, (39, 65, 62), (160 - w / 2 - 1, 100 - h / 2 - 1, w + 2, h + 2), 1)
pygame.draw.rect(screen, (255, 255, 255), (160 - w / 2, 100 - h / 2, w, h), 0)
w -= 10
screen.blit(surf, (160 - w / 2, 100 - h / 2))
if g.game.admin:
surf = self.font.render("Press space to begin.", False, (39, 65, 62))
w, h = surf.get_size()
screen.blit(surf, (160 - w / 2, 8))
示例5: Scene
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import draw [as 别名]
from ball import Ball
WIDTH = 800
HEIGHT = 600
BG = (255, 67, 0)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
scene = Scene(screen, BG)
scene.add(Player("player", 5, (WIDTH / 2) - 50, 10, 50))
scene.add(Ia("ia", WIDTH - 5 - 10, (HEIGHT / 2) - 50, 10, 50))
scene.add(Ball("ball", (WIDTH / 2) - (10 / 2), (HEIGHT / 2) - (10 / 2), 10, 10))
scene.draw()
clock = pygame.time.Clock()
totalTime = pygame.time.get_ticks()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
timeChange = pygame.time.get_ticks() - totalTime
totalTime = pygame.time.get_ticks()
velocityScale = timeChange / 16
space = pygame.key.get_pressed()[pygame.K_SPACE]