當前位置: 首頁>>代碼示例>>Python>>正文


Python pygame.K_a方法代碼示例

本文整理匯總了Python中pygame.K_a方法的典型用法代碼示例。如果您正苦於以下問題:Python pygame.K_a方法的具體用法?Python pygame.K_a怎麽用?Python pygame.K_a使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygame的用法示例。


在下文中一共展示了pygame.K_a方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _map_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def _map_keys(self):
        key_map = self.io.key_map

        key_map[imgui.KEY_TAB] = pygame.K_TAB
        key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT
        key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT
        key_map[imgui.KEY_UP_ARROW] = pygame.K_UP
        key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN
        key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP
        key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN
        key_map[imgui.KEY_HOME] = pygame.K_HOME
        key_map[imgui.KEY_END] = pygame.K_END
        key_map[imgui.KEY_DELETE] = pygame.K_DELETE
        key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE
        key_map[imgui.KEY_ENTER] = pygame.K_RETURN
        key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE
        key_map[imgui.KEY_A] = pygame.K_a
        key_map[imgui.KEY_C] = pygame.K_c
        key_map[imgui.KEY_V] = pygame.K_v
        key_map[imgui.KEY_X] = pygame.K_x
        key_map[imgui.KEY_Y] = pygame.K_y
        key_map[imgui.KEY_Z] = pygame.K_z 
開發者ID:swistakm,項目名稱:pyimgui,代碼行數:24,代碼來源:pygame.py

示例2: get_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def get_keys(self):
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.rot_speed = PLAYER_ROT_SPEED
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.rot_speed = -PLAYER_ROT_SPEED
        if keys[pg.K_UP] or keys[pg.K_w]:
            self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot)
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot)
        if keys[pg.K_SPACE]:
            now = pg.time.get_ticks()
            if now - self.last_shot > BULLET_RATE:
                self.last_shot = now
                dir = vec(1, 0).rotate(-self.rot)
                pos = self.pos + BARREL_OFFSET.rotate(-self.rot)
                Bullet(self.game, pos, dir)
                self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
                choice(self.game.weapon_sounds['gun']).play()
                MuzzleFlash(self.game, pos) 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:24,代碼來源:sprites.py

示例3: get_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def get_keys(self):
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.rot_speed = PLAYER_ROT_SPEED
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.rot_speed = -PLAYER_ROT_SPEED
        if keys[pg.K_UP] or keys[pg.K_w]:
            self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot)
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot)
        if keys[pg.K_SPACE]:
            now = pg.time.get_ticks()
            if now - self.last_shot > BULLET_RATE:
                self.last_shot = now
                dir = vec(1, 0).rotate(-self.rot)
                pos = self.pos + BARREL_OFFSET.rotate(-self.rot)
                Bullet(self.game, pos, dir)
                self.vel = vec(-KICKBACK, 0).rotate(-self.rot) 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:22,代碼來源:sprites.py

示例4: get_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def get_keys(self):
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.rot_speed = PLAYER_ROT_SPEED
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.rot_speed = -PLAYER_ROT_SPEED
        if keys[pg.K_UP] or keys[pg.K_w]:
            self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot)
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot)
        if keys[pg.K_SPACE]:
            now = pg.time.get_ticks()
            if now - self.last_shot > BULLET_RATE:
                self.last_shot = now
                dir = vec(1, 0).rotate(-self.rot)
                pos = self.pos + BARREL_OFFSET.rotate(-self.rot)
                Bullet(self.game, pos, dir)
                self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
                MuzzleFlash(self.game, pos) 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:23,代碼來源:sprites.py

示例5: handleKeyDown

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def handleKeyDown(self,key,unicode):
        isAlt = (pygame.key.get_mods() & pygame.KMOD_ALT)
        if isAlt:
            for menu in self.menus:
                scNr=menu["scChar"]
                title=menu["title"]
                scChr=title[scNr]
                scNr=ord(scChr)-ord("A")
                keyNr=key-pygame.K_a
                if keyNr == scNr:
                    self.activeMenu=menu
                    menulist=menu["menulist"]
                    menulist.isVisible=True
                else:
                    menulist = menu["menulist"]
                    menulist.isVisible = False
                # We are handling this so clear queue for others
                pygame.event.clear() 
