当前位置: 首页>>代码示例>>Python>>正文


Python Timer.update方法代码示例

本文整理汇总了Python中Timer.Timer.update方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.update方法的具体用法?Python Timer.update怎么用?Python Timer.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timer.Timer的用法示例。


在下文中一共展示了Timer.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getX

# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import update [as 别名]
 def getX(self,t, Kset = None):
     
     # Kset is of the form [ 'Ki', un, cn, Kvalue] where un = U number and cn is controller number
     
     plant = self.getPlant()
     controller = self.controllerFrame.getControllerBox()
     if Kset != None:
         chosenK = Kset[0]
         un = Kset[1]
         cn = Kset[2]
         newK = Kset[3]
         if chosenK == 'Ki':
             controller.setKi(un,cn,newK)
         elif chosenK == 'Kp':
             controller.setKp(un,cn,newK)
         elif chosenK == 'Kd':
             controller.setKd(un,cn,newK)
         
     columns = len(self.getA())
     
     rows = len(t)
     
     res = np.zeros( (rows,columns) )
     res[0] = self.getic()
     
     i = 0
     
     columns = self.getB().shape[1]
     
     u_res = np.zeros( (rows,columns) )
     #u_res[0] = [0]
     
     while( Timer.update() ):
         u = controller.get(res[i])
         
         res[Timer.i] = plant.get(u)
         i += 1
         u_res[i] = u
     return (res,u_res)
开发者ID:fgonz012,项目名称:Control-System-Application,代码行数:41,代码来源:PlantFrame.py

示例2: Game

# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import update [as 别名]
class Game(object):
    """Holds all the game objects and runs the game
    pygame must be initialised before including this."""
    # Constants
    #   Colors
    SCREEN_CLEAR_COLOR = pygame.Color(255, 255, 255)
    PLAYER_COLOR = pygame.Color(0, 0, 0)
    #       Tiles
    SOLID_TILE_COLOR = pygame.Color(128, 128, 128)
    END_TILE_COLOR = pygame.Color(0, 0, 255)

    #   Gameplay
    GAME_NAME = 'Bounce'
    RESOLUTION = (900, 600)
    TILE_SIZE = 15 #60x40 tiles
    DEF_TIME_SCALE = 0.001 #0.001 is standard time, where each unit is per second

    #   Timer
    TIMER_FONT = pygame.font.SysFont("monospace", 20)
    TIMER_COLOR = pygame.Color(0, 0, 0)
    TIMER_POSITION = (800, 15)

    #   Sounds
    BOUNCE_VOLUME = 0.8
    POPCORN_VOLUME = 0.15

    #   Controls
    NEXT_LEVEL_BTN = K_n
    RESTART_BTN = K_r

    def __init__(self):
        self.timer = Timer(self.TIMER_FONT, self.TIMER_COLOR, self.TIMER_POSITION)
        self.time_scale = self.DEF_TIME_SCALE

        self.current_level = 0
        self.load_next_level()

        self.player.POPCORN_SOUND.set_volume(self.POPCORN_VOLUME)

    def restart_level(self):
        player_start = self.level.load_level(self.current_level)
        self.player = Player(player_start, (0, 0), self.PLAYER_COLOR, self.BOUNCE_VOLUME, self.level)
        self.timer.time = 0
        self.level_complete = False

    def load_next_level(self):
        self.current_level += 1
        self.level = Level([res // self.TILE_SIZE for res in self.RESOLUTION], self.TILE_SIZE, self.SOLID_TILE_COLOR, self.END_TILE_COLOR)
        self.restart_level()

    def handle_input(self, key_events):
        for event in key_events:
            if event.key == self.NEXT_LEVEL_BTN:
               self.load_next_level()
            elif event.key == self.RESTART_BTN:
                self.restart_level()

    def update(self, delta, key_events):
        self.handle_input(key_events)
        if not self.level_complete:
            special_collisions = self.player.update(delta)
            self.level_complete = special_collisions == 'level_complete'
            self.timer.update(delta)

    def draw(self, display):
        self.level.draw(display)
        self.player.draw(display)
        self.timer.draw(display)
开发者ID:jgardner8,项目名称:Bounce,代码行数:70,代码来源:Game.py


注:本文中的Timer.Timer.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。