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


Python Keyboard.is_down方法代码示例

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


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

示例1: is_triggered

# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import is_down [as 别名]
 def is_triggered(self, obj):
     directions = []
     
     for direction in obj.steering :
         if(Keyboard.is_down(obj.steering[direction])) :
             directions.append(direction)
     if Direction.FORWARD in directions or Direction.BACKWARD in directions :
         self.additionalInfo = directions
         return True
     
     return False        
开发者ID:d00d171,项目名称:game,代码行数:13,代码来源:basiccreatures.py

示例2: start_game

# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import is_down [as 别名]
    def start_game(self):
        
        while 1 :
            if self.toSetGameScreen != None :
                self.currGameScreen = self.toSetGameScreen
                self.toSetGameScreen = None
                
            if self.currGameScreen == None :
                raise Exception("currGameScreen for game is not set")
            
            for event in pygame.event.get() :
                if event.type == pygame.QUIT: 
                    FileDirHelper.delete_dir(self.GAME_DIRECTORY + Default.TMP_FOLDER)
                    sys.exit()
                    
            Keyboard.get_pressed()
            
            if Keyboard.is_down(pygame.K_LCTRL) and Keyboard.is_down(pygame.K_d) :
                DebugHelper.run_debugger()
            
            
            if Keyboard.is_down(pygame.K_LCTRL) and Keyboard.is_down(pygame.K_s) :
                MainMenuHelper.save_game(self)

                Keyboard.get_pressed()
            
            for gameObject in self.currGameScreen.activeObjects.values() :
                gameObject.analyze_state()
            for gameObject in self.currGameScreen.activeObjects.values() :
                gameObject.interpret_state()
                
            self.currGameScreen.refreshScreen()
            
            
            #obj1 = Game.currGameScreen.activeObjects[2]
            #obj2 = Game.currGameScreen.activeObjects[4]
            #DebugHelper.draw_borders(Game.currGameScreen.surface, obj1)
            #DebugHelper.draw_borders(Game.currGameScreen.surface, obj2)
               
开发者ID:d00d171,项目名称:game,代码行数:40,代码来源:game.py

示例3: game

# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import is_down [as 别名]
def game():
    screen.fill(black)
    running = True
    keyboard = Keyboard()
    world = World(32, 32)
    off = ((WIDTH - world.get_render_width()) / 2,
           (HEIGHT - world.get_render_height()) / 2)
    world.offX = off[0]
    world.offY = off[1]
    ply = Player(0, 0, world)
    ply.x = random.randint(0, WIDTH - ply.w)
    ply.y = random.randint(0, HEIGHT - ply.h)
    while world.entity_hitpos(ply):
        ply.x = random.randint(0, WIDTH - ply.w)
        ply.y = random.randint(0, HEIGHT - ply.h)
    physics = Physics(world, (WIDTH, HEIGHT))
    physics.watch(ply)
    clock = pygame.time.Clock()
    last = pygame.time.get_ticks()
    ticks = 0
    plydeathtimer = 0
    lastrect = pygame.Rect(0, 0, 0, 0)

    while running:
        ticks += 1
        clock.tick(0)
        for ev in pygame.event.get():
            if ev.type == QUIT:
                running = False
                break
            elif ev.type == FRAMECOUNTER:
                print clock.get_fps()
            elif ev.type == WORLDREGEN:
                world.regen_once()
            elif ev.type == ENTITYGEN:
                x = random.randint(0, WIDTH)
                y = random.randint(0, HEIGHT)
                physics.watch(Enemy(x, y, world, physics))
            elif ev.type == MOUSEBUTTONDOWN:
                if ev.button == 0 and plydeathtimer == 0:
                    mpos = ev.pos
                    center = ply.get_center()
                    a = mpos[0] - center[0]
                    b = mpos[1] - center[1]
                    # tan(ang) = b / a
                    ang = math.atan2(b, a)

                    # Calculate bullet pos
                    pos = [math.cos(ang) * ply.w + center[0],
                           math.sin(ang) * ply.h + center[1]]

                    bull = Bullet(pos[0], pos[1], world)
                    speed = 2
                    bull.vx = speed * math.cos(ang)
                    bull.vy = speed * math.sin(ang)
                    physics.watch(bull)
                    shootsound.play()

            elif ev.type == KEYDOWN:
                keyboard.keydown(ev.key)
            elif ev.type == KEYUP:
                keyboard.keyup(ev.key)

        # Handle movement
        if plydeathtimer == 0:
            if keyboard.is_down(K_w):
                ply.vy = -1
            elif keyboard.is_down(K_s):
                ply.vy = 1
            else:
                ply.vy = 0
            if keyboard.is_down(K_a):
                ply.vx = -1
            elif keyboard.is_down(K_d):
                ply.vx = 1
            else:
                ply.vx = 0

        # Shooting repeat
        if ticks % 10 == 0 and pygame.mouse.get_pressed()[0]:
            mpos = pygame.mouse.get_pos()
            center = ply.get_center()
            a = mpos[0] - center[0]
            b = mpos[1] - center[1]
            # tan(ang) = b / a
            ang = math.atan2(b, a)

            # Calculate bullet pos
            pos = [math.cos(ang) * ply.w + center[0],
                   math.sin(ang) * ply.h + center[1]]

            bull = Bullet(pos[0], pos[1], world)
            speed = 2
            bull.vx = speed * math.cos(ang)
            bull.vy = speed * math.sin(ang)
            physics.watch(bull)
            shootsound.play()


        for ent in physics.entities:
#.........这里部分代码省略.........
开发者ID:calzoneman,项目名称:ludumdare25,代码行数:103,代码来源:destroy.py


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