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


Python pygame.K_q方法代码示例

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


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

示例1: game_intro

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def game_intro():
    intro=True
    while intro:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            if event.type==pygame.KEYDOWN:
                if event.key==pygame.K_c:
                    intro=False
                if event.key==pygame.K_q:
                    pygame.quit()
                    quit()
        gameDisplay.fill(white)
        
        message_to_screen("Welcome to Flafel",green,-100,"large")
        message_to_screen("The objective of the game is to eat red apples",black,-30)
        message_to_screen("The more apples you eat,the longer you get",black,10)
        message_to_screen("If you run into yourself, or the edges, you die!",black,50)
        message_to_screen("Press C to play, P to pause or Q to quit",black,180)
        pygame.display.update()
        clock.tick(15) 
开发者ID:ActiveState,项目名称:code,代码行数:24,代码来源:recipe-578996.py

示例2: pause

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def pause():

    paused=True
    
    message_to_screen("Paused",black,-100,size="large")
    message_to_screen("Press C to continue or Q to quit",black,25)

    pygame.display.update()

    while paused:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            if event.type==pygame.KEYDOWN:
                if event.key==pygame.K_c:
                    paused=False
                elif event.key==pygame.K_q:
                    pygame.quit()
                    quit()
        
        clock.tick(5) 
开发者ID:ActiveState,项目名称:code,代码行数:24,代码来源:recipe-578996.py

示例3: check_keydown_events

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def check_keydown_events(event: EventType, ai_settings: Settings
                         , stats: GameStats, game_items: GameItems):
    """Respond when key is being pressed."""
    if event.key == pygame.K_RIGHT:
        # Move ship to the right.
        game_items.ship.moving_right = True

    elif event.key == pygame.K_LEFT:
        # Move ship to the left.
        game_items.ship.moving_left = True

    elif event.key == pygame.K_SPACE:
        fire_bullet(ai_settings, game_items)

    elif event.key == pygame.K_q:
        quit_game(stats)

    elif event.key == pygame.K_RETURN:  # ENTER key
        start_new_game(ai_settings, stats, game_items) 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:21,代码来源:game_functions.py

示例4: dispatch_event

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def dispatch_event(self, event):
        if event.type == pygame.QUIT:
            sys.exit(0)
        if event.type == pygame.KEYDOWN:
            self.keyboard._press(event.key)
            if event.key == pygame.K_q and event.mod & self.CTRL_ALT:
                sys.exit(0)
            elif event.key == pygame.K_F12:
                video = event.mod & self.SHIFT
                event = ScreenShotEvent(ScreenShotEvent, video)
        elif event.type == pygame.KEYUP:
            self.keyboard._release(event.key)

        handler = self.handlers.get(event.type)
        if handler:
            handler(event)
            return True
        return False 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:20,代码来源:game.py

示例5: check_keypress

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def check_keypress():
    try:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q or event.key == pygame.K_a or event.key == pygame.K_KP_DIVIDE or event.key == pygame.K_BACKSPACE:
                    logger.debug("Keypress 'a' or 'q' or 'backspace' or 'keypad /' detected.")
                    return "end_event"
                if event.key == pygame.K_n or event.key == pygame.K_SPACE or event.key == pygame.K_KP_PLUS:
                    logger.debug("Keypress 'n' or 'space' or 'keypad +' detected.")
                    return "next_event"
                if event.key == pygame.K_r or event.key == pygame.K_KP_PERIOD or event.key == pygame.K_COMMA:
                    logger.debug("Keypress 'r' or ',' or 'keypad .' detected")
                    return "resume_rotation"
                if event.key == pygame.K_p or event.key == pygame.K_KP_MULTIPLY:
                    logger.debug("Keypress 'p' or 'keypad *' detected")
                    return "pause_rotation"
                for numeric_key_counter, key in enumerate([pygame.K_F1,pygame.K_F2,pygame.K_F3,pygame.K_F4,pygame.K_F5,pygame.K_F6,pygame.K_F7,pygame.K_F8,pygame.K_F9,pygame.K_F10,pygame.K_F11,pygame.K_F12]):
                    if event.key == key:
                        logger.debug("Keypress 'F" + str(numeric_key_counter + 1) + "' detected")
                        return numeric_key_counter
                for numeric_key_counter, key in enumerate([pygame.K_KP0,pygame.K_KP1,pygame.K_KP2,pygame.K_KP3,pygame.K_KP4,pygame.K_KP5,pygame.K_KP6,pygame.K_KP7,pygame.K_KP8,pygame.K_KP9]):
                    if event.key == key:
                        logger.debug("Keypress 'keypad " + str(numeric_key_counter + 1) + "' detected")
                        return numeric_key_counter
                else:
                    return None
    except pygame.error as e:
        logger.debug("Exception " + repr(e))
        exit(0) 
