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


Python pygame.K_d方法代码示例

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


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

示例1: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例2: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例3: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例4: keydown

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例5: keyup

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例6: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例7: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例8: get_event

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例9: __event

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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

示例10: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [as 别名]
def get_keys(self):
        self.vx, self.vy = 0, 0
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.vx = -300
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.vx = 300
        if keys[pg.K_UP] or keys[pg.K_w]:
            self.vy = -300
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            self.vy = 300
        if self.vx != 0 and self.vy != 0:
            self.vx *= 0.7071
            self.vy *= 0.7071 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:16,代码来源:screen_shake.py

示例11: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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]:
            self.shoot() 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:16,代码来源:sprites.py

示例12: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_d [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) 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:14,代码来源:sprites.py


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