本文整理匯總了Python中Menu.Menu.start_bgrn_animation方法的典型用法代碼示例。如果您正苦於以下問題:Python Menu.start_bgrn_animation方法的具體用法?Python Menu.start_bgrn_animation怎麽用?Python Menu.start_bgrn_animation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Menu.Menu
的用法示例。
在下文中一共展示了Menu.start_bgrn_animation方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Game
# 需要導入模塊: from Menu import Menu [as 別名]
# 或者: from Menu.Menu import start_bgrn_animation [as 別名]
class Game(object):
INITIAL_UPDATE_INTERVAL = UPDATE_INTERVAL
def __init__(self):
impl.funcs.load_resources()
self.gameInfo = GameInfo()
self.win = Window(FIELD_WIDTH, FIELD_HEIGHT)
self.win.set_caption("snake")
impl.funcs.setup_background_color()
impl.funcs.setup_opengl_blend_func()
self.gameField = GameField(self.gameInfo, self.win)
self.menu = Menu(FIELD_WIDTH//2, FIELD_HEIGHT//2, self.game_start_callback, self.game_exit_callback, self.win)
self._overlay = None
self._update_interval = Game.INITIAL_UPDATE_INTERVAL
@self.gameField.event
def on_restart_snake():
unschedule(func=self.update)
self._setup_overlay("restart")
schedule_once(func=self.run_snake, delay=DELAY_FOR_NEW_RUN)
@self.gameField.event
def on_rerun_menu():
unschedule(func=self.update)
#reset current handler
self.win.pop_handlers()
#and setup update handler
self.win.push_handlers(self.menu)
self.menu.start_bgrn_animation()
@self.gameField.event
def on_game_over():
unschedule(func=self.update)
self._setup_overlay('game over...')
schedule_once(func=self.game_exit_callback, delay=DELAY_FOR_EXIT)
@self.gameField.event
def on_score_up():
if self._update_interval > MAX_UPDATE_SPEED_INTERVAL:
self._update_interval -= UPDATE_INTERVAL_SPEED_DX
unschedule(func=self.update)
schedule_interval(func=self.update,interval=self._update_interval)
def _setup_overlay(self, text):
self._overlay = BouncingLabel(FIELD_WIDTH//2,FIELD_HEIGHT//2,text,DEFAULT_OVERLAY_COLOR)
self.win.pop_handlers()
def on_draw():
self.win.clear()
self._overlay.draw()
self.win.push_handlers(on_draw)
schedule_interval(func=self._overlay.update, interval=OVERLAY_UPDATE_INTERVAL)
def game_start_callback(self):
self._setup_overlay("start")
schedule_once(func=self.run_snake, delay=DELAY_FOR_NEW_RUN)
def game_exit_callback(self, *args):
if self._overlay:
unschedule(self._overlay.update)
self._overlay = None
self.win.pop_handlers()
self.win.close()
def start(self):
self.win.push_handlers(self.menu)
pyglet.app.run()
def update(self, dt):
if not self.gameInfo.pause:
self.gameField.update(dt)
def run_snake(self, *args):
if self._overlay:
unschedule(self._overlay.update)
self._overlay = None
#reset current handlers
self.win.pop_handlers()
self.gameInfo.pause = False
self.gameField.reset()
#setup new handlers
self.win.push_handlers(self.gameField)
#and setup update handler
self._update_interval = Game.INITIAL_UPDATE_INTERVAL
schedule_interval(func=self.update,interval=self._update_interval)