開發者ID:Photonsters,項目名稱:PhotonFileEditor,代碼行數:20,代碼來源:GUI.py

示例6: __human_control

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def __human_control(self, key):
        if self.human_control:
            robot = self.robots[self.human_control_robot]
            if key == pygame.K_LEFT:
                robot.move(GlobalConstants.LEFT_ACTION, self.sprites)
            if key == pygame.K_RIGHT:
                robot.move(GlobalConstants.RIGHT_ACTION, self.sprites)
            if key == pygame.K_UP:
                robot.move(GlobalConstants.UP_ACTION, self.sprites)
            if key == pygame.K_DOWN:
                robot.move(GlobalConstants.DOWN_ACTION, self.sprites)
            if key == pygame.K_a:
                reward = robot.move(GlobalConstants.FIRE_ACTION, self.sprites)
                if reward > 0:
                    self.rewards[self.human_control_robot].append(reward)
                    self.total_score[self.human_control_robot] += reward 
開發者ID:garlicdevs,項目名稱:Fruit-API,代碼行數:18,代碼來源:engine.py

示例7: keydown

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def keydown(self, key):
        """ Update velocities based on key pressed
        Arguments:
            key: pygame key
        """
        if key == pygame.K_UP:  # set forward velocity
            self.for_back_velocity = S
        elif key == pygame.K_DOWN:  # set backward velocity
            self.for_back_velocity = -S
        elif key == pygame.K_LEFT:  # set left velocity
            self.left_right_velocity = -S
        elif key == pygame.K_RIGHT:  # set right velocity
            self.left_right_velocity = S
        elif key == pygame.K_w:  # set up velocity
            self.up_down_velocity = S
        elif key == pygame.K_s:  # set down velocity
            self.up_down_velocity = -S
        elif key == pygame.K_a:  # set yaw counter clockwise velocity
            self.yaw_velocity = -S
        elif key == pygame.K_d:  # set yaw clockwise velocity
            self.yaw_velocity = S 
開發者ID:damiafuentes,項目名稱:DJITelloPy,代碼行數:23,代碼來源:manual-control-pygame.py

示例8: keyup

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def keyup(self, key):
        """ Update velocities based on key released
        Arguments:
            key: pygame key
        """
        if key == pygame.K_UP or key == pygame.K_DOWN:  # set zero forward/backward velocity
            self.for_back_velocity = 0
        elif key == pygame.K_LEFT or key == pygame.K_RIGHT:  # set zero left/right velocity
            self.left_right_velocity = 0
        elif key == pygame.K_w or key == pygame.K_s:  # set zero up/down velocity
            self.up_down_velocity = 0
        elif key == pygame.K_a or key == pygame.K_d:  # set zero yaw velocity
            self.yaw_velocity = 0
        elif key == pygame.K_t:  # takeoff
            self.tello.takeoff()
            self.send_rc_control = True
        elif key == pygame.K_l:  # land
            not self.tello.land()
            self.send_rc_control = False 
開發者ID:damiafuentes,項目名稱:DJITelloPy,代碼行數:21,代碼來源:manual-control-pygame.py

示例9: update

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def update(self, event: pg.event) -> None:
        """Update game logic with each game tick."""
        if game_vars.is_started:
            # Scroll the earth into view when the game starts
            if self.entry_y_offset > 0:
                self.entry_y_offset = max(self.entry_y_offset - self.entry_speed, 0)

            # If we are not doing a task - we can move the background
            if not game_vars.open_task:
                key_pressed = pg.key.get_pressed()

                if key_pressed[pg.K_a] or key_pressed[pg.K_LEFT]:
                    self.__scroll_left()
                if key_pressed[pg.K_d] or key_pressed[pg.K_RIGHT]:
                    self.__scroll_right()

                self.__update_tiles(event)
            else:
                game_vars.open_task.update(event)

        self.current_cloud_bg_pos += BG_CLOUDS_SCROLL_SPEED
        self.current_cloud_fg_pos += FG_CLOUDS_SCROLL_SPEED

        self.__update_positions()
        self.__update_indicators() 
開發者ID:python-discord,項目名稱:code-jam-5,代碼行數:27,代碼來源:earth.py