开发者ID:SvenVD,项目名称:rpisurv,代码行数:31,代码来源:draw.py

示例6: get_order

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def get_order(self): 
        # get order from controler
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_1]: self.n = 0
        if pressed[pygame.K_2]: self.n = 1
        if pressed[pygame.K_3]: self.n = 2
        if pressed[pygame.K_4]: self.n = 3
        self.orders[self.n] = 0
        if pressed[pygame.K_w]: self.orders[self.n, 0] += 1
        if pressed[pygame.K_s]: self.orders[self.n, 0] -= 1
        if pressed[pygame.K_q]: self.orders[self.n, 1] -= 1
        if pressed[pygame.K_e]: self.orders[self.n, 1] += 1
        if pressed[pygame.K_a]: self.orders[self.n, 2] -= 1
        if pressed[pygame.K_d]: self.orders[self.n, 2] += 1
        if pressed[pygame.K_b]: self.orders[self.n, 3] -= 1
        if pressed[pygame.K_m]: self.orders[self.n, 3] += 1
        if pressed[pygame.K_SPACE]: self.orders[self.n, 4] = 1
        else: self.orders[self.n, 4] = 0
        if pressed[pygame.K_f]: self.orders[self.n, 5] = 1
        else: self.orders[self.n, 5] = 0
        if pressed[pygame.K_r]: self.orders[self.n, 6] = 1
        else: self.orders[self.n, 6] = 0
        if pressed[pygame.K_n]: self.orders[self.n, 7] = 1
        else: self.orders[self.n, 7] = 0
        if pressed[pygame.K_TAB]: self.dev = True
        else: self.dev = False
        return False 
开发者ID:LoveThinkinghard,项目名称:RoboMaster-AI-Challenge-Simulator-2D,代码行数:32,代码来源:kernal.py

示例7: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def __init__(self, input, target):
        
        super().__init__()
    
        self.input = input
        self.target = target
        
        # forward vector stays level with horizontal plane
        self.forward = np.array( [0, 0, -1] )
        # up vector is constant
        self.up = np.array( [0,1,0] )
        # recalculate right vector whenever forward vector changes
        self.right = np.cross( self.forward, self.up )
        
        # control rate of movement
        self.deltaTime = 1.0/60.0 # TODO: get actual number from input? 
        self.unitsPerSecond = 1
        self.moveAmount = self.unitsPerSecond * self.deltaTime
        self.degreesPerSecond = 60
        self.turnAmount = self.degreesPerSecond * (3.1415926 / 180) * self.deltaTime

        # customizable key mappings
        # standard controls (WASDRF, QETG)     

        self.KEY_MOVE_FORWARDS  = pygame.K_w
        self.KEY_MOVE_BACKWARDS = pygame.K_s
        self.KEY_MOVE_LEFT      = pygame.K_a
        self.KEY_MOVE_RIGHT     = pygame.K_d
        self.KEY_MOVE_UP        = pygame.K_r
        self.KEY_MOVE_DOWN      = pygame.K_f
        self.KEY_TURN_LEFT      = pygame.K_q
        self.KEY_TURN_RIGHT     = pygame.K_e
        self.KEY_LOOK_UP        = pygame.K_t
        self.KEY_LOOK_DOWN      = pygame.K_g 
开发者ID:stemkoski,项目名称:three.py,代码行数:36,代码来源:FirstPersonController.py

示例8: intro_for_game

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def intro_for_game():
    intro_screen = True

    while intro_screen:

        for eachEvent in game.event.get():
            if eachEvent.type == game.QUIT:
                game.quit()
                quit()

            if eachEvent.type == game.KEYDOWN:
                if eachEvent.key == game.K_c:
                    intro_screen = False
                if eachEvent.key == game.K_q:
                    game.quit()
                    quit()

        DisplayScreen.fill(color_white)
        display_ScreenMessage("Welcome to drawSnake",
                          green,
                          -100,
                          "large")
        display_ScreenMessage("",
                          color_black,
                          -30)

        display_ScreenMessage("",
                          color_black,
                          10)

        display_ScreenMessage("Made by Python Programmers",
                          color_black,
                          50)

        display_ScreenMessage("Press C to play or Q to quit.",
                          color_red,
                          180)

        game.display.update()
        objectClock.tick(15) 
开发者ID:PacktPublishing,项目名称:Learning-Python-by-building-games,代码行数:42,代码来源:SnakeGameFinal.py

示例9: display_frame

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def display_frame():
    for event in pg.event.get():
        if event.type == pg.QUIT:
            sys.exit(0)

        if event.type == pg.KEYDOWN:
            if event.key == pg.K_q:
                sys.exit(0)


    pg.display.flip() 
开发者ID:RedBalloonShenanigans,项目名称:MonitorDarkly,代码行数:13,代码来源:cnc_display.py

示例10: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def get_keys():
    """Returns a tuple of (UP, DOWN, LEFT, RIGHT, change, ACCELERATE,
    DECELERATE, stop) representing which keys are UP or DOWN and
    whether or not the key states changed.
    """
    change = False
    stop = False
    key_to_global_name = {
        pygame.K_LEFT: 'LEFT',
        pygame.K_RIGHT: 'RIGHT',
        pygame.K_UP: 'UP',
        pygame.K_DOWN: 'DOWN',
        pygame.K_ESCAPE: 'QUIT',
        pygame.K_q: 'QUIT',
        pygame.K_w: 'ACCELERATE',
        pygame.K_s: 'DECELERATE'
    }
    for event in pygame.event.get():
        if event.type in {pygame.K_q, pygame.K_ESCAPE}:
            stop = True
        elif event.type in {pygame.KEYDOWN, pygame.KEYUP}:
            down = (event.type == pygame.KEYDOWN)
            change = (event.key in key_to_global_name)
            if event.key in key_to_global_name:
                globals()[key_to_global_name[event.key]] = down
    return (UP, DOWN, LEFT, RIGHT, change, ACCELERATE, DECELERATE, stop) 
开发者ID:multunus,项目名称:autonomous-rc-car,代码行数:28,代码来源:interactive_control_train.py

示例11: steer

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_q [as 别名]
def steer(self):

        while self.send_inst:
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    key_input = pygame.key.get_pressed()

                    # complex orders
                    if key_input[pygame.K_UP] and key_input[pygame.K_RIGHT]:
                        print("Forward Right")
                        self.ser.write(chr(6).encode())

                    elif key_input[pygame.K_UP] and key_input[pygame.K_LEFT]:
                        print("Forward Left")
                        self.ser.write(chr(7).encode())

                    elif key_input[pygame.K_DOWN] and key_input[pygame.K_RIGHT]:
                        print("Reverse Right")
                        self.ser.write(chr(8).encode())

                    elif key_input[pygame.K_DOWN] and key_input[pygame.K_LEFT]:
                        print("Reverse Left")
                        self.ser.write(chr(9).encode())

                    # simple orders
                    elif key_input[pygame.K_UP]:
                        print("Forward")
                        self.ser.write(chr(1).encode())

                    elif key_input[pygame.K_DOWN]:
                        print("Reverse")
                        self.ser.write(chr(2).encode())

                    elif key_input[pygame.K_RIGHT]:
                        print("Right")
                        self.ser.write(chr(3).encode())

                    elif key_input[pygame.K_LEFT]:
                        print("Left")
                        self.ser.write(chr(4).encode())

                    # exit
                    elif key_input[pygame.K_x] or key_input[pygame.K_q]:
                        print("Exit")
                        self.send_inst = False
                        self.ser.write(chr(0).encode())
                        self.ser.close()
                        break

                elif event.type == pygame.KEYUP:
                    self.ser.write(chr(0).encode()) 
开发者ID:hamuchiwa,项目名称:AutoRCCar,代码行数:53,代码来源:rc_control_test.py


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