示例10: __init__

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def __init__(self):
 
        pygame.init()
 
        self.screen = pygame.display.set_mode( (800,600) )
        pygame.display.set_caption("Collisions")
        
        self.player = Player(keyboard={
            'left': pygame.K_LEFT,
            'right': pygame.K_RIGHT,
            'up': pygame.K_UP,
            'down': pygame.K_DOWN,
        })
        
        self.enemy  = Player(keyboard={
            'left': pygame.K_a,
            'right': pygame.K_d,
            'up': pygame.K_w,
            'down': pygame.K_s,
        })
        
        self.enemy.set_center(self.screen)
 
        self.font = pygame.font.SysFont("", 32)
        self.text = '' 
開發者ID:furas,項目名稱:python-examples,代碼行數:27,代碼來源:main_4.py

示例11: __init__

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def __init__(self, num):
        self.keys = {'up': 0, 'down': 0, 'left': 0, 'right': 0}
        self.num = num
        self.alive = True
        # depending on which player, set different values
        if self.num == 0:
            self.body = [vec(GRIDWIDTH - 5, GRIDHEIGHT - 5)]
            self.dir = 'u'
            self.color = GREEN
            self.keys['up'] = pg.K_UP
            self.keys['down'] = pg.K_DOWN
            self.keys['left'] = pg.K_LEFT
            self.keys['right'] = pg.K_RIGHT
        elif self.num == 1:
            self.body = [vec(5, 5)]
            self.dir = 'd'
            self.color = RED
            self.keys['up'] = pg.K_w
            self.keys['down'] = pg.K_s
            self.keys['left'] = pg.K_a
            self.keys['right'] = pg.K_d 
開發者ID:kidscancode,項目名稱:gamedev,代碼行數:23,代碼來源:snake_duel.py

示例12: get_event

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def get_event(self):
        global SCREEN_WIDTH, SCREEN_HEIGHT
        event_list = pygame.event.get()
        for event in event_list:
            if event.type == pygame.VIDEORESIZE:
                SCREEN_WIDTH, SCREEN_HEIGHT = event.size
                self.window = self.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT], pygame.RESIZABLE, 32)

            if event.type == pygame.QUIT:
                self.end_game()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w:
                    self.my_tank.direction = U
                elif event.key == pygame.K_s:
                    self.my_tank.direction = D
                elif event.key == pygame.K_a:
                    self.my_tank.direction = L
                elif event.key == pygame.K_d:
                    self.my_tank.direction = R
                else:
                    return None
                self.my_tank.move_stop = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if len(TankGame.my_bullet_list) < 3:
                    bullet = self.my_tank.fire()
                    load_music('fire')
                    TankGame.my_bullet_list.append(bullet)
            elif event.type == pygame.KEYUP:
                self.my_tank.move_stop = True 
開發者ID:jtyoui,項目名稱:Jtyoui,代碼行數:31,代碼來源:tank.py

示例13: __event

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_a [as 別名]
def __event(self):
        # 獲取所有窗口中的事件監聽 -> 列表
        event_list = pygame.event.get()
        # 遍曆所有的事件
        for event in event_list:
            # 如果是鼠標點擊關閉事件
            if event.type == pygame.QUIT:
                self.game_over()

            # 監聽按下事件
            if event.type == pygame.KEYDOWN:
                # 是否按下的是Esc
                if event.key == pygame.K_ESCAPE:
                    self.game_over()
                # 是否按下的是空格
                if event.key == pygame.K_SPACE:
                    self.hero_plane.shoot()

        # 監聽鍵盤長按事件 -> 元組(0沒按下,1長按了) 字母對應阿斯克碼
        pressed_keys = pygame.key.get_pressed()

        # 判斷向上是否被長按(1)
        if pressed_keys[pygame.K_UP] or pressed_keys[pygame.K_w]:
            self.hero_plane.move_up()

        # 判斷向下是否被長按(1)
        if pressed_keys[pygame.K_DOWN] or pressed_keys[pygame.K_s]:
            self.hero_plane.move_down()

        # 判斷向左是否被長按(1)
        if pressed_keys[pygame.K_LEFT] or pressed_keys[pygame.K_a]:
            self.hero_plane.move_left()

        # 判斷向右是否被長按(1)
        if pressed_keys[pygame.K_RIGHT] or pressed_keys[pygame.K_d]:
            self.hero_plane.move_right()

    # 4- 刷新窗口 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:40,代碼來源:game_main.py


注:本文中的pygame.K_a方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。